New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CALCITE-6396] Add ADD_MONTHS function (enabled in Spark library) #3784
base: main
Are you sure you want to change the base?
Conversation
Quality Gate passedIssues Measures |
@@ -270,6 +270,13 @@ private static SqlCall transformConvert(SqlValidator validator, SqlCall call) { | |||
.andThen(SqlTypeTransforms.TO_NULLABLE_ALL), | |||
OperandTypes.SAME_SAME); | |||
|
|||
/** The "NVL(value, value)" function. */ | |||
@LibraryOperator(libraries = {SPARK}) | |||
public static final SqlBasicFunction ADD_MONTHS = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the Databricks documentation ADD_MONTHS takes an expression that evaluates to a date, and not a string: https://docs.databricks.com/en/sql/language-manual/functions/add_months.html
The result is also supposed to be a DATE.
I have already asked this question in a prior review. Reviews take a lot of energy and time, so please listen to the comments if you expect people to review your PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I encountered a weird bug that seems to take some time
+ "ADD_MONTHS\\(<CHARACTER>, <NUMERIC>\\)", false); | ||
|
||
final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.SPARK); | ||
f.checkScalar("ADD_MONTHS('2016-08-31', 1)", "2016-09-30", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should test with invalid dates too, and with dates prior to the Gregorian calendar introduction.
You should also test with negative values for the number of months.
https://issues.apache.org/jira/browse/CALCITE-6396