Tanner Clary created CALCITE-6045: ------------------------------------- Summary: CURRENT_TIMESTAMP has incorrect return type Key: CALCITE-6045 URL: https://issues.apache.org/jira/browse/CALCITE-6045 Project: Calcite Issue Type: Bug Reporter: Tanner Clary
When trying to work on CALCITE-6021, I noticed that {{CURRENT_TIMESTAMP}} currently returns type {{TIMESTAMP}} when it should be {{TIMESTAMP_WITH_LOCAL_TIME_ZONE}}. After modifying it, I noticed function was returning the time from (UTC - System TZ) hours ago. For example, I am in {{America/Los_Angeles}} and if I called the function at {{2023-10-10 13:28:00 America/Los_Angeles}}, it would return {{2023-10-10 06:28:00 America/Los_Angeles}}. I think this is because the DataContext {{CURRENT_TIMESTAMP}} variable, which is meant to represent milliseconds since epoch UTC, actually has the timezone offset applied in {{CalciteConnectionImpl#DataContextImpl}} [here|https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java#L442]. To be clear: it is meant to represent millis since epoch UTC, but instead it is millis since epoch [system tz], as I understand it. Additionally, I believe the {{getString()}} method for timestamps in AvaticaResultSet should behave similarly to [{{SqlFunctions#timestampWithLocalTimezoneToString()}}|https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java#L4021] when dealing with a {{TIMESTAMP WITH LOCAL TIME ZONE}}. Right now, it does not take the timezone into consideration so although it represents the accurate instant in time, it displays differently than {{CAST(CURRENT_TIMESTAMP AS VARCHAR)}}. For example, {{SELECT CURRENT_TIMESTAMP, CAST(CURRENT_TIMESTAMP AS VARCHAR)}}, with the correct return type, returns something like: {{2023-10-10 13:28:00 | 2023-10-10 06:28:00.000 America/Los_Angeles}} -- This message was sent by Atlassian Jira (v8.20.10#820010)