Applies to: ✅Microsoft Fabric✅Azure Data Explorer✅Azure Monitor✅Microsoft Sentinel
파티션 연산자는 키 열의 값에 따라 입력 테이블의 레코드를 여러 하위 테이블로 분할합니다. 연산자는 각 하위 테이블에 대해 하위 쿼리를 실행하고 모든 하위 쿼리의 결과 통합인 단일 출력 테이블을 생성합니다.
파티션 연산자는 전체 데이터 세트의 쿼리가 아니라 동일한 파티션 키에 속하는 행의 하위 집합에서만 하위 쿼리를 수행해야 하는 경우에 유용합니다. These subqueries could include aggregate functions, window functions, top N and others.
파티션 연산자는 하위 쿼리 작업의 몇 가지 전략을 지원합니다.
- Native - use with an implicit data source with thousands of key partition values.
- Shuffle - use with an implicit source with millions of key partition values.
- Legacy - use with an implicit or explicit source for 64 or less key partition values.
Syntax
T|
partition
[ hint.strategy=
Strategy ] [ Hints ] by
Column(
TransformationSubQuery)
T|
partition
[ hint.strategy=legacy
] [ Hints ] by
Column{
SubQueryWithSource}
Learn more about syntax conventions.
Parameters
Name | Type | Required | Description |
---|---|---|---|
T | string |
✔️ | 입력 테이블 형식 원본입니다. |
Strategy | string |
값 legacy 또는 shuffle native . 이 힌트는 파티션 연산자의 실행 전략을 정의합니다.
전략이 지정되지 legacy 않은 경우 전략이 사용됩니다. For more information, see Strategies. |
|
Column | string |
✔️ | The name of a column in T whose values determine how to partition the input tabular source. |
TransformationSubQuery | string |
✔️ | 테이블 형식 변환 식입니다. The source is implicitly the subtables produced by partitioning the records of T. Each subtable is homogenous on the value of Column.
식은 하나의 테이블 형식 결과만 제공해야 하며 문과 같은 let 다른 형식의 문이 없어야 합니다. |
SubQueryWithSource | string |
✔️ | 테이블 참조와 같은 자체 테이블 형식 원본을 포함하는 테이블 형식 식입니다. This syntax is only supported with the legacy strategy. The subquery can only reference the key column, Column, from T. To reference the column, use the syntax toscalar( Column) .
식은 하나의 테이블 형식 결과만 제공해야 하며 문과 같은 let 다른 형식의 문이 없어야 합니다. |
Hints | string |
Zero or more space-separated parameters in the form of: HintName= Value that control the behavior of the operator. See the supported hints per strategy type. |
Supported hints
Hint name | Type | Strategy | Description |
---|---|---|---|
hint.shufflekey |
string |
shuffle | 전략을 사용하여 파티션 연산 shuffle 자를 실행하는 데 사용되는 파티션 키입니다. |
hint.materialized |
bool |
legacy |
true 설정하면 partition 연산자의 원본이 구체화됩니다. 기본값은 false 입니다. |
hint.concurrency |
int |
legacy | 병렬로 실행할 파티션 수를 결정합니다. 기본값은 16 입니다. |
hint.spread |
int |
legacy | 클러스터 노드 간에 파티션을 배포하는 방법을 결정합니다. 기본값은 1 입니다.
For example, if there are N partitions and the spread hint is set to P, then the N partitions are processed by P different cluster nodes equally, in parallel/sequentially depending on the concurrency hint. |
Returns
연산자는 개별 하위 쿼리 결과의 합을 반환합니다.
Strategies
The partition operator supports several strategies of subquery operation: native, shuffle, and legacy.
Note
호출자는 전략과 native
전략을 구분 shuffle
하여 하위 쿼리의 카디널리티 및 실행 전략을 나타낼 수 있습니다. 이 선택은 하위 쿼리를 완료하는 데 걸리는 시간에 영향을 줄 수 있지만 최종 결과는 변경되지 않습니다.
Native strategy
이 전략은 파티션 키의 고유 값 수가 크지 않은 경우(대략 수천 개) 적용해야 합니다.
하위 쿼리는 테이블 형식 소스를 지정하지 않는 테이블 형식 변환이어야 합니다. 원본은 암시적이며 하위 테이블 파티션에 따라 할당됩니다. Only certain supported operators can be used in the subquery. 파티션 수에는 제한이 없습니다.
이 전략을 사용하려면 .를 지정합니다 hint.strategy=native
.
Shuffle strategy
파티션 키의 고유 값 수가 수백만 개인 경우 이 전략을 적용해야 합니다.
하위 쿼리는 테이블 형식 소스를 지정하지 않는 테이블 형식 변환이어야 합니다. 원본은 암시적이며 하위 테이블 파티션에 따라 할당됩니다. Only certain supported operators can be used in the subquery. 파티션 수에는 제한이 없습니다.
이 전략을 사용하려면 .를 지정합니다 hint.strategy=shuffle
. For more information about shuffle strategy and performance, see shuffle query.
네이티브 및 순서 섞기 전략에 지원되는 연산자
다음 연산자 목록은 네이티브 또는 순서 섞기 전략을 사용하여 하위 쿼리에서 사용할 수 있습니다.
- count
- distinct
- extend
- make-series (partially supported, see note)
- mv-apply
- mv-expand
- parse
- parse-where
- project
- project-away
- project-keep
- project-rename
- project-reorder
- reduce
- sample
- sample-distinct
- scan
- search
- serialize
- sort
- summarize
- take
- top
- top-hitters
- top-nested
- where
Note
- 하위 테이블 파티션 이외의 테이블 원본을 참조하는 연산자는 및 전략과
native
shuffle
호환되지 않습니다. For example, join, union, externaldata, and evaluate (plugins). For such scenarios, resort to the legacy strategy. - The fork operator isn't supported for any strategy type, as the subquery must return a single tabular result.
- The make-series operator is only partially supported within the
partition by
operator. 매개 변수와from
매개 변수가to
모두 지정된 경우에만 지원됩니다.
Legacy strategy
역사적 이유로 이 legacy
전략은 기본 전략입니다. However, we recommend favoring the native or shuffle strategies, as the legacy
approach is limited to 64 partitions and is less efficient.
일부 시나리오에서는 하위 쿼리에 legacy
테이블 형식 소스를 포함하도록 지원하기 때문에 전략이 필요할 수 있습니다. In such cases, the subquery can only reference the key column, Column, from the input tabular source, T. To reference the column, use the syntax toscalar(
Column)
.
하위 쿼리가 테이블 형식 원본이 없는 테이블 형식 변환인 경우 원본은 암시적이며 하위 테이블 파티션을 기반으로 합니다.
이 전략을 사용하려면 다른 전략 표시를 지정 hint.strategy=legacy
하거나 생략합니다.
Note
An error occurs if the partition column, Column, contains more than 64 distinct 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. 작업 영역의 테이블과 일치하도록 예제 쿼리에서 테이블 이름을 수정해야 할 수 있습니다.
상위 값 찾기
경우에 따라 연산자를 사용하는 partition
것보다 연산자를 사용하여 top-nested
쿼리를 작성하는 것이 더 성능이 높고 더 쉽습니다. 다음 쿼리는 하위 쿼리 계산 summarize
을 실행하고 각각 top
"WYOMING", "WASHINGTON", "WEST VIRGINIA" 및 "WISCONSIN"로 시작 State
W
합니다.
StormEvents
| where State startswith 'W'
| partition hint.strategy=native by State
(
summarize Events=count(), Injuries=sum(InjuriesDirect) by EventType, State
| top 3 by Events
)
Output
EventType | State | Events | Injuries |
---|---|---|---|
Hail | WYOMING | 108 | 0 |
High Wind | WYOMING | 81 | 5 |
Winter Storm | WYOMING | 72 | 0 |
Heavy Snow | WASHINGTON | 82 | 0 |
High Wind | WASHINGTON | 58 | 13 |
Wildfire | WASHINGTON | 29 | 0 |
Thunderstorm Wind | WEST VIRGINIA | 180 | 1 |
Hail | WEST VIRGINIA | 103 | 0 |
Winter Weather | WEST VIRGINIA | 88 | 0 |
Thunderstorm Wind | WISCONSIN | 416 | 1 |
Winter Storm | WISCONSIN | 310 | 0 |
Hail | WISCONSIN | 303 | 1 |
Native strategy
다음 쿼리는 'W'로 시작하는 각 EventType
값에 TotalInjuries
대한 상위 2 State
개 값을 반환합니다.
StormEvents
| where State startswith 'W'
| partition hint.strategy = native by State
(
summarize TotalInjueries = sum(InjuriesDirect) by EventType
| top 2 by TotalInjueries
)
Output
EventType | TotalInjueries |
---|---|
Tornado | 4 |
Hail | 1 |
Thunderstorm Wind | 1 |
Excessive Heat | 0 |
High Wind | 13 |
Lightning | 5 |
High Wind | 5 |
Avalanche | 3 |
Shuffle strategy
다음 쿼리는 상위 3 DamagedProperty
개 값 foreach EpisodeId
와 열 및 EpisodeId
State
.
StormEvents
| partition hint.strategy=shuffle by EpisodeId
(
top 3 by DamageProperty
| project EpisodeId, State, DamageProperty
)
| count
Output
Count |
---|
22345 |
명시적 원본을 사용하여 레거시 전략
다음 쿼리는 두 개의 하위 쿼리를 실행합니다.
- 이 경우
x == 1
쿼리는 해당StormEvents
행의 모든 행을 반환합니다InjuriesIndirect == 1
. - 이 경우
x == 2
쿼리는 해당StormEvents
행의 모든 행을 반환합니다InjuriesIndirect == 2
.
최종 결과는 이 두 하위 쿼리의 합합입니다.
range x from 1 to 2 step 1
| partition hint.strategy=legacy by x {StormEvents | where x == InjuriesIndirect}
| count
Output
Count |
---|
113 |
Partition reference
The following example shows how to use the as operator to give a "name" to each data partition and then reuse that name within the subquery. 이 방법은 전략과 legacy
만 관련이 있습니다.
T
| partition by Dim
(
as Partition
| extend MetricPct = Metric * 100.0 / toscalar(Partition | summarize sum(Metric))
)