如果我在AWS Athena中创建了这样的表:
CREATE EXTERNAL TABLE table (
`timestamp` BIGINT,
`id` STRING,
)PARTITIONED BY (
date_column STRING
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' STORED AS INPUTFORMAT 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat' LOCATION 's3://bucket/key' TBLPROPERTIES ( 'parquet.compress'='SNAPPY', 'CrawlerSchemaDeserializerVersion'='1.0', 'CrawlerSchemaSerializerVersion'='1.0', 'classification'='parquet')
添加数据后,date_column如下所示:
date_column
date=2018102300
date=2018091500 //(so Sept 15, 2018)
我只想获取9月份的数据,但无法构成正确的查询:
到目前为止,我有引发日期格式错误的消息:
SELECT * FROM table
where date_parse(date_column, 'date=%Y%m%d') >= date_parse('date=2018090100', 'date=%Y%m%d') and date_parse(date_column, 'date=%Y%m%d') < date_parse('date=2018100100', 'date=%Y%m%d')
答案 0 :(得分:0)
您传递给函数date_parse()的参数不正确。应采用以下格式以获取正确的时间戳格式
select date_parse('2018091500', '%Y%m%d%H') will fetch you 2018-09-15 00:00:00.000
您可以重写查询以获取9月的结果
select * from table where date_parse(date_column, '%Y%m%d%H') between date '2018-09-01' and date '2018-09-30'