ADX Stored Query Result - Passing Query Parameters

478 Views Asked by At

I am trying to create a stored_query_result dynamically from the java application .So the query part am going to construct from java . I have used ClientRequestProperty for passing query parameters to the query .But in ADX while using declare statement it is not allowing us to use the set statement .So I am unable to create stored query result with query params using clientrequestproperty .As a work around I did string manipulation and constructed the query ? is there any recommended way to do that ?

2

There are 2 best solutions below

1
On

Did you declare the query parameters in front of the query? for example:

.set stored_query_result foo <| 
declare query_parameters(User:string, PWD:string);
T | where UserName == User and Password == PWD
0
On

You can try to create the stored_query_result without any query parameters and set expiresAfter and previewCount parameters as per your choice. For example:

.set stored_query_result DailyClicksByAdNetwork7Days with (expiresAfter = timespan(1h), previewCount = 100) <|
Events
| summarize Count=count() by Day=bin(Timestamp, 1d), AdNetwork
| order by Count desc
| project Num=row_number(), Day, AdNetwork, Count

And then create a function as a wrapper over the stored_query_result. For example:

.create-or-alter function DailyClicksByAdNetwork7DaysFunc(eventType:string,startOffset:real, endOffset:real) {
    stored_query_result("DailyClicksByAdNetwork7Days")
    | where EventType == eventType
    | where Num between (startOffset .. endOffset)
}

And then make sure the caller passes the required parameters when calling the function DailyClicksByAdNetwork7DaysFunc. For example: DailyClicksByAdNetwork7DaysFunc("click", 10, 20)