Nuta
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować się zalogować lub zmienić katalog.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
Applies to: ✅Microsoft Fabric✅Azure Data Explorer✅Azure Monitor✅Microsoft Sentinel
Operator partycji dzieli rekordy tabeli wejściowej na wiele tabel podrzędnych zgodnie z wartościami w kolumnie klucza. Operator uruchamia podzapytywanie w każdej podtabliwie i tworzy pojedynczą tabelę wyjściową, która jest unionem wyników wszystkich podzapytania.
Operator partycji jest przydatny, gdy trzeba wykonać podzapytywanie tylko w podzestawie wierszy należących do tego samego klucza partycji, a nie kwerendy całego zestawu danych. These subqueries could include aggregate functions, window functions, top N and others.
Operator partycji obsługuje kilka strategii operacji podzapytania:
- 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 ] byColumn(TransformationSubQuery)
T|partition [ hint.strategy=legacy ] [ Hints ] byColumn{SubQueryWithSource}
Learn more about syntax conventions.
Parameters
| Name | Typ | Required | Description |
|---|---|---|---|
| T | string |
✔️ | Źródło tabelaryczne danych wejściowych. |
| Strategy | string |
Wartość legacy, shufflelub native. Ta wskazówka definiuje strategię wykonywania operatora partycji.
Jeśli żadna strategia nie zostanie określona, zostanie użyta legacy strategia. 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 |
✔️ | Wyrażenie przekształcenia tabelarycznego. The source is implicitly the subtables produced by partitioning the records of T. Each subtable is homogenous on the value of Column.
Wyrażenie musi zawierać tylko jeden wynik tabelaryczny i nie powinien mieć innych typów instrukcji, takich jak let instrukcje. |
| SubQueryWithSource | string |
✔️ | Wyrażenie tabelaryczne, które zawiera własne źródło tabelaryczne, takie jak odwołanie do tabeli. 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).
Wyrażenie musi zawierać tylko jeden wynik tabelaryczny i nie powinien mieć innych typów instrukcji, takich jak let instrukcje. |
| 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 | Typ | Strategy | Description |
|---|---|---|---|
hint.shufflekey |
string |
shuffle | Klucz partycji używany do uruchamiania operatora partycji ze strategią shuffle . |
hint.materialized |
bool |
legacy | Jeśli ustawiono wartość true, zmaterializuje źródło operatora partition. Domyślna wartość to false. |
hint.concurrency |
int |
legacy | Określa liczbę partycji, które mają być uruchamiane równolegle. Domyślna wartość to 16. |
hint.spread |
int |
legacy | Określa sposób dystrybucji partycji między węzłami klastra. Domyślna wartość to 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
Operator zwraca związek wyników poszczególnych podzapytania.
Strategies
The partition operator supports several strategies of subquery operation: native, shuffle, and legacy.
Note
Rozróżnienie między strategiami native i shuffle umożliwia obiektowi wywołującym wskazanie kardynalności i strategii wykonywania podzapytania. Ten wybór może mieć wpływ na czas ukończenia podzapytania, ale nie zmienia wyniku końcowego.
Native strategy
Ta strategia powinna być stosowana, gdy liczba odrębnych wartości klucza partycji nie jest duża, w przybliżeniu w tysiącach.
Podzapytywanie musi być przekształceniem tabelarycznym, które nie określa źródła tabelarycznego. Źródło jest niejawne i jest przypisywane zgodnie z partycjami w tabeli podrzędnej. Only certain supported operators can be used in the subquery. Nie ma żadnych ograniczeń dotyczących liczby partycji.
Aby użyć tej strategii, określ wartość hint.strategy=native.
Shuffle strategy
Ta strategia powinna być stosowana, gdy liczba odrębnych wartości klucza partycji jest duża w milionach.
Podzapytywanie musi być przekształceniem tabelarycznym, które nie określa źródła tabelarycznego. Źródło jest niejawne i jest przypisywane zgodnie z partycjami w tabeli podrzędnej. Only certain supported operators can be used in the subquery. Nie ma żadnych ograniczeń dotyczących liczby partycji.
Aby użyć tej strategii, określ wartość hint.strategy=shuffle. For more information about shuffle strategy and performance, see shuffle query.
Obsługiwane operatory dla strategii natywnych i mieszania
Poniższa lista operatorów może być używana w podzapytaniach ze strategiami natywnymi lub shuffle:
- 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
- Operatory odwołujące się do źródła tabeli innego niż partycje podrzędne nie są zgodne z strategiami
nativei .shuffleFor 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 byoperator. Jest obsługiwany tylko wtedy, gdy określono parametryfromi .to
Legacy strategy
Ze względów legacy historycznych strategia jest strategią domyślną. However, we recommend favoring the native or shuffle strategies, as the legacy approach is limited to 64 partitions and is less efficient.
W niektórych scenariuszach legacy strategia może być konieczna ze względu na obsługę dołączania źródła tabelarycznego do podzapytania. 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).
Jeśli podzapytywanie jest przekształceniem tabelarycznym bez źródła tabelarycznego, źródło jest niejawne i opiera się na partycjach podrzędnych.
Aby użyć tej strategii, określ hint.strategy=legacy lub pomiń wszelkie inne wskazania strategii.
Note
An error occurs if the partition column, Column, contains more than 64 distinct values.
Examples
W przykładach w tej sekcji pokazano, jak używać składni, aby ułatwić rozpoczęcie pracy.
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. Może być konieczne zmodyfikowanie nazwy tabeli w przykładowym zapytaniu, aby było zgodne z tabelą w obszarze roboczym.
Znajdowanie najważniejszych wartości
W niektórych przypadkach bardziej wydajne i łatwiejsze jest pisanie zapytania przy użyciu partition operatora niż użycie top-nested operatora. Następujące zapytanie uruchamia podzapytywanie i summarizetop dla każdego State rozpoczynającego się od W: "WYOMING", "WASHINGTON", "WEST VIRGINIA" i "WISCONSIN".
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
Następujące zapytanie zwraca 2 EventType pierwsze wartości TotalInjuries dla każdego State , co zaczyna się od "W":
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
Poniższe zapytanie zwraca 3 DamagedProperty pierwsze wartości foreach EpisodeId oraz kolumny EpisodeId i State.
StormEvents
| partition hint.strategy=shuffle by EpisodeId
(
top 3 by DamageProperty
| project EpisodeId, State, DamageProperty
)
| count
Output
| Count |
|---|
| 22345 |
Starsza strategia z jawnym źródłem
Następujące zapytanie uruchamia dwa podzapytania:
- Gdy
x == 1zapytanie zwraca wszystkie wiersze zStormEventstych elementów o wartościInjuriesIndirect == 1. - Gdy
x == 2zapytanie zwraca wszystkie wiersze zStormEventstych elementów o wartościInjuriesIndirect == 2.
Ostatnim wynikiem jest związek tych dwóch podzapytania.
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. Takie podejście jest istotne tylko dla legacy strategii.
T
| partition by Dim
(
as Partition
| extend MetricPct = Metric * 100.0 / toscalar(Partition | summarize sum(Metric))
)