apache / pinot

Apache Pinot - A realtime distributed OLAP datastore
https://pinot.apache.org/
Apache License 2.0
5.39k stars 1.26k forks source link

String equality in Case statement inside date transform function throws #8992

Open priyen opened 2 years ago

priyen commented 2 years ago

Given a query as follows:

select
  cast(
    date_trunc(
      'day',
      datetime_convert(
        datetime_convert(
          date_timestamp + FromEpochDays(case when 'week' = 'week'  then 1 else 0 end),
          '1:MILLISECONDS:EPOCH',
          '1:MILLISECONDS:SIMPLE_DATE_FORMAT:yyyy-MM-dd tz(UTC)',
          '1:MILLISECONDS'
          ),.........

this throws with exception

ProcessingException(errorCode:150, message:SQLParsingError:
org.apache.pinot.sql.parsers.SqlCompilationException: Caught exception while invoking method: public static boolean org.apache.pinot.common.function.scalar.ComparisonFunctions.equals(double,double) with arguments: [week, week]
    at org.apache.pinot.sql.parsers.rewriter.CompileTimeFunctionsInvoker.invokeCompileTimeFunctionExpression(CompileTimeFunctionsInvoker.java:87)
    at org.apache.pinot.sql.parsers.rewriter.CompileTimeFunctionsInvoker.invokeCompileTimeFunctionExpression(CompileTimeFunctionsInvoker.java:65)
    at org.apache.pinot.sql.parsers.rewriter.CompileTimeFunctionsInvoker.invokeCompileTimeFunctionExpression(CompileTimeFunctionsInvoker.java:65)
    at org.apache.pinot.sql.parsers.rewriter.CompileTimeFunctionsInvoker.invokeCompileTimeFunctionExpression(CompileTimeFunctionsInvoker.java:65)
...
Caused by: java.lang.NumberFormatException: For input string: "week"
    at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054)
    at java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
    at java.base/java.lang.Double.parseDouble(Double.java:543)
    at org.apache.pinot.common.utils.PinotDataType$11.toDouble(PinotDataType.java:621))

-- Previously this worked fine in an older version of Pinot, if you change the 'week' = 'week' to 2 = 2, it works, so something is wrong with the literal parsing. This is inside a case statement, so string comparison should be supported.

Jackie-Jiang commented 2 years ago

The exception is thrown from the scalar function version of the equals, which means this operation is applied to an aggregation result? Do you have the exactly same query working in the old version of Pinot? I don't think scalar function version cast is supported in the old version, so maybe the old query is not applied to the aggregation result, but regular transform (applied to the column)?