-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(isthmus): support converting Substrait Plan.Root to Calcite RelRoot
Signed-off-by: Niels Pardon <par@zurich.ibm.com>
- Loading branch information
1 parent
780a0bb
commit 4f305d2
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
isthmus/src/test/java/io/substrait/isthmus/SubstraitToCalciteTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.substrait.isthmus; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.substrait.plan.Plan; | ||
import io.substrait.plan.ProtoPlanConverter; | ||
import java.util.Map.Entry; | ||
import org.apache.calcite.adapter.tpcds.TpcdsSchema; | ||
import org.apache.calcite.rel.RelRoot; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class SubstraitToCalciteTest extends PlanTestBase { | ||
@Test | ||
void testConvertRoot() throws Exception { | ||
SqlToSubstrait s = new SqlToSubstrait(); | ||
TpcdsSchema schema = new TpcdsSchema(1.0); | ||
|
||
// single column | ||
String newColName = "store_name"; | ||
String sql = "select s_store_name as " + newColName + " from tpcds.store"; | ||
|
||
io.substrait.proto.Plan protoPlan = s.execute(sql, "tpcds", schema); | ||
|
||
ProtoPlanConverter protoPlanConverter = new ProtoPlanConverter(extensions); | ||
Plan plan = protoPlanConverter.from(protoPlan); | ||
Plan.Root root = plan.getRoots().get(0); | ||
|
||
assertEquals(1, root.getNames().size()); | ||
assertEquals(newColName.toUpperCase(), root.getNames().get(0)); | ||
|
||
SubstraitToCalcite converter = new SubstraitToCalcite(extensions, typeFactory); | ||
RelRoot relRoot = converter.convert(root); | ||
|
||
assertEquals(root.getNames().size(), relRoot.fields.size()); | ||
for (Entry<Integer, String> field : relRoot.fields) { | ||
assertEquals(root.getNames().get(field.getKey()), field.getValue()); | ||
} | ||
|
||
// multiple columns | ||
String storeIdColumnName = "s_store_id"; | ||
sql = "select " + storeIdColumnName + ", s_store_name as " + newColName + " from tpcds.store"; | ||
protoPlan = s.execute(sql, "tpcds", schema); | ||
|
||
protoPlanConverter = new ProtoPlanConverter(extensions); | ||
plan = protoPlanConverter.from(protoPlan); | ||
root = plan.getRoots().get(0); | ||
|
||
assertEquals(2, root.getNames().size()); | ||
assertEquals(storeIdColumnName.toUpperCase(), root.getNames().get(0)); | ||
assertEquals(newColName.toUpperCase(), root.getNames().get(1)); | ||
|
||
relRoot = converter.convert(root); | ||
|
||
assertEquals(root.getNames().size(), relRoot.fields.size()); | ||
for (Entry<Integer, String> field : relRoot.fields) { | ||
assertEquals(root.getNames().get(field.getKey()), field.getValue()); | ||
} | ||
} | ||
} |