azureazure-data-explorer

query_parameters with web queries


I was wondering if there is a way to use query_parameters with shared web queries? I have tried "copy link" from my query + adding the query params to the link, but this is not populating query_paramters.

See:

https://learn.microsoft.com/en-us/azure/data-explorer/web-share-queries

https://learn.microsoft.com/en-us/kusto/query/query-parameters-statement?view=azure-data-explorer

For example:

https://kusto.azure.com/clusters/help/databases/Samples?query=H4sIAAAAAAAAA0tJTc5JLEpVKCxNLaqML0gsSsxNLUktKtbISM3JybcqLinKzEtXsFVQAvOVNK15uQqAQiUKYD4AvCmDJD4AAAA%3D&hello=world

declare query_parameters(hello:string = "hello"); print hello

... does not print "world" though I passed world in the query string.


Solution

  • query_parameters with web queries

    The declare query_parameters feature in Kusto is for parameterized queries in application code like SDKs or REST API, not web URLs and the web-share-queries format uses a base64 or gzip+base64-encoded KQL string in the ?query= parameter. ADX does not parse additional URL parameters like &hello=world into KQL parameters.

    Instead of using query_parameters, I tried by creating a web page that takes user input, embeds it directly in the KQL query, base64-encodes it, and builds a valid ADX shareable link. It injects the value directly into the query text before encoding and it works successfully as shown in the below output.

    Below is the code which i tried to generate ADX link.

    <!DOCTYPE html>
    <html>
    <head>
      <title>ADX Query Link Generator</title>
    </head>
    <body>
      <h2>ADX Query Link Generator</h2>
    
      <label for="name">Enter name: </label>
      <input type="text" id="name" value="world" />
      <button onclick="generateLink()">Generate ADX Link</button>
    
      <p><strong>Resulting ADX Query Link:</strong></p>
      <pre id="output"></pre>
    
      <script>
        function generateLink() {
          const name = document.getElementById('name').value || 'world';
    
          const kql = `print greeting = "Hello", name = "${name}"`;
    
          const url = `https://kusto.azure.com/clusters/help/databases/Samples?query=${encodeURIComponent(kql)}`;
    
          document.getElementById('output').textContent = url;
        }
      </script>
    </body>
    </html>
    

    Output: enter image description here

    ADX Link: https://kusto.azure.com/clusters/help/databases/Samples?query=print%20greeting%20%3D%20%22Hello%22%2C%20name%20%3D%20%22Alice%22

    Copy the above generated link and open in the browser, it re-directs to the ADX WEB UI with the query as shown below:

    print  greeting  =  "Hello",  name  =  "Alice"
    

    This executes successfully and shows how dynamic values can be included in shared query URLs as shown in the below output. Output: enter image description here