我在 Hive 中有一個表,我想洗掉它的磁區鍵,以便以后使用其他磁區鍵。
Parquet 檔案的位置在 Amazon S3 中。我正在處理的表按 date_year 和 date_month 列進行磁區。總共有143個磁區。現在我試圖通過執行以下命令來洗掉磁區:
Alter Table `my_hive_db`.`my_table`
Drop PARTITION (`date_year` , `date_month` );
但是,我收到此錯誤:
編譯陳述句時出錯:FAILED:ParseException line 48:28 不匹配的輸入“,”期望在 drop partition 陳述句中設定為 null。

如果有幫助,我的表定義如下:
CREATE External Table `my_hive_db`.`my_table`(
`col_id` bigint,
`result_section__col2` string,
`result_section_col3` string ,
`result_section_col4` string,
`result_section_col5` string,
`result_section_col6__label` string,
`result_section_col7__label_id` bigint ,
`result_section_text` string ,
`result_section_unit` string,
`result_section_col` string ,
`result_section_title` string,
`result_section_title_id` bigint,
`col13` string,
`timestamp` bigint,
`date_day` string
)
PARTITIONED BY (
`date_year` string,
`date_month` string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION
's3a://some/where/in/amazon/s3';
最重要的是,我真的不想洗掉底層檔案。我只想洗掉磁區鍵,以便稍后我可以使用不同的列組合重新磁區表。問題是如何更改表,洗掉磁區,但仍將這些磁區鍵保留在表中作為普通列。
我愿意通過 Hive 或 Spark 實作這一目標。然而,Hive 在這個階段更受歡迎。
感謝您的寶貴意見。
uj5u.com熱心網友回復:
我認為您不能根據不同的列重新磁區配置單元表。因為磁區映射到 HDFS 中的物理檔案夾,無法按需重新分配。
所以,唯一的選擇是——
- 將表備份到 bkp 表中。
- 洗掉原始表并使用新磁區重新創建表。
- 從備份插入新的原始表。
或者,您可以創建一個帶有新磁區的新表并從舊表插入,然后洗掉舊表并重命名新表。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/365958.html
