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-6664] Replace GREATEST, LEAST functions in Spark library wit… #4090

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions babel/src/test/resources/sql/spark.iq
Original file line number Diff line number Diff line change
Expand Up @@ -667,4 +667,34 @@ SELECT KEY, "set" IS NULL AS N FROM COMPLEX;

!ok

SELECT greatest(1, null, 3) AS x;
+---+
| X |
+---+
| 3 |
+---+
(1 row)

!ok

SELECT least(1, 2, null, 3) AS x;
+---+
| X |
+---+
| 1 |
+---+
(1 row)

!ok

SELECT greatest(null, null) AS x;
+---+
| X |
+---+
| |
+---+
(1 row)

!ok

# End spark.iq
6 changes: 3 additions & 3 deletions core/src/main/java/org/apache/calcite/sql/SqlKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,10 @@ public enum SqlKind {
/** {@code NVL2} function (Oracle, Spark). */
NVL2,

/** {@code GREATEST} function (Oracle, Spark). */
/** {@code GREATEST} function (Oracle). */
GREATEST,

/** {@code GREATEST} function (PostgreSQL). */
/** {@code GREATEST} function (PostgreSQL, Spark). */
GREATEST_PG,

/** The two-argument {@code CONCAT} function (Oracle). */
Expand All @@ -503,7 +503,7 @@ public enum SqlKind {
/** {@code LEAST} function (Oracle). */
LEAST,

/** {@code LEAST} function (PostgreSQL). */
/** {@code LEAST} function (PostgreSQL, Spark). */
LEAST_PG,

/** {@code LOG} function. (Mysql, Spark). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,28 +480,30 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
SqlFunctionCategory.STRING);

/** The "GREATEST(value, value)" function. */
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, SPARK})
@LibraryOperator(libraries = {BIG_QUERY, ORACLE})
public static final SqlFunction GREATEST =
SqlBasicFunction.create(SqlKind.GREATEST,
ReturnTypes.LEAST_RESTRICTIVE.andThen(SqlTypeTransforms.TO_NULLABLE),
OperandTypes.SAME_VARIADIC);

/** The "GREATEST(value, value)" function. */
@LibraryOperator(libraries = {POSTGRESQL})
/** The "GREATEST(value, value)" function. Identical to the standard <code>GREATEST</code>
* function except it skips null values and only returns null if all parameters are nulls. */
@LibraryOperator(libraries = {POSTGRESQL, SPARK})
public static final SqlFunction GREATEST_PG =
SqlBasicFunction.create("GREATEST", SqlKind.GREATEST_PG,
ReturnTypes.LEAST_RESTRICTIVE.andThen(SqlTypeTransforms.TO_NULLABLE),
OperandTypes.SAME_VARIADIC);

/** The "LEAST(value, value)" function. */
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, SPARK})
@LibraryOperator(libraries = {BIG_QUERY, ORACLE})
public static final SqlFunction LEAST =
SqlBasicFunction.create(SqlKind.LEAST,
ReturnTypes.LEAST_RESTRICTIVE.andThen(SqlTypeTransforms.TO_NULLABLE),
OperandTypes.SAME_VARIADIC);

/** The "GREATEST(value, value)" function. */
@LibraryOperator(libraries = {POSTGRESQL})
/** The "LEAST(value, value)" function. Identical to the standard <code>LEAST</code>
* function except it skips null values and only returns null if all parameters are nulls. */
@LibraryOperator(libraries = {POSTGRESQL, SPARK})
public static final SqlFunction LEAST_PG =
SqlBasicFunction.create("LEAST", SqlKind.LEAST_PG,
ReturnTypes.LEAST_RESTRICTIVE.andThen(SqlTypeTransforms.TO_NULLABLE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11664,7 +11664,7 @@ void assertSubFunReturns(boolean binary, String s, int start,
"VARCHAR(5) NOT NULL");
};
final List<SqlLibrary> libraries =
list(SqlLibrary.BIG_QUERY, SqlLibrary.ORACLE, SqlLibrary.SPARK);
list(SqlLibrary.BIG_QUERY, SqlLibrary.ORACLE);
f0.forEachLibrary(libraries, consumer);
}

Expand All @@ -11686,7 +11686,8 @@ void assertSubFunReturns(boolean binary, String s, int start,
f.checkScalar("greatest(CAST(NULL AS INTEGER), CAST(NULL AS INTEGER))", isNullValue(),
"INTEGER");
};
final List<SqlLibrary> libraries = list(SqlLibrary.POSTGRESQL, SqlLibrary.REDSHIFT);
final List<SqlLibrary> libraries =
list(SqlLibrary.POSTGRESQL, SqlLibrary.REDSHIFT, SqlLibrary.SPARK);
f0.forEachLibrary(libraries, consumer);
}

Expand All @@ -11710,7 +11711,7 @@ void assertSubFunReturns(boolean binary, String s, int start,
"VARCHAR(5) NOT NULL");
};
final List<SqlLibrary> libraries =
list(SqlLibrary.BIG_QUERY, SqlLibrary.ORACLE, SqlLibrary.SPARK);
list(SqlLibrary.BIG_QUERY, SqlLibrary.ORACLE);
f0.forEachLibrary(libraries, consumer);
}

Expand All @@ -11732,7 +11733,8 @@ void assertSubFunReturns(boolean binary, String s, int start,
f.checkScalar("least(CAST(NULL AS INTEGER), CAST(NULL AS INTEGER))", isNullValue(),
"INTEGER");
};
final List<SqlLibrary> libraries = list(SqlLibrary.POSTGRESQL, SqlLibrary.REDSHIFT);
final List<SqlLibrary> libraries =
list(SqlLibrary.POSTGRESQL, SqlLibrary.REDSHIFT, SqlLibrary.SPARK);
NobiGo marked this conversation as resolved.
Show resolved Hide resolved
f0.forEachLibrary(libraries, consumer);
}

Expand Down
Loading