Casting TIMESTAMP to TIMESTAMP causes Function Invoker to fail
- Dominant language
- Java
- Stars
- 6.1k
- Forks
- 1.5k
- Avg merge
- 2d 55m
- Merged PRs (30d)
- 182
Description
The following test:
```java
{
String query = "SELECT DAYOFWEEK(CAST(NOW() AS TIMESTAMP)) as timestampColumn FROM testTable";
BrokerResponseNative brokerResponse = getBrokerResponse(query);
ResultTable resultTable = brokerResponse.getResultTable();
DataSchema dataSchema = resultTable.getDataSchema();
assertEquals(dataSchema,
new DataSchema(new String[]{"timestampColumn"}, new ColumnDataType[]{ColumnDataType.INT}));
List rows = resultTable.getRows();
assertEquals(rows.size(), 10);
for (int i = 0; i < 10; i++) {
Object[] row = rows.get(i);
assertEquals(row.length, 1);
assertEquals(row[0], 3);
}
}
```
Fails with the following exception:
```
Caused by: java.lang.NumberFormatException: For input string: "2022-11-23 09:56:37.877"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.base/java.lang.Long.parseLong(Long.java:692)
at java.base/java.lang.Long.parseLong(Long.java:817)
at org.apache.pinot.common.utils.PinotDataType$11.toLong(PinotDataType.java:609)
at org.apache.pinot.common.utils.PinotDataType$6.convert(PinotDataType.java:369)
at org.apache.pinot.common.utils.PinotDataType$6.convert(PinotDataType.java:318)
at org.apache.pinot.common.function.FunctionInvoker.convertTypes(FunctionInvoker.java:110)
at org.apache.pinot.sql.parsers.rewriter.CompileTimeFunctionsInvoker.invokeCompileTimeFunctionExpression(CompileTimeFunctionsInvoker.java:81)
... 34 more
```
The reason is that the `DayOfWeek` method takes in a long and the cast turns the timestamp into a string (instead of keeping it as a Timestamp type).
Contributor guide
Research direction
Start by tracing the failing query through FunctionInvoker.convertTypes and CompileTimeFunctionsInvoker.invokeCompileTimeFunctionExpression, then inspect the conversions in PinotDataType around the stack-trace locations. Reproduce the supplied DAYOFWEEK(CAST(NOW() AS TIMESTAMP)) query and confirm that the result schema and ten rows match the test expectations without the NumberFormatException.
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
- 45/100