在where子句中配置具有当前日期的Hive select查询

时间:2018-11-02 09:35:04

标签: hive hiveql

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

  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中进行所有操作。我也不知道它是否可行。

1 个答案:

答案 0 :(得分:2)

您不需要子查询,可以直接将值与

进行比较
where run_date = from_unixtime(unix_timestamp(current_date),'yyyyMMdd')

或使用date_format

where run_date = date_format(current_date,'yyyyMMdd')
相关问题