如何从 Apache Drill 中的时间戳字段中提取日期部分?

How to extract the date part from a timestamp field in apache drill?

我在钻table(比如date_time)中有一个时间戳字段,我怎样才能只从中提取日期字段。看到很多日期操作函数 here 但其中 none 有帮助。

这是示例数据,

+------------------------+
|       date_time        |
+------------------------+
| 2017-01-01 03:45:58.0  |
| 2017-01-01 21:42:20.0  |
| 2017-01-01 15:08:47.0  |
| 2017-01-01 19:59:39.0  |
| 2017-01-01 22:37:24.0  |
+------------------------+

我需要如下输出,

+-------------+
|  date_time  |
+-------------+
| 2017-01-01  |
| 2017-01-01  |
| 2017-01-01  |
| 2017-01-01  |
| 2017-01-01  |
+-------------+

我不想做字符串操作。 :)

除了第一个评论中的内容——即 cast(date_time as date)——另一个选项是:

select to_date(datetime)

Date/Time Functions page that you referenced should really have a link to https://drill.apache.org/docs/data-type-conversion/#other-data-type-conversions,显示如何将自定义格式应用于时间戳字段:

select to_char(date_time, 'yyyyMMdd');

如果 table 中的日期格式正确,请尝试此操作。一个简单的方法

select cast(date_time as date) date_time from table