join kusto database with a function from another database - azure-data-explorer

Edit:
Below are more details about what I am trying to achieve.
I have 1 cluster with two databases. Database1 contains Table1 with the below info
DB2 contains a table with the below info:
UniqueID contains the same data as userID on table1.
In DB2, I have a function that performs some filtering on Unique ID.
I know that I can join both tables as the below screenshot, but my production example is way more complex than that and requires me to use the function.
My goal is to run the Table1 query, and pass the the userID to the function getuserproperties, to get a merged output.
Something Like this which does not work :)

Finally found it :) It was very simple :)
let UID = 7;
database('db1').Table1
| join kind=leftouter database('db2').Table2 on $left.userID==$right.UniqueID
| where userID == toscalar(getUserProperties(UID))

Related

Kusto join tables from different DB

I have a requirement to join 2 tables in Kusto but they are in different Database under same cluster.
I can see the below Query works if the tables are in Same DB.
Table1 | join (Table2) on CommonColumn, $left.Col1 == $right.Col2
But could you please tell me how do I join 2 tables in diff DB.
for example
DB1 - Table 1 - This is where I run the Query
DB2 - Table 2 - this is where I would like to take a join and I have the common column name - RunID
If you're running the query in the context of db1, then you can run a cross-db query like this:
Table1 // assuming Table1 is in db1
| join (database("db2").Table2) on CommonColumn, $left.Col1 == $right.Col2
If you don't know (or don't want to rely) on the database in the context of which the query runs, you can prefix all the tables with the relevant database name, like this:
database("db1").Table1
| join (database("db2").Table2) on CommonColumn, $left.Col1 == $right.Col2
I was able to take the join with the below query
| join kind = innerunique (
database("DB2").Table2) on $left.RunID == $right.RunID
Thanks

Kusto: Full table scan on join even join conditions are time-based?

I have a Kusto Query like:
(Events
| take 1)
| join kind=leftouter Sensor_Data on $left.start_timestmp ==
$right.timestmp, someotherfield
and it will never return. The right side of the join has several billion entries.
If I do a
Events
| take 1
and use the result in the where clause of Sensor_Data it returns in no time.
The MS Support Team explains that this query requires a full table scan of the Sensors_Data table. The join parameters are not taken into consideration by the query optimizer.
Question:
Is the Kusto Query Optimizer really no able to optimize queries based on the join condition? To me it sounds a little bit like 1999 to have to first do the left side of the query manualy and then do the right side manualy as well? Is there some hint or so, to make this run fast?
consider rewriting your query as follows (for example) and see if that helps it perform better:
let x = toscalar(Events | take 1 | project pack("ts", start_timestmp, "sof", someotherfield));
Sensor_Data
| where timestmp == todatetime(x["ts"])
| where someotherfield == tostring(x["sof"])

How are you supposed to think of joins in cosmosdb?

I am very confused by the cosmosdb documentation on joins. When I think of a join conventionally, I think of 2 tables, with 1 shared id, on which I perform the join. These 2 tables have different schemas, but the result of the join is a combined table with a merge of the columns from both tables. The join for cosmosdb does not seem to me intuitively congruent with that.
I have a collection with heterogenous data. Each document can have a different structure from the next. I want to count the number of documents that have a value that is present in the result set of a subquery. Intuitively, I want to do something like this:
SELECT COUNT(1) as c
FROM CollectionName as outer
where outer.type = "table"
JOIN ((SELECT c.id from c where c.type = "database") as inner) on outer.databaseId == t.id
// count the number of tables that are in deleted databases
It would seem like I would need to do a join on the result of the subquery with the result of the outer query, and then process that resulting table. But I am not understanding right now how to do that:
Select COUNT(1)
from Collection outer
where outer.type = 'table'
JOIN (select c.id from c IN outer.databaseId where c.type = "database" and c.state = "deleted")
I am constantly getting a 400 with the above query. So how am I supposed to think about joins in cosmosdb?
Cosmos is a document database. It stores and operates on json data which can be in hierarchical format. Joins in Cosmos reference tuples within these hierarchies where they can be projected with other data in the document.
There is a really good article that talks through this at pretty deep level but also have lots of examples too, Joins in Cosmos DB.
This takes some getting used to writing queries like this but once you get the hang of it you'll be ok. You can easily practice queries using the Query Playground that has a bunch of sample queries for nutrition dataset with food and ingredients. Or follow along with the families data in the docs. You can create additional items and then write some queries to see how joins work.
Hope that is helpful.

Using the results of the output of one query as table names

I have written the following code which extracts the names of tables which have used storage in Sentinel. I'm not sure if Kusto is capable of doing the query but essentially I want to use the value stored in "Out" as names of tables. e.g union(Out) or search in (Out) *
let MyTables =
Usage
| where Quantity > 0
| summarize by DataType ;
let Out =
MyTables
| summarize makelist(DataType);
No, this is not possible. The tables referenced by the query should be known during query planning. A possible workaround can be generating the query and invoking it using the execute_query plugin.

Phonegap retrieve data from two table in sqlite

I have a task to retrieve data from two tables, from table one: name,firstname,lastname and also retrieve their cities from a second table. In the second table I have foreign key as table one's id as tbl_id in second table. please reply me and advice me is joinquery support or not in phonegap.
Just use websql join query
tx.executeSql( 'SELECT * FROM table1 JOIN table2 ON table1.primary = table2.foreign',
[],nullHandler,errorHandler);
},errorHandler,successCallBack);
In sucessCallback Function query results will be returned.
For more understanding of webSql database look into here
Its in the phongap documentation how to implement local database in mobile this

Resources