我的目标是使用unix时间戳字段使用impala只查询昨天的数据。我不想硬编码日期,因为我希望这个脚本每天运行,只查询前一天。我正在使用python,并为开始和结束时间创建了字符串。
endtime存储为bigint,如下所示: 1561996779000
.
yesterday = dt.date.fromordinal(dt.date.today().toordinal()-1).strftime("%F")
yesterday_start = yesterday + ' 00:00:00'
yesterday_end = yesterday + ' 23:59:59'
yesterday_start
'2019-07-28 00:00:00'
yesterday_end
'2019-07-28 23:59:59'
我试过以下方法,但似乎都不管用:
cursor.execute('select sourceaddress, sourcehostname, sourceusername, endtime from proxy where endtime between unix_timestamp("+yesterday_start+") and unix_timestamp("+yesterday_end+")')
cursor.execute("select sourceaddress, sourcehostname, sourceusername, endtime from proxy where endtime between unix_timestamp("+yesterday_start+") and unix_timestamp("+yesterday_end+")")
cursor.execute("select sourceaddress, sourcehostname, sourceusername, endtime from proxy where endtime between unix_timestamp('yesterday_start') and unix_timestamp('yesterday_end')")
cursor.execute("SELECT * from proxy where endtime between unix_timestamp('"+yesterday_start+"') and unix_timestamp('"+yesterday_end+"')")
以下是 Impala 文档中的一个示例:
select unix_timestamp('2015-05-15 12:00:00');
+---------------------------------------+
| unix_timestamp('2015-05-15 12:00:00') |
+---------------------------------------+
| 1431691200 |
+---------------------------------------+
1条答案
按热度按时间30byixjq1#
仍在寻找更好的方法来实现这一点。不过,这是可行的。