Dynamic Partitioning
The dynamic partitioning syntax allows you to specify a partition column name without a specific value when inserting data into a partitioned table. The partition value is provided by the corresponding column in the SELECT clause. Only after a SQL statement is executed can you determine which partitions will be generated based on the values generated by the partition column.
To resolve the data skew issue that occurs in the map phase when data is inserted using dynamic partitioning, you can find the partitions with a large number of records, prune them, and then insert data separately. The procedure is as follows:
- Run the following commands to query the partitions with a large number of records:
SELECT ds, hh, COUNT(*) AS cnt FROM dwd_alsc_ent_shop_info_hi GROUP BY ds, hh ORDER BY cnt DESC;
The following table lists some partitions.
ds
hh
cnt
20200928
17
1052800
20191017
17
1041234
20210928
17
1034332
20190328
17
1000321
20210504
1
19
20191003
20
18
20200522
1
18
20220504
1
18
- Run the following commands to insert data of small partitions and then separately insert data of large partitions:
-- Insert data of small partitions in batches. INSERT OVERWRITE TABLE data_demo3 PARTITION(ds, hh) SELECT * FROM dwd_alsc_ent_shop_info_hi WHERE concat(ds, hh) NOT IN ('2020092817','2019101717','2021092817','2019032817'); -- Insert data of large partitions separately (you can use repartition to control concurrency). INSERT OVERWRITE TABLE data_demo3 PARTITION(ds, hh) SELECT * FROM dwd_alsc_ent_shop_info_hi WHERE concat(ds, hh) IN ('2020092817','2019101717','2021092817','2019032817'); -- Perform verification. SELECT ds, hh, COUNT(*) AS cnt FROM dwd_alsc_ent_shop_info_hi GROUP BY ds, hh ORDER BY cnt DESC;
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