make_bag()(聚合函数)make_bag() (aggregation function)

返回组中 Expr 的所有值的 dynamic (JSON) 属性包(字典)。Returns a dynamic (JSON) property-bag (dictionary) of all the values of Expr in the group.

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

语法Syntax

summarize make_bag(Expr [, MaxSize ])summarize make_bag(Expr [, MaxSize ])

参数Arguments

  • Expr:用于聚合计算的 dynamic 类型的表达式。Expr : Expression of type dynamic that is used for aggregation calculations.
  • MaxSize 是对返回元素最大数目的可选整数限制。MaxSize is an optional integer limit on the maximum number of elements returned. 默认值为 1048576。The default is 1048576 . MaxSize 值不能超过 1048576。MaxSize value can't exceed 1048576 .

注意Note

函数 make_dictionary() 的旧版和已过时变体的默认限制为 MaxSize = 128。A legacy and obsolete variant of function make_dictionary(), has a default limit of MaxSize = 128.

返回Returns

返回组(属性包)中 Expr 的所有值的 dynamic (JSON) 属性包(字典)。Returns a dynamic (JSON) property-bag (dictionary) of all the values of Expr in the group, which are property-bags. 将跳过非字典值。Non-dictionary values will be skipped. 如果一个键出现在多个行中,则会从此键的可能值中选择一个任意值。If a key appears in more than one row, an arbitrary value, out of the possible values for this key, will be selected.

请参阅See also

使用 bag_unpack() 插件将动态 JSON 对象扩展到使用属性包键的列中。Use the bag_unpack() plugin for expanding dynamic JSON objects into columns that use property bag keys.

示例Examples

let T = datatable(prop:string, value:string)
[
    "prop01", "val_a",
    "prop02", "val_b",
    "prop03", "val_c",
];
T
| extend p = pack(prop, value)
| summarize dict=make_bag(p)

dictdict
{ "prop01": "val_a", "prop02": "val_b", "prop03": "val_c" }{ "prop01": "val_a", "prop02": "val_b", "prop03": "val_c" }

使用 bag_unpack() 插件将 make_bag() 输出中的包键转换为列。Use the bag_unpack() plugin for transforming the bag keys in the make_bag() output into columns.

let T = datatable(prop:string, value:string)
[
    "prop01", "val_a",
    "prop02", "val_b",
    "prop03", "val_c",
];
T
| extend p = pack(prop, value)
| summarize bag=make_bag(p)
| evaluate bag_unpack(bag) 

prop01prop01 prop02prop02 prop03prop03
val_aval_a val_bval_b val_cval_c