English 中文(简体)
日期: hive中的trunc 工作不正确
原标题:date_trunc in hive is working incorrectly
  • 时间:2017-12-14 11:27:06
  •  标签:
  • hive
  • presto

我下面问:

select a.event_date,
    date_format(date_trunc( month , a.event_date),  %m/%d/%Y ) as date
from monthly_test_table a
order by 1;

产出:

 2017-09-15 | 09/01/2017
 2017-10-01 | 09/30/2017
 2017-11-01 | 11/01/2017

谁能告诉我,“2017-10-01”在使用日期_trunc之后将我的日期显示为“09/30/2017”。

Thanks in Advance...!

问题回答

You are reverse formatting so it is incorrect. Use the below Code

select a.event_date,
    date_format(date_trunc( month , a.event_date),  %Y/%m/%d ) as date
from monthly_test_table a
order by 1;

您可使用<代码>date_add,其逻辑是将1天(日期)细分为<代码>trunc。

For eg:

2017-10-01 - day( 2017-10-01 ) is 1 and you add 1-1=0 days 
2017-08-30 - day( 2017-08-30 ) is 30 and you add 1-30=-29 days 

I faced the same issue recently and resorted to using this logic.

date_add(from_unixtime(unix_timestamp(event_date, yyyy-MM-dd ), yyyy-MM-dd ),
         1-day(from_unixtime(unix_timestamp(event_date, yyyy-MM-dd ), yyyy-MM-dd ))
        )

PS:就一所知,在。 参考文件。





相关问题
How to connect to Hadoop/Hive from .NET

I am working on a solution where I will have a Hadoop cluster with Hive running and I want to send jobs and hive queries from a .NET application to be processed and get notified when they are done. I ...

Difference between Pig and Hive? Why have both? [closed]

My background - 4 weeks old in the Hadoop world. Dabbled a bit in Hive, Pig and Hadoop using Cloudera s Hadoop VM. Have read Google s paper on Map-Reduce and GFS (PDF link). I understand that- Pig s ...

Even data distribution on hadoop/hive

I am trying a small hadoop setup (for experimentation) with just 2 machines. I am loading about 13GB of data, a table of around 39 million rows, with a replication factor of 1 using Hive. My problem ...

Building Apache Hive - impossible to resolve dependencies

I am trying out the Apache Hive as per http://wiki.apache.org/hadoop/Hive/GettingStarted and am getting this error from Ivy: Downloaded file size doesn t match expected Content Length for http://...

热门标签