【问题标题】:Hive. Can not refer to partitions in where clause蜂巢。不能在 where 子句中引用分区
【发布时间】:2012-12-17 16:46:49
【问题描述】:

我创建了一个按日期分区的表。但不能在 where 子句中使用分区。 这是过程 第一步:

     CREATE TABLE new_table (
           a string,
           b string
      )
     PARTITIONED BY (dt string);

第二步:

        Insert overwrite table new_table partition (dt=$date)
        Select a, b from my_table
        where dt = '$date

表已创建。

           Describe new_table;
           a string
           b string
           dt string

问题

           select * from new_table where dt='$date'

返回空集。

            select * from new_table 

返回 a、b 和 dt。

有谁知道这可能是什么原因?

谢谢

【问题讨论】:

  • 如果你运行SHOW PARTITIONS new_table;会发生什么?
  • 试过了,但无法重现您的问题;做了几个排列,包括动态分区。如前所述,验证您的查询、检查分区等。
  • 我的错,我在做; > hive -e 'select * from new_table where dt='$date'' 和单引号导致问题。我花了 3 个小时才看到这个:) 谢谢你的回答

标签: hadoop hql hive


【解决方案1】:

Sahara,where 子句中的分区确实有效。您是否有可能在谓词的 RHS 中指定了错误的值?

您可能还想查看/user/hive/warehouse/new_table(默认情况下)中的数据,以查看其中的数据是否符合您的预期。

【讨论】:

    【解决方案2】:

    尝试插入

    Insert overwrite table new_table partition (dt=$date)
        Select a, b, dt from my_table
        where dt = '$date'
    

    【讨论】:

      猜你喜欢
      • 2014-11-01
      • 2015-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-26
      • 2015-06-17
      相关资源
      最近更新 更多