Skip to content

Commit

Permalink
[CALCITE-6800] Enable a few existing functions to hive library
Browse files Browse the repository at this point in the history
  • Loading branch information
xuyu committed Jan 25, 2025
1 parent b78fba4 commit 5c1de46
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private static SqlCall transformConvert(SqlValidator validator, SqlCall call) {
}

/** The "NVL(value, value)" function. */
@LibraryOperator(libraries = {ORACLE, REDSHIFT, SPARK, HIVE})
@LibraryOperator(libraries = {ORACLE, REDSHIFT, SPARK})
public static final SqlBasicFunction NVL =
SqlBasicFunction.create(SqlKind.NVL,
ReturnTypes.LEAST_RESTRICTIVE
Expand Down Expand Up @@ -2483,7 +2483,7 @@ 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,
Expand Down
6 changes: 3 additions & 3 deletions site/_docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2852,7 +2852,7 @@ In the following:
| b | DATE(string) | Equivalent to `CAST(string AS DATE)`
| b | DATE(year, month, day) | Returns a DATE value for *year*, *month*, and *day* (all of type INTEGER)
| q r f | DATEADD(timeUnit, integer, datetime) | Equivalent to `TIMESTAMPADD(timeUnit, integer, datetime)`
| q r f h | DATEDIFF(timeUnit, datetime, datetime2) | Equivalent to `TIMESTAMPDIFF(timeUnit, datetime, datetime2)`
| q r f | DATEDIFF(timeUnit, datetime, datetime2) | Equivalent to `TIMESTAMPDIFF(timeUnit, datetime, datetime2)`
| q | DATEPART(timeUnit, datetime) | Equivalent to `EXTRACT(timeUnit FROM datetime)`
| b | DATETIME(date, time) | Converts *date* and *time* to a TIMESTAMP
| b | DATETIME(date) | Converts *date* to a TIMESTAMP value (at midnight)
Expand Down Expand Up @@ -2936,9 +2936,9 @@ In the following:
| s | MAP_FROM_ENTRIES(arrayOfRows) | Returns a map created from an arrays of row with two fields. Note that the number of fields in a row must be 2. Note that calcite is using the LAST_WIN strategy
| s | STR_TO_MAP(string [, stringDelimiter [, keyValueDelimiter]]) | Returns a map after splitting the *string* into key/value pairs using delimiters. Default delimiters are ',' for *stringDelimiter* and ':' for *keyValueDelimiter*. Note that calcite is using the LAST_WIN strategy
| s | SUBSTRING_INDEX(string, delim, count) | Returns the substring from *string* before *count* occurrences of the delimiter *delim*. If *count* is positive, everything to the left of the final delimiter (counting from the left) is returned. If *count* is negative, everything to the right of the final delimiter (counting from the right) is returned. The function substring_index performs a case-sensitive match when searching for *delim*.
| b m p r s | MD5(string) | Calculates an MD5 128-bit checksum of *string* and returns it as a hex string
| b m p r s h | MD5(string) | Calculates an MD5 128-bit checksum of *string* and returns it as a hex string
| m | MONTHNAME(date) | Returns the name, in the connection's locale, of the month in *datetime*; for example, for a locale of en, it will return 'February' for both DATE '2020-02-10' and TIMESTAMP '2020-02-10 10:10:10', and for a locale of zh, it will return '二月'
| o r s h | NVL(value1, value2) | Returns *value1* if *value1* is not null, otherwise *value2*
| o r s | NVL(value1, value2) | Returns *value1* if *value1* is not null, otherwise *value2*
| o r s | NVL2(value1, value2, value3) | Returns *value2* if *value1* is not null, otherwise *value3*
| b | OFFSET(index) | When indexing an array, wrapping *index* in `OFFSET` returns the value at the 0-based *index*; throws error if *index* is out of bounds
| b | ORDINAL(index) | Similar to `OFFSET` except *index* begins at 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5725,7 +5725,8 @@ void testBitGetFunc(SqlOperatorFixture f, String functionName) {
false);
final List<SqlLibrary> libraries =
ImmutableList.of(SqlLibrary.BIG_QUERY, SqlLibrary.MYSQL,
SqlLibrary.POSTGRESQL, SqlLibrary.REDSHIFT, SqlLibrary.SPARK);
SqlLibrary.POSTGRESQL, SqlLibrary.REDSHIFT,
SqlLibrary.SPARK, SqlLibrary.HIVE);
final Consumer<SqlOperatorFixture> consumer = f -> {
f.checkString("md5(x'')",
"d41d8cd98f00b204e9800998ecf8427e",
Expand Down Expand Up @@ -10990,7 +10991,7 @@ private void testSysDateFunc(Pair<String, Hook.Closeable> pair) {
};
final List<SqlLibrary> libraries =
list(SqlLibrary.BIG_QUERY, SqlLibrary.ORACLE, SqlLibrary.POSTGRESQL,
SqlLibrary.REDSHIFT, SqlLibrary.SPARK);
SqlLibrary.REDSHIFT, SqlLibrary.SPARK, SqlLibrary.HIVE);
f0.forEachLibrary(libraries, consumer);
}

Expand Down Expand Up @@ -11774,7 +11775,7 @@ void assertSubFunReturns(boolean binary, String s, int start,
};
final List<SqlLibrary> libraries =
list(SqlLibrary.BIG_QUERY, SqlLibrary.ORACLE, SqlLibrary.POSTGRESQL,
SqlLibrary.REDSHIFT, SqlLibrary.SPARK);
SqlLibrary.REDSHIFT, SqlLibrary.SPARK, SqlLibrary.HIVE);
f0.forEachLibrary(libraries, consumer);
}

Expand All @@ -11790,7 +11791,7 @@ void assertSubFunReturns(boolean binary, String s, int start,
};
final List<SqlLibrary> libraries =
list(SqlLibrary.BIG_QUERY, SqlLibrary.ORACLE, SqlLibrary.POSTGRESQL,
SqlLibrary.REDSHIFT, SqlLibrary.SPARK);
SqlLibrary.REDSHIFT, SqlLibrary.SPARK, SqlLibrary.HIVE);
f0.forEachLibrary(libraries, consumer);
}

Expand Down Expand Up @@ -11897,7 +11898,7 @@ void assertSubFunReturns(boolean binary, String s, int start,
@Test void testNvlFunc() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlLibraryOperators.NVL, VmName.EXPAND);
final SqlOperatorFixture f12 = f
SqlOperatorFixture f12 = f
.withLibrary(SqlLibrary.ORACLE)
.forOracle(SqlConformanceEnum.ORACLE_12);
f12.checkString("nvl('abc', 'de')", "abc", "VARCHAR(3) NOT NULL");
Expand Down

0 comments on commit 5c1de46

Please sign in to comment.