Sql 使用where子句将配置单元数据输出到csv中

Sql 使用where子句将配置单元数据输出到csv中,sql,csv,hive,quotes,hiveql,Sql,Csv,Hive,Quotes,Hiveql,我目前正在尝试将配置单元数据导出到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

我目前正在尝试将配置单元数据导出到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
我收到一个错误,说“无效的表别名或列引用”

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


谢谢

请查看配置单元数据类型

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

请参阅配置单元数据类型

Hive0.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 -e "select * from table where timestamp > '2013-08-19 00:00:00';exit;" | 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

希望这能有所帮助。

谢谢您的回复,我可以调整where子句以使用完整的时间戳,但是您对引号的问题有什么建议吗?再次感谢您的跟进!您为时间戳提供的数据类型。时间戳的数据类型应为bigint。请提供创建表查询和修改的select查询。如果可能,请提供一些示例数据。使用如下查询:hive-e“从时间戳为'2013-08-19 00:00:00'的表中选择*”;exit;“| sed's/[\t]/,/g'>outputfile.csv”。如果它现在起作用,请让我们知道。谢谢你的回复,我可以调整where子句以使用完整的时间戳,但是你对报价的问题有什么建议吗?再次感谢您的跟进!您为时间戳提供的数据类型。时间戳的数据类型应为bigint。请提供创建表查询和修改的select查询。如果可能,请提供一些示例数据。使用如下查询:hive-e“从时间戳为'2013-08-19 00:00:00'的表中选择*”;exit;“| sed's/[\t]/,/g'>outputfile.csv”。如果它现在起作用,请让我们知道。