【发布时间】:2022-01-03 21:56:21
【问题描述】:
我正在使用 Hive,IDE 是 Hue。我正在尝试为我的分区键选择不同的组合键。
我原表的定义如下:
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';
以上代码运行正常。但是当我使用 date_day 作为分区键创建一个新表时,该表是空的,我需要运行 MSCK 修复表。但是,我收到以下错误:
编译语句时出错:FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.ddl.DDLTask
分区键为date_year、date_month时,MSCK正常工作。
我收到错误的表的表定义如下:
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_year` string,
`date_month` string
)
PARTITIONED BY (
`date_day` 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';
在此之后,以下查询为空:
Select * From `my_hive_db`.`my_table` Limit 10;
因此我运行了以下命令:
MSCK REPAIR TABLE `my_hive_db`.`my_table`;
我收到错误:编译语句时出错:FAILED:执行错误,从 org.apache.hadoop.hive.ql.ddl.DDLTask 返回代码 1
我检查了this link,因为这正是我遇到的错误,但使用提供的解决方案:
set hive.msck.path.validation=ignore;
MSCK REPAIR TABLE table_name;
我得到一个不同的错误:
处理语句时出错:无法在运行时修改 hive.msck.path.validation。它不在允许在运行时修改的参数列表中。
我认为我收到这些错误的原因是有超过 2 亿条 date_day 具有空值的记录。
有 31 个不同的 date-day not null 值。 我想用 32 个分区对我的表进行分区,每个分区都有一个不同的 date_day 字段值,并且所有空值都进入不同的分区。有没有办法这样做(按具有空值的列分区)?
如果这可以通过spark实现,我也愿意使用。
这是通过重新创建表来更改分区键的更大问题的一部分in this link in answer to my other question。
感谢您的帮助。
【问题讨论】:
-
无法在运行时修改 hive.msck.path.validation。 --> 您只需要更改配置并重新启动 hive 即可解决此问题。或者将该值添加到您可以在运行时修改的参数列表中。
-
您似乎正在尝试重新分区现有表。分区是表位置下的文件夹,包含数据文件。您不能更改现有表上的分区架构。数据应根据分区组织在文件夹中。创建新表并从第一个表加载数据,请参阅 stackoverflow.com/a/53598283/2700344 和 stackoverflow.com/a/68760607/2700344 和 stackoverflow.com/a/68740919/2700344
-
添加到leftjoin的评论。 Hive 是读取模式,它包含解释数据的定义。如果您更改如何读取数据的定义,它不会更改数据。它只是尝试读取您定义的数据。
-
关于分区列中的空值:在插入时使用 NVL() 将它们替换为其他内容。数据文件中不存在分区列,它只是s3中的元数据+文件夹,看起来像key=value。如果在插入过程中 value 为 null,hive 会将此类记录放入 HIVE_DEFAULT_PARTITION 文件夹中。它会造成额外的混乱。所以用别的东西替换空值
-
Matt 我无法更改配置,因为它由数据湖团队管理。我正在使用该平台作为外部开发人员。有没有其他办法?
标签: apache-spark hadoop hive database-partitioning