buildschema() (aggregation function)

Learn how to use the buildschema() function to build a table schema from a dynamic expression.

Builds the minimal schema that admits all values of DynamicExpr.

Syntax

buildschema (DynamicExpr)

Parameters

NameTypeRequiredDescription
DynamicExprdynamic✔️Expression used for the aggregation calculation.

Returns

Returns the minimal schema that admits all values of DynamicExpr.

Example

The following example builds a schema based on:

  • {"x":1, "y":3.5}
  • {"x":"somevalue", "z":[1, 2, 3]}
  • {"y":{"w":"zzz"}, "t":["aa", "bb"], "z":["foo"]}
datatable(value: dynamic) [
    dynamic({"x":1, "y":3.5}),
    dynamic({"x":"somevalue", "z":[1, 2, 3]}),
    dynamic({"y":{"w":"zzz"}, "t":["aa", "bb"], "z":["foo"]})
]
| summarize buildschema(value)

Results

schema_value
{“x”:[“long”,“string”],“y”:[“double”,{“w”:“string”}],“z”:{"indexer":[“long”,“string”]},“t”:{"indexer":“string”}}

Schema breakdown

In the resulting schema:

  • The root object is a container with four properties named x, y, z, and t.
  • Property x is either type long or type string.
  • Property y is either type double or another container with a property w of type string.
  • Property z is an array, indicated by the indexer keyword, where each item can be either type long or type string.
  • Property t is an array, indicated by the indexer keyword, where each item is a string.
  • Every property is implicitly optional, and any array might be empty.