Skip to content

Commit

Permalink
feat(isthmus): support for replace (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvolpato authored Feb 6, 2024
1 parent e63388d commit e96f4ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class FunctionMappings {
s(SqlStdOperatorTable.FLOOR, "floor"),
s(SqlStdOperatorTable.ROUND, "round"),
s(SqlStdOperatorTable.LIKE),
s(SqlStdOperatorTable.REPLACE, "replace"),
s(SqlStdOperatorTable.SUBSTRING, "substring"),
s(SqlStdOperatorTable.CONCAT, "concat"),
s(SqlStdOperatorTable.CHAR_LENGTH, "char_length"),
Expand Down
11 changes: 11 additions & 0 deletions isthmus/src/test/java/io/substrait/isthmus/StringFunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
public class StringFunctionTest extends PlanTestBase {

static List<String> CREATES = List.of("CREATE TABLE strings (c16 CHAR(16), vc32 VARCHAR(32))");
static List<String> REPLACE_CREATES =
List.of(
"CREATE TABLE replace_strings (c16 CHAR(16), vc32 VARCHAR(32), replace_from VARCHAR(16), replace_to VARCHAR(16))");

@ParameterizedTest
@ValueSource(strings = {"c16", "vc32"})
Expand Down Expand Up @@ -36,6 +39,14 @@ void upper(String column) throws Exception {
assertSqlSubstraitRelRoundTrip(query, CREATES);
}

@ParameterizedTest
@ValueSource(strings = {"c16", "vc32"})
void replace(String column) throws Exception {
String query =
String.format("SELECT replace(%s, replace_from, replace_to) FROM replace_strings", column);
assertSqlSubstraitRelRoundTrip(query, REPLACE_CREATES);
}

@ParameterizedTest
@ValueSource(strings = {"c16", "vc32"})
void substringWith1Param(String column) throws Exception {
Expand Down

0 comments on commit e96f4ba

Please sign in to comment.