【问题标题】:Hive select query with current date in where clause在 where 子句中使用当前日期的 Hive 选择查询
【发布时间】:2018-11-02 09:35:03
【问题描述】:

我是蜂巢新手。我有一个如下表:

  EntriesRunDate (
     id string,
     run_date string
  );

在上表中,当关联的 run_date 是今天的日期(其中 run_date 的格式为 YYYYMMDD)时,将处理一个条目。

要选择这样的行,我编写了以下配置单元查询:

 select * from EntriesRunDate where run_date = (select from_unixtime(unix_timestamp(),'YYYYMMDD'));

但在运行上述查询时,我收到以下错误:

FAILED: SemanticException Line 0:-1 Unsupported SubQuery Expression ''YYYYMMDD'': Only SubQuery expressions that are top level conjuncts are allowed

虽然我认为有一种方法可以通过在命令行中设置一个变量并在 hive 中重新使用它来做到这一点,但我想在 hive 中做所有事情。我也不确定它是否可行。

【问题讨论】:

    标签: hive hiveql


    【解决方案1】:

    不需要子查询,直接比较值即可

    where run_date = from_unixtime(unix_timestamp(current_date),'yyyyMMdd')
    

    或使用date_format

    where run_date = date_format(current_date,'yyyyMMdd')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-24
      • 2013-09-04
      • 1970-01-01
      • 2017-05-07
      相关资源
      最近更新 更多