cluster()(范围函数)cluster() (scope function)

将查询的引用更改为远程群集。Changes the reference of the query to a remote cluster.

cluster('help').database('Sample').SomeTable

语法Syntax

cluster(stringConstant)cluster(stringConstant)

参数Arguments

  • stringConstant:被引用群集的名称。stringConstant: Name of the cluster that is referenced. 群集名称可以是完全限定的 DNS 名称,也可以是以 .kusto.chinacloudapi.cn 为后缀的字符串。Cluster name can be either a fully qualified DNS name, or a string that will be suffixed with .kusto.chinacloudapi.cn. 在执行查询之前,参数必须是常量,即不能来自子查询求值。Argument has to be constant prior to the query's execution, i.e. cannot come from sub-query evaluation.

说明Notes

  • 若要访问同一群集内的数据库,请使用 database() 函数。For accessing database within the same cluster - use database() function.
  • 有关跨群集查询和跨数据库查询的详细信息,请参阅此文More information about cross-cluster and cross-database queries available here

示例Examples

使用 cluster() 访问远程群集Use cluster() to access remote cluster

下一查询可在任何 Kusto 群集上运行。The next query can be run on any of the Kusto clusters.

cluster('help').database('Samples').StormEvents | count

cluster('help.kusto.chinacloudapi.cn').database('Samples').StormEvents | count  
计数Count
5906659066

在 let 语句中使用 cluster()Use cluster() inside let statements

可以重写与上述查询相同的查询,以便使用可接收参数 clusterName 的内联函数(let 语句)- 该参数会传递到 cluster() 函数中。The same query as above can be rewritten to use inline function (let statement) that receives a parameter clusterName - which is passed into the cluster() function.

let foo = (clusterName:string)
{
    cluster(clusterName).database('Samples').StormEvents | count
};
foo('help')
计数Count
5906659066

在 Functions 内使用 cluster()Use cluster() inside Functions

可以重写与上述查询相同的查询,以便在可接收参数 clusterName 的函数中使用它 - 该参数会传递到 cluster() 函数中。The same query as above can be rewritten to be used in a function that receives a parameter clusterName - which is passed into the cluster() function.

.create function foo(clusterName:string)
{
    cluster(clusterName).database('Samples').StormEvents | count
};

请注意: 此类函数只能在本地使用,而不能在跨群集查询中使用。Note: such functions can be used only locally and not in the cross-cluster query.

Azure Monitor 不支持此功能This capability isn't supported in Azure Monitor