Buildschema()(聚合函数)buildschema() (aggregation function)

返回允许“DynamicExpr”所有值的最小架构。Returns the minimal schema that admits all values of DynamicExpr .

  • 只能在 summarize 内的聚合上下文中使用Can be used only in context of aggregation, inside summarize

语法Syntax

summarize buildschema(DynamicExpr)summarize buildschema(DynamicExpr)

参数Arguments

  • DynamicExpr :用于聚合计算的表达式。DynamicExpr : Expression that is used for the aggregation calculation. 参数列类型必须为 dynamicThe parameter column type must be dynamic.

返回Returns

组内“Expr”的最大值。The maximum value of Expr across the group.

提示

如果 buildschema(json_column) 指示语法错误:If buildschema(json_column) gives a syntax error:

你的 json_column 是字符串,不是动态对象?Is your json_column a string rather than a dynamic object?

则使用 buildschema(parsejson(json_column))then use buildschema(parsejson(json_column)).

示例Example

假定输入列具有三个动态值。Assume the input column has three dynamic values.

  • {"x":1, "y":3.5}
  • {"x":"somevalue", "z":[1, 2, 3]}
  • {"y":{"w":"zzz"}, "t":["aa", "bb"], "z":["foo"]}

生成的架构可能为:The resulting schema would be:

{ 
    "x":["int", "string"],
    "y":["double", {"w": "string"}],
    "z":{"`indexer`": ["int", "string"]},
    "t":{"`indexer`": "string"}
}

此架构表示:The schema tells us that:

  • 根对象是具有四个属性(名为 x、y、z 和 t)的容器。The root object is a container with four properties named x, y, z, and t.
  • “x”属性可能属于“int”类型或“string”类型。The property called "x" that could be of type "int" or of type "string".
  • “y”属性可能属于“double”类型,或者另一个容器的“w”属性属于“string”类型。The property called "y" that could be of type "double", or another container with a property called "w" of type "string".
  • indexer 关键字指示“z”和“t”是数组。The indexer keyword indicates that "z" and "t" are arrays.
  • 数组“z”中的每一项均为“int”类型或“string”类型。Each item in the array "z" is of type "int" or of type "string".
  • “t”是一个字符串数组。"t" is an array of strings.
  • 每个属性均为隐式可选,并且任何数组均可能为空。Every property is implicitly optional, and any array may be empty.

架构模型Schema model

返回架构的语法是:The syntax of the returned schema is:

Container ::= '{' Named-type* '}';
Named-type ::= (name | '"`indexer`"') ':' Type;
Type ::= Primitive-type | Union-type | Container;
Union-type ::= '[' Type* ']';
Primitive-type ::= "int" | "string" | ...;

这些值等效于 TypeScript 类型批注的子集,作为 Kusto 动态值编码。The values are equivalent to a subset of the TypeScript type annotations, encoded as a Kusto dynamic value. 在 Typescript 中,示例架构应为:In Typescript, the example schema would be:

var someobject: 
{
    x?: (number | string),
    y?: (number | { w?: string}),
    z?: { [n:number] : (int | string)},
    t?: { [n:number]: string }
}