Skip to content

Commit ea89aec

Browse files
committed
feat: introduce SubstraitSchema
1 parent edb610e commit ea89aec

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.substrait.isthmus.calcite;
2+
3+
import java.util.Map;
4+
import org.apache.calcite.schema.Table;
5+
import org.apache.calcite.schema.impl.AbstractSchema;
6+
7+
/**
8+
* Basic {@link AbstractSchema} implementation for associating table names to {@link Table} objects
9+
*/
10+
public class SubstraitSchema extends AbstractSchema {
11+
12+
/** Maps of table names to their associated tables */
13+
protected final Map<String, Table> tableMap;
14+
15+
public SubstraitSchema(Map<String, Table> tableMap) {
16+
this.tableMap = tableMap;
17+
}
18+
19+
@Override
20+
public Map<String, Table> getTableMap() {
21+
return tableMap;
22+
}
23+
}

isthmus/src/test/java/io/substrait/isthmus/NestedStructQueryTest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

55
import com.google.protobuf.TextFormat;
6+
import io.substrait.isthmus.calcite.SubstraitSchema;
67
import io.substrait.plan.ProtoPlanConverter;
78
import io.substrait.proto.Expression;
89
import io.substrait.proto.Plan;
@@ -13,7 +14,6 @@
1314
import org.apache.calcite.rel.type.RelDataTypeFactory;
1415
import org.apache.calcite.schema.Schema;
1516
import org.apache.calcite.schema.Table;
16-
import org.apache.calcite.schema.impl.AbstractSchema;
1717
import org.apache.calcite.schema.impl.AbstractTable;
1818
import org.apache.calcite.sql.parser.SqlParseException;
1919
import org.apache.calcite.sql.type.SqlTypeName;
@@ -56,14 +56,7 @@ RelDataType map(RelDataType key, RelDataType value) {
5656

5757
private void test(Table table, String query, String expectedExpressionText)
5858
throws SqlParseException, IOException {
59-
final Schema schema =
60-
new AbstractSchema() {
61-
@Override
62-
protected Map<String, Table> getTableMap() {
63-
return Map.of("my_table", table);
64-
}
65-
};
66-
59+
final Schema schema = new SubstraitSchema(Map.of("my_table", table));
6760
final SqlToSubstrait sqlToSubstrait = new SqlToSubstrait();
6861
Plan plan = sqlToSubstrait.execute(query, "nested", schema);
6962
Expression obtainedExpression =

0 commit comments

Comments
 (0)