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

返回组中 Expr 所有值的 dynamic (JSON) 数组。Returns a dynamic (JSON) array of all the values of Expr in the group.

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

语法Syntax

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

参数Arguments

  • Expr:用于聚合计算的表达式。Expr: Expression that will be used for aggregation calculation.
  • MaxSize 是对返回元素最大数目的可选整数限制(默认值是 1048576)。MaxSize is an optional integer limit on the maximum number of elements returned (default is 1048576). MaxSize 值不能超过 1048576。MaxSize value cannot exceed 1048576.

备注

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

返回Returns

返回组中 Expr 所有值的 dynamic (JSON) 数组。Returns a dynamic (JSON) array of all the values of Expr in the group. 如果未对 summarize 运算符的输入进行排序,那么生成的数组中的元素顺序是不确定的。If the input to the summarize operator is not sorted, the order of elements in the resulting array is undefined. 如果对 summarize 运算符的输入进行了排序,则生成的数组中的元素顺序和输入一样。If the input to the summarize operator is sorted, the order of elements in the resulting array tracks that of the input.

提示

使用 mv-apply 运算符按某个键值创建一个有序列表。Use the mv-apply operator to create an ordered list by some key. 请参阅此处的示例。See examples here.

示例Examples

一列One column

最简单的示例是基于一列生成一个列表:The simplest example is to make a list out of a single column:

let shapes = datatable (name: string, sideCount: int)
[
    "triangle", 3,
    "square", 4,
    "rectangle", 4,
    "pentagon", 5,
    "hexagon", 6,
    "heptagon", 7,
    "octogon", 8,
    "nonagon", 9,
    "decagon", 10
];
shapes
| summarize mylist = make_list(name)
mylistmylist
["triangle","square","rectangle","pentagon","hexagon","heptagon","octogon","nonagon","decagon"]["triangle","square","rectangle","pentagon","hexagon","heptagon","octogon","nonagon","decagon"]

使用“by”子句Using the 'by' clause

在下面的查询中,使用了 by 子句进行分组:In the following query, you group using the by clause:

let shapes = datatable (name: string, sideCount: int)
[
    "triangle", 3,
    "square", 4,
    "rectangle", 4,
    "pentagon", 5,
    "hexagon", 6,
    "heptagon", 7,
    "octogon", 8,
    "nonagon", 9,
    "decagon", 10
];
shapes
| summarize mylist = make_list(name) by isEvenSideCount = sideCount % 2 == 0
mylistmylist isEvenSideCountisEvenSideCount
falsefalse ["triangle","pentagon","heptagon","nonagon"]["triangle","pentagon","heptagon","nonagon"]
true ["square","rectangle","hexagon","octogon","decagon"]["square","rectangle","hexagon","octogon","decagon"]

将动态对象打包Packing a dynamic object

可以在列中将一个动态对象打包,然后基于其生成一个列表,如以下查询所示:You can pack a dynamic object in a column before making a list out of it, as seen in the following query:

let shapes = datatable (name: string, sideCount: int)
[
    "triangle", 3,
    "square", 4,
    "rectangle", 4,
    "pentagon", 5,
    "hexagon", 6,
    "heptagon", 7,
    "octogon", 8,
    "nonagon", 9,
    "decagon", 10
];
shapes
| extend d = pack("name", name, "sideCount", sideCount)
| summarize mylist = make_list(d) by isEvenSideCount = sideCount % 2 == 0
mylistmylist isEvenSideCountisEvenSideCount
falsefalse [{"name":"triangle","sideCount":3},{"name":"pentagon","sideCount":5},{"name":"heptagon","sideCount":7},{"name":"nonagon","sideCount":9}][{"name":"triangle","sideCount":3},{"name":"pentagon","sideCount":5},{"name":"heptagon","sideCount":7},{"name":"nonagon","sideCount":9}]
true [{"name":"square","sideCount":4},{"name":"rectangle","sideCount":4},{"name":"hexagon","sideCount":6},{"name":"octogon","sideCount":8},{"name":"decagon","sideCount":10}][{"name":"square","sideCount":4},{"name":"rectangle","sideCount":4},{"name":"hexagon","sideCount":6},{"name":"octogon","sideCount":8},{"name":"decagon","sideCount":10}]

另请参阅See also

make_list_if 运算符与 make_list 相似,只是它也接受谓词。make_list_if operator is similar to make_list, except it also accepts a predicate.