22
33import static org .junit .jupiter .api .Assertions .assertEquals ;
44
5- import io .substrait .isthmus .operation .CalciteOperation ;
65import io .substrait .isthmus .sql .SubstraitCreateStatementParser ;
76import io .substrait .plan .Plan ;
87import io .substrait .plan .PlanProtoConverter ;
98import io .substrait .plan .ProtoPlanConverter ;
10- import io .substrait .relation .Rel ;
119import org .apache .calcite .prepare .Prepare ;
1210import org .apache .calcite .sql .parser .SqlParseException ;
1311import org .junit .jupiter .api .Test ;
@@ -30,55 +28,23 @@ void testSqlToSubstrait(String sqlStatement) throws SqlParseException {
3028 assertEquals (protoPlan , protoPlan1 );
3129 }
3230
33- protected void assertCalciteOperationSubstraitRelRoundTrip (
34- String query , Prepare .CatalogReader catalogReader ) throws Exception {
35- // sql <--> substrait round trip test.
36- // Assert (sql -> calcite -> substrait) and (sql -> substrait -> calcite -> substrait) are same.
37- // Return list of sql -> Substrait rel -> Calcite rel.
38- SqlToSubstrait s = new SqlToSubstrait ();
39-
40- // 1. SQL -> Substrait Plan
41- Plan plan1 = s .convert (query , catalogReader );
42-
43- // 2. Substrait Plan -> Substrait Rel
44- Plan .Root pojo1 = plan1 .getRoots ().get (0 );
45-
46- // 3. Substrait Rel -> CalciteOperation
47-
48- SubstraitToCalciteOperation substraitToCalciteOperation =
49- new SubstraitToCalciteOperation (extensions , typeFactory , catalogReader , s .parserConfig );
50- Rel rel = plan1 .getRoots ().get (0 ).getInput ();
51- CalciteOperation calciteOperation =
52- rel .accept (substraitToCalciteOperation , SubstraitRelNodeConverter .Context .newContext ());
53-
54- // 4. CalciteOperation -> Substrait Rel
55- CalciteOperationToSubstrait calciteOperationToSubstrait =
56- new CalciteOperationToSubstrait (extensions , s .featureBoard );
57- Plan .Root pojo2 = calciteOperation .accept (calciteOperationToSubstrait );
58-
59- assertEquals (pojo1 , pojo2 );
60- }
61-
62- void testPlanRoundTrip (String sqlStatement ) throws Exception {
31+ void testPlanRoundTrip (String sqlStatement ) throws SqlParseException {
6332 SqlToSubstrait sql2subst = new SqlToSubstrait ();
6433 final Plan plan = sql2subst .convert (sqlStatement , catalogReader );
6534
6635 assertPlanRoundtrip (plan );
67- assertCalciteOperationSubstraitRelRoundTrip (sqlStatement , catalogReader );
68-
69- // assertFullRoundTrip(sqlStatement, catalogReader);
7036 }
7137
7238 @ Test
73- void testCreateTable () throws Exception {
39+ void testCreateTable () throws SqlParseException {
7440 String sql = "create table dst1 as select * from src1" ;
7541 testSqlToSubstrait (sql );
7642 // TBD: full roundtrip is not possible because there is no relational algebra for DDL
7743 testPlanRoundTrip (sql );
7844 }
7945
8046 @ Test
81- void testCreateView () throws Exception {
47+ void testCreateView () throws SqlParseException {
8248 String sql = "create view dst1 as select * from src1" ;
8349 testSqlToSubstrait (sql );
8450 testPlanRoundTrip (sql );
0 commit comments