繁体   English   中英

使用where子句将hive数据输出到csv中

[英]output hive data into csv with a where clause

我目前正在尝试将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

我收到错误消息“无效的表别名或列引用”

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

谢谢

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

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

希望有所帮助。

请参阅Hive数据类型链接

时间戳在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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM