Any idea why we convert division of long/long to d...
# general
y
Any idea why we convert division of long/long to double by default? for example, in presto
select (1618900560000 - 1618437600000)/604800000*604800000
returns 0, while
SELECT (1618900560000 - 1618437600000)/604800000
returns 0.76547 ?
a
It is in large part due to
ArithmeticFunctions.java
which outputs a
double
for any arithmetic computation.
y
yeha, my question is that shall we consider the behavior with other SQL engines like Hive/Presto/Mysql
a
I would definitely second making it more standardized 🙂 I have been trying to do some of that with my PRs on numerical type conversion (#6811, #6927).
@User wanted to change ArithmeticFunctions.java to use templates so that we can return the right output type for given input types.
y
yeah, that will be awesome
in the meanwhile, any workaround that you suggest to make the query above to output the same as presto?
s
Use cast function in the meantime?
j
What is the standard sql behavior? Are all numbers without decimal point treated as integer/long?
a
yes, the output of simple arithmetic computation on integer/long values should be integer/long.
s
This needs to be fixed across Pinot. Like sum function over long returns double.
y
+1
also, why
Copy code
SELECT 
cast((1618900560000 - 1618437600000) / 604800000 as integer ) * 604800000
returns 462959999.99999994
but
Copy code
SELECT 
cast((1618900560000 - 1618437600000) / 604800000 as integer )
returns 0 ?
x
I guess this is a bug in the literal evaluation
y
more than literal..
i am debugging a query
x
Ideally this query should directly return
Not hitting servers
y
Copy code
cast((column - 1618437600000) / 604800000 as integer ) * 604800000
returns incorrect data
x
let’s create a github issue to track this?
y
yeah, we should
btw, is there a workaround to achieve bucketing?
you can pick the function
Copy code
ToEpoch<TIME_UNIT>Bucket(timeInMillis, bucketSize)
y
i see
so in my case, i group by week
x
date_trunc? then?
y
i can use
ToEpochDayBucket(time, 7)
?
x
then you need to multiply 7 * 86400000 to get the millis
or try
DATETIMECONVERT(ts, '1:MILLISECONDS:EPOCH', '1:MILLISECONDS:EPOCH', '7:DAYS')
y
yup, get it works
x
also
DATETRUNC('week', ts, 'MILLISECONDS')
so really up to you
you can try multiple functions and find the most efficient one
they are all different implementations
y
i see
j
@User @User Please take a look ^^
👍 2