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-6241] Enable a few existing functions to hive library #4165

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
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ private SqlLibraryOperators() {

/** The "DATE_ADD(date, numDays)" function
* (Spark) Returns the date that is num_days after start_date. */
@LibraryOperator(libraries = {SPARK})
@LibraryOperator(libraries = {SPARK, HIVE})
public static final SqlFunction DATE_ADD_SPARK =
SqlBasicFunction.create(SqlKind.DATE_ADD, ReturnTypes.DATE_NULLABLE,
OperandTypes.DATE_ANY)
.withFunctionType(SqlFunctionCategory.TIMEDATE);

/** The "DATE_SUB(date, numDays)" function
* (Spark) Returns the date that is num_days before start_date.*/
@LibraryOperator(libraries = {SPARK})
@LibraryOperator(libraries = {SPARK, HIVE})
public static final SqlFunction DATE_SUB_SPARK =
SqlBasicFunction.create(SqlKind.DATE_SUB, ReturnTypes.DATE_NULLABLE,
OperandTypes.DATE_ANY)
Expand All @@ -162,7 +162,7 @@ private SqlLibraryOperators() {
* <p>MySQL has "DATEDIFF(date, date2)" and "TIMEDIFF(time, time2)" functions
* but Calcite does not implement these because they have no "timeUnit"
* argument. */
@LibraryOperator(libraries = {MSSQL, REDSHIFT, SNOWFLAKE})
@LibraryOperator(libraries = {MSSQL, REDSHIFT, SNOWFLAKE, HIVE})
public static final SqlFunction DATEDIFF =
new SqlTimestampDiffFunction("DATEDIFF",
OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.DATE,
Expand Down Expand Up @@ -261,7 +261,7 @@ private static SqlCall transformConvert(SqlValidator validator, SqlCall call) {
};

/** The "DECODE(v, v1, result1, [v2, result2, ...], resultN)" function. */
@LibraryOperator(libraries = {ORACLE, REDSHIFT, SPARK})
@LibraryOperator(libraries = {ORACLE, REDSHIFT, SPARK, HIVE})
public static final SqlFunction DECODE =
SqlBasicFunction.create(SqlKind.DECODE, DECODE_RETURN_TYPE,
OperandTypes.VARIADIC);
Expand Down Expand Up @@ -292,7 +292,7 @@ private static SqlCall transformConvert(SqlValidator validator, SqlCall call) {
}

/** The "NVL(value, value)" function. */
@LibraryOperator(libraries = {ORACLE, REDSHIFT, SPARK})
@LibraryOperator(libraries = {ORACLE, REDSHIFT, SPARK, HIVE})
public static final SqlBasicFunction NVL =
SqlBasicFunction.create(SqlKind.NVL,
ReturnTypes.LEAST_RESTRICTIVE
Expand Down Expand Up @@ -327,7 +327,7 @@ private static RelDataType deriveTypePad(SqlOperatorBinding binding, RelDataType
}

/** The "LPAD(original_value, return_length[, pattern])" function. */
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, POSTGRESQL, SPARK})
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, POSTGRESQL, SPARK, HIVE})
public static final SqlFunction LPAD =
SqlBasicFunction.create(
"LPAD",
Expand All @@ -336,7 +336,7 @@ private static RelDataType deriveTypePad(SqlOperatorBinding binding, RelDataType
SqlFunctionCategory.STRING);

/** The "RPAD(original_value, return_length[, pattern])" function. */
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, POSTGRESQL, SPARK})
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, POSTGRESQL, SPARK, HIVE})
public static final SqlFunction RPAD =
SqlBasicFunction.create(
"RPAD",
Expand All @@ -345,7 +345,7 @@ private static RelDataType deriveTypePad(SqlOperatorBinding binding, RelDataType
SqlFunctionCategory.STRING);

/** The "LTRIM(string)" function. */
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, POSTGRESQL, SPARK})
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, POSTGRESQL, SPARK, HIVE})
public static final SqlFunction LTRIM =
SqlBasicFunction.create(SqlKind.LTRIM,
ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE)
Expand All @@ -354,7 +354,7 @@ private static RelDataType deriveTypePad(SqlOperatorBinding binding, RelDataType
.withFunctionType(SqlFunctionCategory.STRING);

/** The "RTRIM(string)" function. */
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, POSTGRESQL, SPARK})
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, POSTGRESQL, SPARK, HIVE})
public static final SqlFunction RTRIM =
SqlBasicFunction.create(SqlKind.RTRIM,
ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE)
Expand Down Expand Up @@ -401,7 +401,7 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
public static final SqlFunction STRPOS = new SqlPositionFunction("STRPOS");

/** The "INSTR(string, substring [, position [, occurrence]])" function. */
@LibraryOperator(libraries = {BIG_QUERY, HIVE, MYSQL, ORACLE})
@LibraryOperator(libraries = {BIG_QUERY, HIVE, MYSQL, ORACLE, HIVE})
public static final SqlFunction INSTR = new SqlPositionFunction("INSTR");

/** Generic "SUBSTR(string, position [, substringLength ])" function. */
Expand Down Expand Up @@ -484,7 +484,7 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
SqlFunctionCategory.STRING);

/** The "GREATEST(value, value)" function. */
@LibraryOperator(libraries = {BIG_QUERY, ORACLE})
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, HIVE})
public static final SqlFunction GREATEST =
SqlBasicFunction.create(SqlKind.GREATEST,
ReturnTypes.LEAST_RESTRICTIVE.andThen(SqlTypeTransforms.TO_NULLABLE),
Expand All @@ -499,7 +499,7 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
OperandTypes.SAME_VARIADIC);

/** The "LEAST(value, value)" function. */
@LibraryOperator(libraries = {BIG_QUERY, ORACLE})
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, HIVE})
public static final SqlFunction LEAST =
SqlBasicFunction.create(SqlKind.LEAST,
ReturnTypes.LEAST_RESTRICTIVE.andThen(SqlTypeTransforms.TO_NULLABLE),
Expand Down Expand Up @@ -613,7 +613,7 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
/** The "REGEXP_REPLACE(value, regexp, rep)"
* function. Replaces all substrings of value that match regexp with
* {@code rep} and returns modified value. */
@LibraryOperator(libraries = {MYSQL, ORACLE, REDSHIFT})
@LibraryOperator(libraries = {MYSQL, ORACLE, REDSHIFT, HIVE})
public static final SqlFunction REGEXP_REPLACE_3 =
SqlBasicFunction.create("REGEXP_REPLACE", ReturnTypes.VARCHAR_NULLABLE,
OperandTypes.STRING_STRING_STRING, SqlFunctionCategory.STRING);
Expand Down Expand Up @@ -1093,7 +1093,7 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
ReturnTypes.ARG0_NULLABLE_VARYING,
OperandTypes.CBSTRING_INTEGER, SqlFunctionCategory.STRING);

@LibraryOperator(libraries = {BIG_QUERY, MYSQL, POSTGRESQL, SPARK})
@LibraryOperator(libraries = {BIG_QUERY, MYSQL, POSTGRESQL, SPARK, HIVE})
public static final SqlFunction REPEAT =
SqlBasicFunction.create("REPEAT",
ReturnTypes.VARCHAR_NULLABLE,
Expand All @@ -1105,7 +1105,7 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
SqlBasicFunction.create("RIGHT", ReturnTypes.ARG0_NULLABLE_VARYING,
OperandTypes.CBSTRING_INTEGER, SqlFunctionCategory.STRING);

@LibraryOperator(libraries = {MYSQL, SPARK})
@LibraryOperator(libraries = {MYSQL, SPARK, HIVE})
public static final SqlFunction SPACE =
SqlBasicFunction.create("SPACE",
ReturnTypes.VARCHAR_NULLABLE,
Expand All @@ -1119,7 +1119,7 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
OperandTypes.STRING_STRING,
SqlFunctionCategory.STRING);

@LibraryOperator(libraries = {BIG_QUERY, MYSQL, POSTGRESQL, ORACLE})
@LibraryOperator(libraries = {BIG_QUERY, MYSQL, POSTGRESQL, ORACLE, HIVE})
public static final SqlFunction SOUNDEX =
SqlBasicFunction.create("SOUNDEX",
ReturnTypes.VARCHAR_4_NULLABLE,
Expand Down Expand Up @@ -1921,7 +1921,7 @@ private static RelDataType deriveTypeMapFromEntries(SqlOperatorBinding opBinding

/** The "TO_DATE(string1, string2)" function; casts string1
* to a DATE using the format specified in string2. */
@LibraryOperator(libraries = {ORACLE, REDSHIFT})
@LibraryOperator(libraries = {ORACLE, REDSHIFT, HIVE})
public static final SqlFunction TO_DATE =
SqlBasicFunction.create("TO_DATE",
ReturnTypes.DATE_NULLABLE,
Expand Down Expand Up @@ -2490,7 +2490,7 @@ private static RelDataType deriveTypeMapFromEntries(SqlOperatorBinding opBinding
OperandTypes.STRING.or(OperandTypes.BINARY),
SqlFunctionCategory.STRING);

@LibraryOperator(libraries = {BIG_QUERY, MYSQL, POSTGRESQL, SPARK})
@LibraryOperator(libraries = {BIG_QUERY, MYSQL, POSTGRESQL, SPARK, HIVE})
public static final SqlFunction SHA1 =
SqlBasicFunction.create("SHA1",
ReturnTypes.VARCHAR_NULLABLE,
Expand Down Expand Up @@ -2541,7 +2541,7 @@ private static RelDataType deriveTypeMapFromEntries(SqlOperatorBinding opBinding

/** The "LOG(numeric1 [, numeric2 ]) " function. Returns the logarithm of numeric2
* to base numeric1.*/
@LibraryOperator(libraries = {MYSQL, SPARK})
@LibraryOperator(libraries = {MYSQL, SPARK, HIVE})
public static final SqlFunction LOG_MYSQL =
SqlBasicFunction.create(SqlKind.LOG,
ReturnTypes.DOUBLE_FORCE_NULLABLE,
Expand Down
Loading
Loading