How to use azure-kusto-python for cross-cluster and cross-database query?

Viewed 47

Currently I can use azure-kusto-python to query a single cluster and a single database:

The KQL query:

StormEventInfo
      | take 10
      | where environment contains "templ"
      | where userType == "user" or isempty(userType)

the python code is as follows:

client = KustoClient(
      KustoConnectionStringBuilder.with_aad_application_key_authentication(
            KUSTO_CLUSTER,
            CLIENT_ID,
            CLIENT_SECRET,
            AAD_TENANT_ID
         )
     )
response = client.execute(MY_DB_ID, query)

But if the KQL query is as following(it is cross-cluster and databases, this is an aggregate query), how should I code here in python with this sdk?

let Cluster = entity_group [
    cluster('https://b1.abc.net/').database('2f43e3ae086a0'), cluster('https://b2.abc.net').database('6a009979fa88')
];
macro-expand Cluster as X (
    X.StormEventInfo
      | take 10
      | where environment contains "templ"
      | where userType == "user" or isempty(userType)

Thanks for the help guys!

1 Answers

in a cross-cluster or cross-database query, the reference to the remote cluster/database is included in the query text (e.g. cluster("other_cluster)" or database("other_database")).

there's nothing special you need to configure in the calling code.

for instance, if you have:

  1. tableA in databaseA in clusterA
  2. tableB in databaseB in clusterB

and you want to union the contents of 1 and 2, then you could do either of the following:

  • send the following query to clusterA/databaseA:

    tableA | union cluster("clusterB").database("databaseB").table("tableB")

  • send the following query to clusterB/databaseB:

    tableB | union cluster("clusterA").database("databaseA").table("tableA")

reagardless, you do need to make sure that the principal identity used for authentication has read permissions on both the cluster/database the request is being sent to, as well as the other cluster/database that is referenced in the query text.

Related