String equality in Case statement inside date transform function throws
- Dominant language
- Java
- Stars
- 6.1k
- Forks
- 1.5k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 189
Description
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.
Contributor guide
Research direction
Start by reproducing the query through CompileTimeFunctionsInvoker.java, then inspect PinotDataType.java and the comparison path shown in the stack trace. Add a regression test for string equality inside a CASE expression and verify that the query no longer raises NumberFormatException while numeric comparisons continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100