问题描述
我使用以下命令在 hive 中创建了一个外部表:
create external table if not exists summary(
`Restaurant ID` INT,`Restaurant Name` STRING)
PARTITIONED BY (p_filedate INT,p_country_name STRING)
stored as ORC;
现在,当我尝试使用以下方法填充表格时:
INSERT overwrite table zomato_summary partition(p_filedate,p_country_name)
SELECT
`restaurant id`,ISNULL( `restaurant name`,'NA')
FROM Sales;
我收到以下错误:
Failed: SemanticException [Error 10011]: Invalid function any
可能 Hive 将 partition 关键字视为 UDF,这就是它导致错误的原因。
请建议多列动态分区的替代方法。
解决方法
动态加载分区时,select 应包含分区列(与表 DDL 中的顺序相同)。
例如像这样:
SET hive.exec.dynamic.partition=true;
SET hive.exec.dynamic.partition.mode=nonstrict;
INSERT overwrite table zomato_summary partition(p_filedate,p_country_name)
SELECT
`restaurant id`,ISNULL( `restaurant name`,'NA'),--ISNULL exists not in all versions,use COALESCE or NVL
current_date,--or proper column from sales
country_name
FROM Sales;