Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

caicancai
Copy link
Member

@caicancai caicancai commented May 3, 2024

site/_docs/reference.md Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented May 5, 2024

@caicancai caicancai requested a review from mihaibudiu May 7, 2024 00:31
@@ -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 =
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

Copy link
Member Author

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",
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants