Applies to: ✅Microsoft Fabric✅Azure Data Explorer✅Azure Monitor✅Microsoft 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 | Type | 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개 또는 많은 레코드를 출력에 반환합니다.
확장되지 않은 입력 열은 출력에 원래 값으로 표시됩니다. 단일 입력 레코드가 여러 출력 레코드로 확장되면 값이 모든 레코드에 중복됩니다.
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 값으로 대체됩니다. 요소는 원래 배열/모음에 표시되는 순서대로 행으로 확장됩니다.
동적 값이 null이면 해당 값(null)에 대해 단일 레코드가 생성됩니다. 동적 값이 빈 배열 또는 속성 모음인 경우 해당 값에 대한 레코드가 생성되지 않습니다. 그렇지 않으면, 동적 값에 요소가 있으므로 많은 레코드가 생성됩니다.
확장된 열은 절을 사용하여 명시적으로 형식화되지 않는 한 형식 dynamic입니다 to typeof() .
확장 모드
속성 모음 확장의 두 가지 모드가 지원됩니다.
-
kind=bag또는bagexpansion=bag: 속성 모음이 단일 항목 속성 모음으로 확장됩니다. 이 모드가 기본 모드입니다. -
kind=arrayorbagexpansion=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
StormEventstable in the Samples database.
The examples in this article use publicly available tables, such as the
Weathertable 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 |
단일 열 - 모음 확장
단일 열의 간단한 확장:
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 | key | val |
|---|---|---|---|
| 1 | ["prop1","a1"] |
prop1 | a1 |
| 1 | ["prop2","b1"] |
prop2 | b1 |
| 2 | ["prop1","a2"] |
prop1 | a2 |
| 2 | ["prop2","b2"] |
prop2 | b2 |
두 개의 열 압축
먼저 두 열을 확장하면 해당 열이 '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 |
두 열의 데카르트 곱
두 열을 확장하는 카티전 곱을 가져오려면 다음 열을 차례로 확장합니다.
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의 출력을 특정 형식(기본값은 동적)으로 강제 적용하려면 다음을 사용합니다 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 |
참고 열 b 은 다음과 dynamic 같이 c 반환int됩니다.
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 |
Related content
- mv-apply operator.
- For the opposite of the mv-expand operator, see summarize make_list().
- For expanding dynamic JSON objects into columns using property bag keys, see bag_unpack() plugin.
- parse_json function
- array_iff function