Skip to content

Commit

Permalink
[CALCITE-6241] Enable a few existing functions to hive library
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengJie1053 committed Sep 6, 2024
1 parent 8771e3f commit 6f1e4a5
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private SqlLibraryOperators() {

/** THE "DATE_ADD(date, interval)" function
* (BigQuery) adds the interval to the date. */
@LibraryOperator(libraries = {BIG_QUERY})
@LibraryOperator(libraries = {BIG_QUERY, HIVE})
public static final SqlFunction DATE_ADD =
SqlBasicFunction.create(SqlKind.DATE_ADD, ReturnTypes.ARG0_NULLABLE,
OperandTypes.DATE_INTERVAL)
Expand All @@ -132,7 +132,7 @@ private SqlLibraryOperators() {
public static final SqlFunction DATEADD =
new SqlTimestampAddFunction("DATEADD");

@LibraryOperator(libraries = {ORACLE, SPARK})
@LibraryOperator(libraries = {ORACLE, SPARK, HIVE})
public static final SqlFunction ADD_MONTHS =
SqlBasicFunction.create(SqlKind.ADD_MONTHS, ReturnTypes.ARG0_NULLABLE,
OperandTypes.DATE_ANY)
Expand All @@ -144,7 +144,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, POSTGRESQL})
@LibraryOperator(libraries = {MSSQL, POSTGRESQL, HIVE})
public static final SqlFunction DATEDIFF =
new SqlTimestampDiffFunction("DATEDIFF",
OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.DATE,
Expand Down Expand Up @@ -207,7 +207,7 @@ private static SqlCall transformConvert(SqlValidator validator, SqlCall call) {

/** The "DATE_SUB(date, interval)" function (BigQuery);
* subtracts interval from the date, independent of any time zone. */
@LibraryOperator(libraries = {BIG_QUERY})
@LibraryOperator(libraries = {BIG_QUERY, HIVE})
public static final SqlFunction DATE_SUB =
SqlBasicFunction.create(SqlKind.DATE_SUB, ReturnTypes.ARG0_NULLABLE,
OperandTypes.DATE_INTERVAL)
Expand Down Expand Up @@ -243,7 +243,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 @@ -274,7 +274,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 @@ -310,7 +310,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 @@ -319,7 +319,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 @@ -328,7 +328,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 @@ -337,7 +337,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 @@ -376,7 +376,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, MYSQL, ORACLE})
@LibraryOperator(libraries = {BIG_QUERY, MYSQL, ORACLE, HIVE})
public static final SqlFunction INSTR = new SqlPositionFunction("INSTR");

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

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

/** The "LEAST(value, value)" function. */
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, SPARK})
@LibraryOperator(libraries = {BIG_QUERY, ORACLE, SPARK, HIVE})
public static final SqlFunction LEAST =
SqlBasicFunction.create(SqlKind.LEAST,
ReturnTypes.LEAST_RESTRICTIVE.andThen(SqlTypeTransforms.TO_NULLABLE),
Expand Down Expand Up @@ -584,7 +584,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 @@ -1057,7 +1057,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 @@ -1069,7 +1069,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 @@ -1083,7 +1083,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 @@ -1749,7 +1749,7 @@ private static RelDataType deriveTypeMapFromEntries(SqlOperatorBinding opBinding
OperandTypes.MAP_FROM_ENTRIES);

/** The "STR_TO_MAP(string[, stringDelimiter[, keyValueDelimiter]])" function. */
@LibraryOperator(libraries = {SPARK})
@LibraryOperator(libraries = {SPARK, HIVE})
public static final SqlFunction STR_TO_MAP =
SqlBasicFunction.create(SqlKind.STR_TO_MAP,
ReturnTypes.IDENTITY_TO_MAP_NULLABLE,
Expand Down Expand Up @@ -1858,7 +1858,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 @@ -2420,14 +2420,14 @@ private static RelDataType deriveTypeMapFromEntries(SqlOperatorBinding opBinding
OperandTypes.INTEGER,
SqlFunctionCategory.NUMERIC);

@LibraryOperator(libraries = {BIG_QUERY, MYSQL, POSTGRESQL, SPARK})
@LibraryOperator(libraries = {BIG_QUERY, MYSQL, POSTGRESQL, SPARK, HIVE})
public static final SqlFunction MD5 =
SqlBasicFunction.create("MD5",
ReturnTypes.VARCHAR_NULLABLE,
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
Loading

0 comments on commit 6f1e4a5

Please sign in to comment.