calcite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Julian Hyde <jh...@apache.org>
Subject Re: A question regarding the INTERVAL_DAY_TIME
Date Thu, 10 Dec 2015 00:59:00 GMT
Remember that that piece of code is used only for literals. The value
used at run time might be represented differently than how it is
represented in the literal.

That piece of code optimizes casts. So if you write CAST(3 AS INTERVAL
MINUTE) - i.e. convert from an INTEGER literal to an INTERVAL MINUTE
value then it creates an INTERVAL MINUTE literal. What should the
value be? Well, all interval literals are stored in milliseconds, so
the value should be 180,000. Hence the multiplier.

When Hive is converting RexLiteral(INTERVAL_MINUTE, 180000) back to
Hive format it should convert to however Hive represents interval
literals.

Julian


On Wed, Dec 9, 2015 at 3:43 PM, Pengcheng Xiong <pxiong@apache.org> wrote:
> Hi Julian,
>
>     Thanks a lot for your response. However, I still have two questions
>
> (1) will milliseconds be enough? Hive would like to support nanoseconds and
> Vertica also supports microseconds
> https://my.vertica.com/docs/5.0/HTML/Master/9255.htm
> Thus, the internal representation may be better decided by user himself
> rather than fixed at milliseconds?
>
> (2) How about the other way for casting, i.e., casting char to an interval?
>
> select interval_day_time('2 1:2:3') from src limit 1;
>
>     For example, Hive will translate this into a RexLiteral of
> 176523000.000000, which is the millisecond representation of "2 1:2:3".
> Then when it goes through the ReduceExpressionRule, RexReplacer will call
> RexBuilder to make a cast. And in the L527 of RexBuilder, the value of
> 176523000.000000 will be divided by the multiplier and becomes the new
> value. However, Hive does not want any multiplier as it is already in
> millisecond format... Or is there any way to specify the multiplier as 1?
>
> Thanks.
>
> Best
> Pengcheng
>
>
>
> On Wed, Dec 9, 2015 at 2:18 PM, Julian Hyde <jhyde@apache.org> wrote:
>
>> What would you expect the following to yield?
>>
>>   VALUES CAST(INTERVAL '3' HOUR AS INTEGER)
>>
>> Like all intervals (except year-month intervals) the interval is
>> internally represented in milliseconds, in this case 10,800,000, but
>> when converted to a string or a numeric it is measured in hours, i.e.
>> 3.
>>
>> Julian
>>
>>
>> On Wed, Dec 9, 2015 at 2:05 PM, Pengcheng Xiong <pxiong@apache.org> wrote:
>> > Hi all,
>> >
>> >     While I was trying to debug something in Hive, I found some code in
>> > RexBuilder which makes me confused.
>> >
>> > L527 it says
>> >
>> > {code}
>> >
>> > final long multiplier =
>> >
>> >               literal.getType().getIntervalQualifier().getStartUnit()
>> >
>> >                   .multiplier;
>> > {code}
>> >
>> >     I saw it was committed
>> >
>> > commit 45b58ab07223cbb94c7cbbb9a1434a2b01a9497f
>> > Author: julianhyde <julianhyde@gmail.com>
>> > Date:   Tue Jan 7 14:57:17 2014 -0800
>> >
>> >     Reformat org.eigenbase code.
>> >
>> >     Could Julian or someone explain how this multiplier is used? It looks
>> > to me that it is redundant. I do not need that multiplier and "value"
>> > itself is enough. Thanks!
>> >
>> > Best
>> > Pengcheng
>>

Mime
View raw message