Skip to content

Commit

Permalink
feat(isthmus): support for char_length (substrait-io#212)
Browse files Browse the repository at this point in the history
test: added tests for string functions
  • Loading branch information
YannisBres authored Dec 18, 2023
1 parent 9abf1a0 commit ba8ccfd
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class FunctionMappings {
s(SqlStdOperatorTable.LIKE),
s(SqlStdOperatorTable.SUBSTRING, "substring"),
s(SqlStdOperatorTable.CONCAT, "concat"),
s(SqlStdOperatorTable.CHAR_LENGTH, "char_length"),
s(SqlStdOperatorTable.LOWER, "lower"),
s(SqlStdOperatorTable.UPPER, "upper"),
s(SqlStdOperatorTable.BETWEEN),
Expand Down
66 changes: 66 additions & 0 deletions isthmus/src/test/java/io/substrait/isthmus/StringFunctionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.substrait.isthmus;

import java.util.List;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class StringFunctionTest extends PlanTestBase {

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

@ParameterizedTest
@ValueSource(strings = {"c16", "vc32"})
void charLength(String column) throws Exception {
String query = String.format("SELECT char_length(%s) FROM strings", column);
assertSqlSubstraitRelRoundTrip(query, CREATES);
}

@ParameterizedTest
@ValueSource(strings = {"vc32"})
void concat(String column) throws Exception {
String query = String.format("SELECT %s || %s FROM strings", column, column);
assertSqlSubstraitRelRoundTrip(query, CREATES);
}

@ParameterizedTest
@ValueSource(strings = {"c16", "vc32"})
void lower(String column) throws Exception {
String query = String.format("SELECT lower(%s) FROM strings", column);
assertSqlSubstraitRelRoundTrip(query, CREATES);
}

@ParameterizedTest
@ValueSource(strings = {"c16", "vc32"})
void upper(String column) throws Exception {
String query = String.format("SELECT upper(%s) FROM strings", column);
assertSqlSubstraitRelRoundTrip(query, CREATES);
}

@ParameterizedTest
@ValueSource(strings = {"c16", "vc32"})
void substringWith1Param(String column) throws Exception {
String query = String.format("SELECT substring(%s, 42) FROM strings", column);
assertSqlSubstraitRelRoundTrip(query, CREATES);
}

@ParameterizedTest
@ValueSource(strings = {"c16", "vc32"})
void substringWith2Params(String column) throws Exception {
String query = String.format("SELECT substring(%s, 42, 5) FROM strings", column);
assertSqlSubstraitRelRoundTrip(query, CREATES);
}

@ParameterizedTest
@ValueSource(strings = {"c16", "vc32"})
void substringFrom(String column) throws Exception {
String query = String.format("SELECT substring(%s FROM 42) FROM strings", column);
assertSqlSubstraitRelRoundTrip(query, CREATES);
}

@ParameterizedTest
@ValueSource(strings = {"c16", "vc32"})
void substringFromFor(String column) throws Exception {
String query = String.format("SELECT substring(%s FROM 42 FOR 5) FROM strings", column);
assertSqlSubstraitRelRoundTrip(query, CREATES);
}
}

0 comments on commit ba8ccfd

Please sign in to comment.