[CALCITE-6311] Support PostgreSQL DATE_PART#3794
Conversation
normanj-bitquill
commented
May 21, 2024
- PostgreSQL expects the first argument to be a string
- The first argument can be any expression that results in a valid time unit string
- RedShift and PostgreSQL share the same implementation
|
Since RedShift and PostgreSQL share the same implementation, they both now support strings or raw time units as the first argument. If a string is used for the first argument, Validation of the string argument is done against the map generated in |
| // May need to convert the first argument from a String to a TimeUnitRange | ||
| final Object timeUnitRangeObj = translator.getLiteralValue(argValueList.get(0)); | ||
| final TimeUnitRange timeUnitRange; | ||
| if (timeUnitRangeObj instanceof String) { |
There was a problem hiding this comment.
what happens if this conversion fails?
Can you have a test for that?
There was a problem hiding this comment.
During validation, it will test the value and return an error if not valid.
https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java#L3484
I have added a test for this error. It results in an error message like this:
java.sql.SQLException: Error while executing SQL "select date_part('foo', timestamp '2022-06-03 12:15:48.678')": From line 1, column 18 to line 1, column 22: 'foo' is not a valid time frame
| case "MILLENNIUM": | ||
| return TimeUnit.MILLENNIUM; | ||
| default: | ||
| throw new IllegalArgumentException(); |
There was a problem hiding this comment.
Maybe a more verbose error message could be useful.
There was a problem hiding this comment.
I have added a message to the exception.
|
you have a line which exceeds 100 chars. |
|
170e0c6 to
c5f143d
Compare
* PostgreSQL expects the first argument to be a string * The first argument can be any expression that results in a valid time unit string * RedShift and PostgreSQL share the same implementation
c5f143d to
dbec568
Compare
|
@mihaibudiu The commits have been squashed. The CI failure is from running out of heap space in the sonar task. |


