Skip to content

Commit

Permalink
[CALCITE-6424] Enable RLIKE function in MySQL library
Browse files Browse the repository at this point in the history
  • Loading branch information
NobiGo committed Jun 4, 2024
1 parent eb92f96 commit be9b860
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -982,12 +982,12 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
new SqlLikeOperator("NOT ILIKE", SqlKind.LIKE, true, false);

/** The regex variant of the LIKE operator. */
@LibraryOperator(libraries = {SPARK, HIVE})
@LibraryOperator(libraries = {SPARK, HIVE, MYSQL})
public static final SqlSpecialOperator RLIKE =
new SqlLikeOperator("RLIKE", SqlKind.RLIKE, false, true);

/** The regex variant of the NOT LIKE operator. */
@LibraryOperator(libraries = {SPARK, HIVE})
@LibraryOperator(libraries = {SPARK, HIVE, MYSQL})
public static final SqlSpecialOperator NOT_RLIKE =
new SqlLikeOperator("NOT RLIKE", SqlKind.RLIKE, true, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5160,9 +5160,13 @@ private void checkLiteral2(String expression, String expected) {
String expectedHive = "SELECT \"product_name\"\n"
+ "FROM \"foodmart\".\"product\"\n"
+ "WHERE \"product_name\" RLIKE '.+@.+\\\\..+'";
String expectedMysql = "SELECT \"product_name\"\n"
+ "FROM \"foodmart\".\"product\"\n"
+ "WHERE \"product_name\" RLIKE '.+@.+\\\\..+'";
sql(query)
.withLibrary(SqlLibrary.SPARK).ok(expectedSpark)
.withLibrary(SqlLibrary.HIVE).ok(expectedHive);
.withLibrary(SqlLibrary.HIVE).ok(expectedHive)
.withLibrary(SqlLibrary.MYSQL).ok(expectedMysql);
}

@Test void testNotRlike() {
Expand All @@ -5171,7 +5175,16 @@ private void checkLiteral2(String expression, String expected) {
String expected = "SELECT \"product_name\"\n"
+ "FROM \"foodmart\".\"product\"\n"
+ "WHERE \"product_name\" NOT RLIKE '.+@.+\\\\..+'";
sql(query).withLibrary(SqlLibrary.SPARK).ok(expected);
String expectedHive = "SELECT \"product_name\"\n"
+ "FROM \"foodmart\".\"product\"\n"
+ "WHERE \"product_name\" NOT RLIKE '.+@.+\\\\..+'";
String expectedMysql = "SELECT \"product_name\"\n"
+ "FROM \"foodmart\".\"product\"\n"
+ "WHERE \"product_name\" NOT RLIKE '.+@.+\\\\..+'";
sql(query)
.withLibrary(SqlLibrary.SPARK).ok(expected)
.withLibrary(SqlLibrary.HIVE).ok(expectedHive)
.withLibrary(SqlLibrary.MYSQL).ok(expectedMysql);
}

@Test void testNotIlike() {
Expand Down
4 changes: 2 additions & 2 deletions site/_docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2834,8 +2834,8 @@ In the following:
| b m p s | REPEAT(string, integer) | Returns a string consisting of *string* repeated of *integer* times; returns an empty string if *integer* is less than 1
| b m | REVERSE(string) | Returns *string* with the order of the characters reversed
| b m p s | RIGHT(string, length) | Returns the rightmost *length* characters from the *string*
| h s | string1 RLIKE string2 | Whether *string1* matches regex pattern *string2* (similar to `LIKE`, but uses Java regex)
| h s | string1 NOT RLIKE string2 | Whether *string1* does not match regex pattern *string2* (similar to `NOT LIKE`, but uses Java regex)
| h m s | string1 RLIKE string2 | Whether *string1* matches regex pattern *string2* (similar to `LIKE`, but uses Java regex)
| h m s | string1 NOT RLIKE string2 | Whether *string1* does not match regex pattern *string2* (similar to `NOT LIKE`, but uses Java regex)
| b o s | RPAD(string, length[, pattern ]) | Returns a string or bytes value that consists of *string* appended to *length* with *pattern*
| b o s | RTRIM(string) | Returns *string* with all blanks removed from the end
| b | SAFE_ADD(numeric1, numeric2) | Returns *numeric1* + *numeric2*, or NULL on overflow. Arguments are implicitly cast to one of the types BIGINT, DOUBLE, or DECIMAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3790,9 +3790,10 @@ void checkIsNull(SqlOperatorFixture f, SqlOperator operator) {
checkRlikeFunc(f, SqlLibrary.HIVE, SqlLibraryOperators.RLIKE);
checkRlikeFunc(f, SqlLibrary.SPARK, SqlLibraryOperators.RLIKE);
checkRlikeFunc(f, SqlLibrary.SPARK, SqlLibraryOperators.REGEXP);
checkRlikeFunc(f, SqlLibrary.MYSQL, SqlLibraryOperators.RLIKE);
checkNotRlikeFunc(f.withLibrary(SqlLibrary.HIVE));
checkNotRlikeFunc(f.withLibrary(SqlLibrary.SPARK));
checkRlikeFails(f.withLibrary(SqlLibrary.MYSQL));
checkNotRlikeFunc(f.withLibrary(SqlLibrary.MYSQL));
checkRlikeFails(f.withLibrary(SqlLibrary.ORACLE));

f.setFor(SqlLibraryOperators.REGEXP_LIKE, VM_EXPAND);
Expand Down

0 comments on commit be9b860

Please sign in to comment.