DISTRIBUTE BY
Function
The DISTRIBUTE BY clause is used to bucket (repartition) data by the specified fields, distributing rows with the same key value to the same Reducer. DISTRIBUTE BY does not perform sorting within the buckets.
Syntax
SELECT projectItem [, ...] FROM table_reference DISTRIBUTE BY expression [, ...]
Parameters
| Parameter | Description |
|---|---|
| expression | The bucketing expression. Supports single and multiple fields. Data is distributed to different Reducers based on the hash value of the expression. Rows with the same key value are guaranteed to be in the same Reducer. |
Precautions
- DISTRIBUTE BY is only responsible for bucketing, not for sorting within buckets.
- To sort after bucketing, use SORT BY in conjunction. DISTRIBUTE BY and SORT BY can use different fields.
- CLUSTER BY is a shorthand for DISTRIBUTE BY and SORT BY using the same fields.
Examples
Bucket by the score field:
SELECT * FROM student DISTRIBUTE BY score;
Bucket and then sort:
SELECT * FROM student DISTRIBUTE BY class_id SORT BY score DESC;
Bucket by multiple fields:
SELECT * FROM student DISTRIBUTE BY class_id, name;
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot