简体   繁体   English

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

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

I am currently trying to export Hive data to a csv file and CAN do it successfully until I have to add a where clause. 我目前正在尝试将Hive数据导出到csv文件,并且可以成功完成,直到我必须添加where子句。 For example, this works: 例如,这有效:

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

But if I try this: 但如果我试试这个:

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

I get an error saying "Invalid table alias or column reference" 我收到错误消息“无效的表别名或列引用”

I think the issue could be due to the quotes around the date but I can't find a combination that works. 我认为这个问题可能是由于日期的引用,但我找不到有效的组合。 Please help! 请帮忙!

Thank you 谢谢

Looks like you are using single quotes to wrap both the query and a string literal in the query. 看起来您使用单引号将查询和字符串文字包装在查询中。 Try using double quotes to wrap the query instead, so that it is clear where the query ends. 尝试使用双引号来包装查询,以便清楚查询结束的位置。

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

Hope that helps. 希望有所帮助。

Please see Hive Data Types Link . 请参阅Hive数据类型链接

Timestamps were introduced in Hive 0.8.0. 时间戳在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)

According to it your timestamps format is not supported to hive. 根据它,hive不支持你的时间戳格式。

Sample query is here : 示例查询在这里:

 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