【问题标题】:HiveQL select not working as expected on an external table with partitionsHiveQL 选择在具有分区的外部表上无法按预期工作
【发布时间】:2016-01-08 00:51:38
【问题描述】:

在我创建的自定义外部表上使用 select 语句时遇到问题。在使用 add partition 命令为年月日创建表后,我已经向该表添加了分区。

我面临的问题是,对于这个选择语句,我只得到一天 = 1 的一行,而我预计 5 天有 5 行。

select * from test_data where key = 'AX001';

对于这些陈述中的每一个,我都会得到一个结果。

select * from test_data where key = 'AX001' and day = 2;
select * from test_data where key = 'AX001' and day = 3;

但为此,我只得到一天 = 2 的一行。

select * from test_data where key = 'AX001' and day in (2,3);

知道这种行为的原因可能是什么吗?

【问题讨论】:

  • 什么版本的 Hive? (每个版本都会出现很多错误...) 您实际上将DAY 定义为字符串还是整数?将and DAY in (2,3) 替换为and (DAY =2 or DAY =3) 会发生什么?
  • Hive 0.13.1-CDH5.2.0..我在创建表语句“partitioned by (year int, month int, day int)”中将day定义为int .. and (day=2 or day=3) 也给了我一行 day =2。我刚刚在 (3,4,5) 中尝试了一天,并得到了一天 =3 的一行。

标签: hive hiveql


【解决方案1】:

显然这里的解决方案Hive MapReduce job splitting up files,这是我已经解决的另一个问题

select * from test_table where key = 'AX001' and day in (1,2,3);

set hive.input.format=org.apache.hadoop.hive.ql.io.CombineHiveInputFormat; 
select * from test_table where key = 'AX001' and day in (1,2,3);

set hive.input.format=org.apache.hadoop.hive.ql.io.HiveInputFormat;
select * from test_table where key = 'AX001' and day in (1,2,3);

只有最后一个给了我 3 个结果。前两个只返回两行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-22
    • 1970-01-01
    • 2021-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多