You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hive.apache.org by Alexander Pivovarov <ap...@gmail.com> on 2015/04/01 08:26:57 UTC

TIMESTAMP to DATE conversion for negative unix time

Hi Everyone

I noticed interesting behaviour for timestamp to date hive type conversion
for negative unix time.

For example:

select cast(cast('1966-01-01 00:00:01' as timestamp) as date);
1966-02-02

Should it work this way?

Another example
select last_day(cast('1966-01-31 00:00:01' as timestamp));
OK
1966-02-28


more details:
Date: 1966-01-01 00:00:01
unix time UTC: -126230399

daysSinceEpoch=−126230399000 / 86400000 = -1460.999988
int daysSinceEpoch = -1460
DateWritable having daysSinceEpoch=-1460 is 1966-01-02

Re: TIMESTAMP to DATE conversion for negative unix time

Posted by Alexander Pivovarov <ap...@gmail.com>.
fixed
https://issues.apache.org/jira/browse/HIVE-10178

https://reviews.apache.org/r/32715/diff/#

On Tue, Mar 31, 2015 at 11:27 PM, Alexander Pivovarov <ap...@gmail.com>
wrote:

> correction for the first example
> select cast(cast('1966-01-01 00:00:01' as timestamp) as date);
> 1966-01-02
>
>
> On Tue, Mar 31, 2015 at 11:26 PM, Alexander Pivovarov <
> apivovarov@gmail.com> wrote:
>
>> Hi Everyone
>>
>> I noticed interesting behaviour for timestamp to date hive type
>> conversion for negative unix time.
>>
>> For example:
>>
>> select cast(cast('1966-01-01 00:00:01' as timestamp) as date);
>> 1966-02-02
>>
>> Should it work this way?
>>
>> Another example
>> select last_day(cast('1966-01-31 00:00:01' as timestamp));
>> OK
>> 1966-02-28
>>
>>
>> more details:
>> Date: 1966-01-01 00:00:01
>> unix time UTC: -126230399
>>
>> daysSinceEpoch=−126230399000 / 86400000 = -1460.999988
>> int daysSinceEpoch = -1460
>> DateWritable having daysSinceEpoch=-1460 is 1966-01-02
>>
>>
>>
>>
>>
>>
>

Re: TIMESTAMP to DATE conversion for negative unix time

Posted by Alexander Pivovarov <ap...@gmail.com>.
correction for the first example
select cast(cast('1966-01-01 00:00:01' as timestamp) as date);
1966-01-02


On Tue, Mar 31, 2015 at 11:26 PM, Alexander Pivovarov <ap...@gmail.com>
wrote:

> Hi Everyone
>
> I noticed interesting behaviour for timestamp to date hive type conversion
> for negative unix time.
>
> For example:
>
> select cast(cast('1966-01-01 00:00:01' as timestamp) as date);
> 1966-02-02
>
> Should it work this way?
>
> Another example
> select last_day(cast('1966-01-31 00:00:01' as timestamp));
> OK
> 1966-02-28
>
>
> more details:
> Date: 1966-01-01 00:00:01
> unix time UTC: -126230399
>
> daysSinceEpoch=−126230399000 / 86400000 = -1460.999988
> int daysSinceEpoch = -1460
> DateWritable having daysSinceEpoch=-1460 is 1966-01-02
>
>
>
>
>
>