Azure Data Explorer Query Language-batches and materialize - azure-log-analytics

Reference:
https://learn.microsoft.com/en-us/azure/kusto/query/materializefunction
https://learn.microsoft.com/en-us/azure/kusto/query/batches
I am using Microsoft's demo portal: https://aka.ms/LADemo
A query can include multiple tabular expression statements, as long as
they are delimited by a semicolon (;) character. The query then
returns multiple tabular results, as produced by the tabular
expression statements, and ordered according to the order of the
statements in the query text.
When I run following code I am only getting result from the first expression and not the second and third one. Which is contrary to the above statement. Why?
let randomSet = materialize(range x from 1 to 30000000 step 1 | project value = rand(10000000));
randomSet | summarize dcount(value);
randomSet | top 3 by value;
randomSet | summarize sum(value)
Picture of the result set:

Log Analytics does not support this feature, to try it out use the Kusto (Azure Data Explorer) demo cluster, you will see multiple tables in the output pane:

Related

BigQuery UNNEST and JOIN the result from a remote function search function using user query from datastudio

I am trying to implement a custom text search in lookerstudio (formerly datastudio) dashboard using a custom SQL query as the datasource and a paramater which will be a sentence to search on.
The sentence will be passed to a BQ remote function and the cloud function will return matching results.
So far I have mocked the cloud function to return a string of matching IDs as the BQ remote function expects the result length to match the call length.
'{"replies":["ID1,ID2,ID3"]}'
I have tried the following to get the results back initially:
#standardSQL
WITH query AS(SELECT "test sentence query" AS user_query)
SELECT
S.Description,
SPLIT(`data`.search_function(user_query)) as ID
FROM query
LEFT JOIN `data.record_info` AS S
ON ID = S.ID
The SPLIT IDs are coming out into 1 row ID (when I run the query without the left join). In addition I can't seem to get it unnested and the description column pulled in, I get the error:
Expecting 14552 results but got back 1
Is this method of search in datastudio going to be possible?
Posting this here in case anyone else needs a solution to this problem
WITH Query AS(SELECT "test sentence query" AS user_query)
SELECT
S.Description,
ID
FROM
Query,
UNNEST(SPLIT(`data`.search_function(user_query))) as ID
LEFT JOIN `data.record_info` AS S
ON ID = S.ID
The main difference here is the need for the inclusion of the UNNEST function since SPLIT won't separate the input into multiple rows, even if it appears to do so.

Can you use results from 2 sql queries and perform calculations

I have a requirement to calculate a number value by using the results of two sql queries. I know this is possible in python etc but if I want to use the results of sql queries in say, apache superset, how can I achieve this?
For ex:
query1: select * from consumer;
result: 190 rows
query2: select * from producer;
result: 230 rows
value I need, called output : 190/230.
Is this possible using sub queries? How can I extract the output alone?

Why '| count' doesn't work after 'as' operator

Seems the '| count' expression works unexpectedly on a tabular expression bind with 'as' operator. This query returned 100 record instead of 1 record:
traces
| take 100 | as traces100;
traces100
| count
You should do it differently:
let traces100 = traces | take 100;
traces100
| count
It's because as and let are different:
let statements (which is what you need) bind names to expressions. For the rest of the scope, where the let statement appears, the name can be used to refer to its bound value. See more details in the doc.
as (which is what you tried to use) bind a name to the operator's input tabular expression, thus allowing the query to reference the value of the tabular expression multiple times without breaking the query and binding a name through the let statement. See more details in the doc.

SQL Server - collapsing multiple row values into one field

I'm trying to produce the result shown in the "Desired Results" section (in SQL Server 2016) in my screenshot below, where the objections associated with each borrower number are in one column delimited by commas instead of separate rows.
I don't want to restructure my database - I just want to display the results as requested for a customer report. Thanks
I was able to use the STRING_AGG function which I didn't know existed to produce the results I need.
SELECT ht.Hearings_CaseID, Borrower_Number, STRING_AGG(Objection,',') AS Objection
FROM Hearings_Test ht INNER JOIN
Hearings_Objections_Test hot on ht.Hearings_CaseID = hot.Hearings_CaseID
GROUP BY
ht.Hearings_CaseID, Borrower_Number

How to select the max value of the last 6 digits of the entries in the column in SQL

I am trying to select the maximum value of the last 6 digits in a list of strings
This is for creating an Inbox Query in Infor EAM
OBJ_CODE is the column and R5OBJECTS is the table. I have tried the following code but the number returned is 0.
SELECT MAX(RIGHT(OBJ_CODE,6)) FROM R5OBJECTS
My list looks like this
AAAA100000
AAAA100001
AAAA100002
AAAA100003
AAAA100004
AAAA100005
...
AAAA100999
...
BBBB100006
BBBB100007
BBBB100008
BBBB100009
BBBB100010
So the expected output would be 100999
It seems this table R5OBJECTS is too big, and your sql query performance didn't pass the base configuration parameter.
If using Inbox -> Set your INBXSCOR to 50 and try your query again.
If using KPI -> Set your KPISCOR to 50
SQL Statement
Enter the SQL statement to calculate the number of applicable records
for the inbox entry. The system automatically populates SQL Statement
Text. Note: SQL Statement cannot exceed the performance score limit
defined in the INBXSCOR installation parameter.
https://docs.infor.com/eam/11.3.2/en-us/eamolh/cdh1498150395934.html
Although this code works perfectly form me in SQL Server 2016, I add additional function to convert string to int to be sure:
SELECT MAX(CONVERT(INT,RIGHT(OBJ_CODE,6))) FROM R5OBJECTS