【问题标题】:output hive data into csv with a where clause使用 where 子句将 hive 数据输出到 csv
【发布时间】:2013-08-19 08:15:34
【问题描述】:

我目前正在尝试将 Hive 数据导出到 csv 文件,并且可以成功执行此操作,直到我必须添加 where 子句。例如,这有效:

 hive -e 'select * from table' | sed 's/[\t]/,/g'  > outputfile.csv

但如果我试试这个:

 hive -e 'select * from table where timestamp > '1-Aug-2013'' | sed 's/[\t]/,/g'  > outputfile.csv

我收到一条错误消息,提示“无效的表别名或列引用”

我认为问题可能是由于日期周围的引号引起的,但我找不到有效的组合。请帮忙!

谢谢

【问题讨论】:

    标签: sql csv hive quotes hiveql


    【解决方案1】:

    看起来您正在使用单引号来包装查询和查询中的字符串文字。尝试使用双引号来包装查询,以便清楚查询结束的位置。

    hive -e "select * from table where timestamp > '1-Aug-2013'" | sed 's/[\t]/,/g'  > outputfile.csv
    

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      请参阅 Hive 数据类型Link

      在 Hive 0.8.0 中引入了时间戳。

      Supported conversions:
      Integer numeric types: Interpreted as UNIX timestamp in seconds
      Floating point numeric types: Interpreted as UNIX timestamp in seconds
      with decimal precision.
      Strings: JDBC compliant java.sql.Timestamp format "YYYY-MM-DD HH:MM:SS.fffffffff"
      (9 decimal place precision)
      

      据此,hive 不支持您的时间戳格式。

      示例查询在这里:

       hive -e "select * from table where timestamp > '2013-08-19 00:00:00';exit;" | sed 's/[\t]/,/g' > outputfile.csv
      

      【讨论】:

      • 感谢您的回复,我可以调整 where 子句以使用完整的时间戳,但是您对引号问题有什么建议吗?再次感谢您的跟进!
      • 您为时间戳提供的数据类型。时间戳的数据类型应该是 bigint。请提供创建表查询和您修改后的选择查询。如果可能,请提供一些示例数据。
      • 使用这样的查询:hive -e "select * from table where timestamp > '2013-08-19 00:00:00';exit;" | sed 's/[\t]/,/g' > outputfile.csv。如果它现在有效,请告诉我们。
      猜你喜欢
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      • 2019-10-03
      • 1970-01-01
      • 2016-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多