次の方法で共有


mv-expand operator

Applies to: ✅Microsoft FabricAzure Data ExplorerAzure MonitorMicrosoft Sentinel

複数の値の動的配列またはプロパティ バッグを複数のレコードに展開します。

mv-expand can be described as the opposite of the aggregation operators that pack multiple values into a single dynamic-typed array or property bag, such as summarize ... make-list() and make-series. (スカラー) 配列またはプロパティ バッグ内の各要素により、演算子の出力に新しいレコードが生成されます。 展開されない入力のすべての列は、出力のすべてのレコードに複製されます。

Syntax

T|mv-expand [kind=(bag | array)] [with_itemindex=IndexColumnName] ColumnName [to typeof(Typename)] [,ColumnName ...] [limitRowlimit]

T|mv-expand [kind=(bag | array)] [Name=] ArrayExpression [to typeof(Typename)] [, [Name=] ArrayExpression [to typeof(Typename)] ...] [limitRowlimit]

Learn more about syntax conventions.

Parameters

Name タイプ Required Description
ColumnName, ArrayExpression string ✔️ 列参照、または配列またはプロパティ バッグを保持する dynamic 型の値を持つスカラー式。 配列またはプロパティ バッグの個々の最上位レベルの要素は、複数のレコードに展開されます。
When ArrayExpression is used and Name doesn't equal any input column name, the expanded value is extended into a new column in the output. Otherwise, the existing ColumnName is replaced.
Name string 新しい列の名前。
Typename string ✔️ 配列の要素の基になる型を示します。これは、mv-expand 演算子によって生成される列の型になります。 型を適用する操作はキャストのみであり、解析や型変換は含まれません。 宣言された型に準拠していない配列要素は、 null 値になります。
RowLimit int 元の各行から生成された行の最大数。 既定値は 2147483647 です。 mvexpand は、mv-expand 演算子の古いレガシ形式です。 レガシ バージョンでの既定の行の制限は 128 です。
IndexColumnName string If with_itemindex is specified, the output includes another column named IndexColumnName that contains the index starting at 0 of the item in the original expanded collection.

Returns

入力の各レコードについて、演算子は、次の方法で決定されるように、出力で 0 個、1 個、または多数のレコードを返します。

  1. 展開されない入力列は、元の値で出力に表示されます。 1 つの入力レコードが複数の出力レコードに展開された場合、その値はすべてのレコードに複製されます。

  2. For each ColumnName or ArrayExpression that is expanded, the number of output records is determined for each value as explained in modes of expansion. 入力レコードごとに、出力レコードの最大数が計算されます。 すべての配列またはプロパティ バッグは "並行して" 展開され、欠損値 (存在する場合) は null 値に置き換えられます。 要素は、元の配列またはバッグに出現する順序で行に展開されます。

  3. 動的な値が null の場合、その値 (null) に対して 1 つのレコードが生成されます。 動的な値が空の配列またはプロパティ バッグの場合、その値に対してレコードは生成されません。 それ以外の場合は、動的な値に含まれる要素と同数のレコードが生成されます。

展開された列は、dynamic 句を使用して明示的に型指定されている場合を除き、to typeof() 型です。

展開のモード

2 つのモードのプロパティ バッグの展開がサポートされています。

  • kind=bag または bagexpansion=bag: プロパティ バッグは、単一エントリのプロパティ バッグに展開されます。 これは既定のモードです。
  • kind=array or bagexpansion=array: Property bags are expanded into two-element [key,value] array structures, allowing uniform access to keys and values. このモードでは、たとえば、プロパティ名での個別のカウントの集計を実行することもできます。

Examples

The examples in this article use publicly available tables in the help cluster, such as the StormEvents table in the Samples database.

The examples in this article use publicly available tables, such as the Weather table in the Weather analytics sample gallery. ワークスペース内のテーブルと一致するように、クエリ例のテーブル名を変更する必要がある場合があります。

このセクションの例では、構文を使用して作業を開始する方法を示します。

単一列 - 配列の展開

datatable (a: int, b: dynamic)
[
    1, dynamic([10, 20]),
    2, dynamic(['a', 'b'])
]
| mv-expand b

Output

a b
1 10
1 20
2 a
2 b

単一列 - バッグの展開

1 つの列の単純な展開:

datatable (a: int, b: dynamic)
[
    1, dynamic({"prop1": "a1", "prop2": "b1"}),
    2, dynamic({"prop1": "a2", "prop2": "b2"})
]
| mv-expand b

Output

a b
1 {"prop1": "a1"}
1 {"prop2": "b1"}
2 {"prop1": "a2"}
2 {"prop2": "b2"}

単一列 - キーと値のペアへのバッグの展開

キーと値のペアへの単純なバッグの展開:

datatable (a: int, b: dynamic)
[
    1, dynamic({"prop1": "a1", "prop2": "b1"}),
    2, dynamic({"prop1": "a2", "prop2": "b2"})
]
| mv-expand kind=array b 
| extend key = b[0], val=b[1]

Output

a b キー val
1 ["prop1","a1"] prop1 a1
1 ["prop2","b1"] prop2 b1
2 ["prop1","a2"] prop1 a2
2 ["prop2","b2"] prop2 b2

圧縮された 2 つの列

2 つの列を最初に展開して、該当する列を "zip" してから展開します。

datatable (a: int, b: dynamic, c: dynamic)[
    1, dynamic({"prop1": "a", "prop2": "b"}), dynamic([5, 4, 3])
]
| mv-expand b, c

Output

a b c
1 {"prop1":"a"} 5
1 {"prop2":"b"} 4
1 3

2 つの列のデカルト積

展開する 2 つの列のデカルト積を取得する場合は、一方を展開した後で他方を展開します。

datatable (a: int, b: dynamic, c: dynamic)
[
    1, dynamic({"prop1": "a", "prop2": "b"}), dynamic([5, 6])
]
| mv-expand b
| mv-expand c

Output

a b c
1 { "prop1": "a"} 5
1 { "prop1": "a"} 6
1 { "prop2": "b"} 5
1 { "prop2": "b"} 6

Convert output

mv-expand の出力を特定の型に強制的に展開するには (既定値は dynamic)、to typeof を使用します。

datatable (a: string, b: dynamic, c: dynamic)[
    "Constant", dynamic([1, 2, 3, 4]), dynamic([6, 7, 8, 9])
]
| mv-expand b, c to typeof(int)
| getschema 

Output

ColumnName ColumnOrdinal DateType ColumnType
a 0 System.String string
b 1 System.Object dynamic
c 2 System.Int32 int

bdynamic として返されますが、cint として返されることに注意してください。

Using with_itemindex

with_itemindex による配列の展開:

range x from 1 to 4 step 1
| summarize x = make_list(x)
| mv-expand with_itemindex=Index x

Output

x Index
1 0
2 1
3 2
4 3