簡體   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