Update Table Partition Information
Function
Recover (re-register) all partition information in a partitioned table that has not yet been registered in the metadata database. Typical application scenario: After manually adding a partition directory on OBS, use this command to refresh the newly added partition information into the metadata database. The new partitions can then be viewed using SHOW PARTITIONS.
Spark SQL provides two equivalent syntaxes: MSCK REPAIR TABLE and ALTER TABLE ... RECOVER PARTITIONS.
Syntax
- Method 1: MSCK REPAIR TABLE
MSCK REPAIR TABLE table_name;
- Method 2: RECOVER PARTITIONS
ALTER TABLE table_name RECOVER PARTITIONS;
Parameters
| Parameter | Description |
|---|---|
| table_name | Table name. The name of the partitioned table. The table must already exist. |
Precautions
- The partition directory name must be entered in the specified format, i.e., tablepath/partition_column_name=partition_column_value.
- The two syntaxes are functionally equivalent. Either one can be used.
- This command is mainly used for OBS partitioned table scenarios, to refresh metadata after manually adding a partition directory on OBS.
Example 1: Update Partition Information Using MSCK REPAIR TABLE
Update the partition information of table ptable in the metadata database.
MSCK REPAIR TABLE ptable;
Example 2: Update Partition Information Using RECOVER PARTITIONS
Use the equivalent syntax to update the partition information of table ptable.
ALTER TABLE ptable RECOVER PARTITIONS;
Example 3: Add an OBS Directory and Then Repair Partitions
Assuming the partition directory obs://bucketName/datapath/dt=2024-01-01 has been manually created on OBS, execute the following command to register the new partition in the metadata.
MSCK REPAIR TABLE sales_data;
Example 4: View the Partition List After Repairing Partitions
After repairing the partition information, use SHOW PARTITIONS to verify that the new partition has been registered.
-- Repair partitions. ALTER TABLE sales_data RECOVER PARTITIONS; -- View all partitions. SHOW PARTITIONS sales_data;
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