-
Notifications
You must be signed in to change notification settings - Fork 94
test(isthmus): round-trip testing of TPC queries #396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
51 changes: 0 additions & 51 deletions
51
isthmus/src/test/java/io/substrait/isthmus/TpcdsQueryNoValidation.java
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
isthmus/src/test/java/io/substrait/isthmus/TpcdsQueryTest.java
This file contains hidden or 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,61 @@ | ||
| package io.substrait.isthmus; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import io.substrait.plan.Plan.Root; | ||
| import io.substrait.plan.ProtoPlanConverter; | ||
| import io.substrait.proto.Plan; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.IntStream; | ||
| import org.apache.calcite.adapter.tpcds.TpcdsSchema; | ||
| import org.apache.calcite.rel.RelNode; | ||
| import org.apache.calcite.rel.RelRoot; | ||
| import org.apache.calcite.sql.parser.SqlParseException; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| /** TPC-DS test to convert SQL to Substrait and then convert those plans back to SQL. */ | ||
| public class TpcdsQueryTest extends PlanTestBase { | ||
| private static final Set<Integer> toSubstraitExclusions = Set.of(9, 27, 36, 70, 86, 98); | ||
| private static final Set<Integer> fromSubstraitExclusions = Set.of(6, 8, 67); | ||
|
|
||
| private final TpcdsSchema schema = new TpcdsSchema(1.0); | ||
| private final ProtoPlanConverter planConverter = new ProtoPlanConverter(); | ||
|
|
||
| static IntStream testCases() { | ||
| return IntStream.rangeClosed(1, 99).filter(n -> !toSubstraitExclusions.contains(n)); | ||
| } | ||
|
|
||
| /** | ||
| * Note that this test does not currently validate the correctness of the Substrait plan; just | ||
| * that the SQL can be converted to Substrait and back to SQL without error. | ||
| */ | ||
| @ParameterizedTest | ||
| @MethodSource("testCases") | ||
| public void testQuery(int query) throws IOException { | ||
| String inputSql = asString(String.format("tpcds/queries/%02d.sql", query)); | ||
|
|
||
| Plan plan = assertDoesNotThrow(() -> toSubstraitPlan(inputSql), "SQL to Substrait"); | ||
|
|
||
| if (!fromSubstraitExclusions.contains(query)) { | ||
| assertDoesNotThrow(() -> toSql(plan), "Substrait to SQL"); | ||
| } | ||
| } | ||
|
|
||
| private Plan toSubstraitPlan(String sql) throws SqlParseException, IOException { | ||
| return new SqlToSubstrait().execute(sql, "tpcds", schema); | ||
| } | ||
|
|
||
| private String toSql(Plan plan) { | ||
| List<Root> roots = planConverter.from(plan).getRoots(); | ||
| assertEquals(1, roots.size(), "number of roots"); | ||
|
|
||
| Root root = roots.get(0); | ||
| RelRoot relRoot = new SubstraitToCalcite(extensions, typeFactory).convert(root); | ||
| RelNode project = relRoot.project(true); | ||
| return SubstraitToSql.toSql(project); | ||
| } | ||
| } |
24 changes: 0 additions & 24 deletions
24
isthmus/src/test/java/io/substrait/isthmus/TpchQueryNoValidation.java
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
isthmus/src/test/java/io/substrait/isthmus/TpchQueryTest.java
This file contains hidden or 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.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import io.substrait.plan.Plan.Root; | ||
| import io.substrait.plan.ProtoPlanConverter; | ||
| import io.substrait.proto.Plan; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.IntStream; | ||
| import org.apache.calcite.rel.RelNode; | ||
| import org.apache.calcite.rel.RelRoot; | ||
| import org.apache.calcite.sql.parser.SqlParseException; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| /** TPC-H test to convert SQL to Substrait and then convert those plans back to SQL. */ | ||
| public class TpchQueryTest extends PlanTestBase { | ||
| private static final Set<Integer> fromSubstraitExclusions = Set.of(17); | ||
|
|
||
| private final ProtoPlanConverter planConverter = new ProtoPlanConverter(); | ||
|
|
||
| static IntStream testCases() { | ||
| return IntStream.rangeClosed(1, 22); | ||
| } | ||
|
|
||
| /** | ||
| * Note that this test does not currently validate the correctness of the Substrait plan; just | ||
| * that the SQL can be converted to Substrait and back to SQL without error. | ||
| */ | ||
| @ParameterizedTest | ||
| @MethodSource("testCases") | ||
| public void testQuery(int query) throws IOException { | ||
| String inputSql = asString(String.format("tpch/queries/%02d.sql", query)); | ||
|
|
||
| Plan plan = assertDoesNotThrow(() -> toSubstraitPlan(inputSql), "SQL to Substrait"); | ||
|
|
||
| if (!fromSubstraitExclusions.contains(query)) { | ||
| assertDoesNotThrow(() -> toSql(plan), "Substrait to SQL"); | ||
| } | ||
| } | ||
|
|
||
| private Plan toSubstraitPlan(String sql) throws SqlParseException { | ||
| List<String> createStatements = tpchSchemaCreateStatements(); | ||
| return new SqlToSubstrait().execute(sql, createStatements); | ||
| } | ||
|
|
||
| private String toSql(Plan plan) { | ||
| List<Root> roots = planConverter.from(plan).getRoots(); | ||
| assertEquals(1, roots.size(), "number of roots"); | ||
|
|
||
| Root root = roots.get(0); | ||
| RelRoot relRoot = new SubstraitToCalcite(extensions, typeFactory).convert(root); | ||
| RelNode project = relRoot.project(true); | ||
| return SubstraitToSql.toSql(project); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea ✨