How to pass in a List of parameters to query_parameters

MarkL 5 Reputation points
2023-07-10T23:02:53.3333333+00:00

Hi, I have the following simple query in a Java application

declare query_parameters(pointNames:dynamic); CurrentData | where Point in (pointNames)

pointNames is a Java list of strings e.g. "TestSite1:11kV:Cb1:Amps", "TestSite2:11kV:Cb22:Voltage", etc etc

I'm using the kusto-data jar library version 5.0.0 and attempting to set the parameters with the following: -

clientRequestProperties.setParameter("pointNames", pointNamesList);

This doesn't work. Is there a way to set parameters for an IN clause in KQL with a list/array of strings?

Thanks Mark

Azure Data Explorer
Azure Data Explorer
An Azure data analytics service for real-time analysis on large volumes of data streaming from sources including applications, websites, and internet of things devices.
576 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MarkL 5 Reputation points
    2023-07-13T07:21:45.79+00:00

    Hi Annu,

    The problem with your answer is there won't be a fixed number of pointNames as it is a Java List of Strings. Therefore the number of requested points could be 1, it could be 8, it could be 100 etc.

    I've spent a few hours working on this and came up with this solution which works

    var pointList = pointNames.stream().collect(Collectors.joining("','", "dynamic(['", "'])"));
    var clientRequestProperties = new ClientRequestProperties();
    clientRequestProperties.setParameter("pointList", pointList);
    var query = """
    		declare query_parameters(pointList:dynamic);
    		let pointNames = pointList;
    		CurrentData 
    		| where Point in (pointNames)
    		""";
    return kustoClient.execute("MyDB", query, clientRequestProperties);
    

    The Collectors.joining(delimiter, prefix, suffix) creates a kusto dynamic array in the format: -

    dynamic(['point name1', 'point name2', 'point name3'..... , 'point nameX'])

    which can be passed into query as a dynamic type

    Regards

    Mark

    1 person found this answer helpful.

  2. AnnuKumari-MSFT 34,556 Reputation points Microsoft Employee Moderator
    2023-07-12T17:29:28.42+00:00

    Hi MarkL ,

    Welcome to Microsoft Q&A platform and thanks for posting your question here.

    From the description of your question, it seems you are trying to figure out the way to use multiple selections in query parameters in data explorer.

    Please let me know if that is not the correct understanding.

    You can use 'in' clause in KQL for specifying multiple selections in KQL. . For that, you need to declare multiple parameters in the query parameter list

    declare query_parameters(pointName1:string ,pointName2:string);
    QnaCsatData
    | where Point in (pointName1,pointName2)
    
    
    

    Press Alt+P to provide values to these parameters.

    User's image

    Hope it helps. Kindly accept the answer by clicking on Accept answer button. Thankyou

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.