Impala查询昨天的数据而不键入日期(可能使用python)
数据已被解析为日期时间“2018-03-08 00:00:00”。我可以通过说出“2018-03-08 00:00:00”和“2018-03-08 24:00:00”之间的位置来获得2018年3月8日的数据。但是我想以某种方式使用Impala日期时间函数,这样我就可以每天运行它,而不用手动输入每个日期。我已经阅读了一些文档,但仍然感到困惑 查询黑斑羚 即使我可以在查询之前用python定义昨天,如下所示:Impala查询昨天的数据而不键入日期(可能使用python),python,sql,hadoop,impala,Python,Sql,Hadoop,Impala,数据已被解析为日期时间“2018-03-08 00:00:00”。我可以通过说出“2018-03-08 00:00:00”和“2018-03-08 24:00:00”之间的位置来获得2018年3月8日的数据。但是我想以某种方式使用Impala日期时间函数,这样我就可以每天运行它,而不用手动输入每个日期。我已经阅读了一些文档,但仍然感到困惑 查询黑斑羚 即使我可以在查询之前用python定义昨天,如下所示: yesterday = str((pd.to_datetime('today') - pd
yesterday = str((pd.to_datetime('today') - pd.Timedelta(days=1)).date())
并以某种方式将其合并到Impala查询中。您的问题并不完全清楚,但据我所知,您希望使用Impala/python日期时间函数来自动执行查询,以选择一天的数据。下面是我在黑斑羚身上的例子
-- to_date - function will cut the date from timestamp
-- now() - gives you the current timestamp
select to_date(now()) as currentDate,
to_date(now() + interval 1 days) as currentDatePlusaDay,
now() as currentTimestamp,
now() + interval 1 day as currentTimestampPlusaDay,
concat(to_date(now() - interval 1 days), ' 00:00:00') as whereBetweenMin,
concat(to_date(now() - interval 1 days), ' 24:00:00') as whereBetweenMax ;
--Result
+-------------+---------------------+-------------------------------+-------------------------------+---------------------+---------------------+
| currentdate | currentdateplusaday | currenttimestamp | currenttimestampplusaday | wherebetweenmin | wherebetweenmax |
+-------------+---------------------+-------------------------------+-------------------------------+---------------------+---------------------+
| 2018-03-23 | 2018-03-24 | 2018-03-23 12:14:36.073281000 | 2018-03-24 12:14:36.073281000 | 2018-03-22 00:00:00 | 2018-03-22 24:00:00 |
+-------------+---------------------+-------------------------------+-------------------------------+---------------------+---------------------+
--You can probably use wherebetweenmin & wherebetweenmax
从表中选择子字符串(时间,1,10)作为日期字符串,子字符串(时间,12,2)作为小时字符串,count(*)作为countString,其中concat(到日期(现在()-间隔5天),“00:00:00”)和concat(到日期(现在()-间隔5天),“24:00:00”)之间的时间按子字符串(时间,1,10)分组,子字符串(时间,12,2)以1,2的顺序排列@roh@sectechguy如果这个答案是你问题的解决方案,那么你应该接受它。
-- to_date - function will cut the date from timestamp
-- now() - gives you the current timestamp
select to_date(now()) as currentDate,
to_date(now() + interval 1 days) as currentDatePlusaDay,
now() as currentTimestamp,
now() + interval 1 day as currentTimestampPlusaDay,
concat(to_date(now() - interval 1 days), ' 00:00:00') as whereBetweenMin,
concat(to_date(now() - interval 1 days), ' 24:00:00') as whereBetweenMax ;
--Result
+-------------+---------------------+-------------------------------+-------------------------------+---------------------+---------------------+
| currentdate | currentdateplusaday | currenttimestamp | currenttimestampplusaday | wherebetweenmin | wherebetweenmax |
+-------------+---------------------+-------------------------------+-------------------------------+---------------------+---------------------+
| 2018-03-23 | 2018-03-24 | 2018-03-23 12:14:36.073281000 | 2018-03-24 12:14:36.073281000 | 2018-03-22 00:00:00 | 2018-03-22 24:00:00 |
+-------------+---------------------+-------------------------------+-------------------------------+---------------------+---------------------+
--You can probably use wherebetweenmin & wherebetweenmax