Updated Branches: refs/heads/master 251022f84 -> 70cd6af56
Update prepare to exclude Optiq's ENUMERABLE_* rules. Update Limit and Sort rules to convert as required. Add test for limit + order by. Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/2b7fd5af Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/2b7fd5af Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/2b7fd5af Branch: refs/heads/master Commit: 2b7fd5af8b9a4738fed3f879ed5edca718580cd7 Parents: e11c2e5 Author: Jacques Nadeau <[email protected]> Authored: Wed Oct 9 10:58:50 2013 -0700 Committer: Timothy Chen <[email protected]> Committed: Mon Oct 14 12:06:18 2013 -0700 ---------------------------------------------------------------------- .../org/apache/drill/optiq/DrillLimitRule.java | 36 ++++++++++---------- .../apache/drill/optiq/DrillPrepareImpl.java | 19 +++++++---- .../org/apache/drill/optiq/DrillSortRule.java | 15 ++++---- .../org/apache/drill/jdbc/test/JdbcTest.java | 19 ++++++++++- 4 files changed, 58 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2b7fd5af/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRule.java ---------------------------------------------------------------------- diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRule.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRule.java index 2662156..0b835c9 100644 --- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRule.java +++ b/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRule.java @@ -17,7 +17,6 @@ */ package org.apache.drill.optiq; -import org.eigenbase.rel.RelCollationImpl; import org.eigenbase.rel.RelNode; import org.eigenbase.rel.SortRel; import org.eigenbase.relopt.Convention; @@ -36,24 +35,25 @@ public class DrillLimitRule extends RelOptRule { } @Override - public void onMatch(RelOptRuleCall call) { + public boolean matches(RelOptRuleCall call) { final SortRel sort = call.rel(0); - if (sort.offset == null && sort.fetch == null) { - return; - } - final RelTraitSet traits = sort.getTraitSet(); - RelNode input = sort.getChild(); - if (!sort.getCollation().getFieldCollations().isEmpty()) { - input = sort.copy( - sort.getTraitSet(), - sort, - sort.getCollation(), - null, - null); + return sort.offset != null || sort.fetch != null; + } + + @Override + public void onMatch(RelOptRuleCall call) { + final SortRel incomingSort = call.rel(0); + final RelTraitSet incomingTraits = incomingSort.getTraitSet(); + RelNode input = incomingSort.getChild(); + + // if the Optiq sort rel includes a collation and a limit, we need to create a copy the sort rel that excludes the + // limit information. + if (!incomingSort.getCollation().getFieldCollations().isEmpty()) { + input = incomingSort.copy(incomingTraits, input, incomingSort.getCollation(), null, null); } - //RelNode x = convert( - // input, - // input.getTraitSet()); - call.transformTo(new DrillLimitRel(sort.getCluster(), traits, input, sort.offset, sort.fetch)); + + RelNode convertedInput = convert(input, input.getTraitSet().plus(DrillRel.CONVENTION)); + call.transformTo(new DrillLimitRel(incomingSort.getCluster(), incomingTraits.plus(DrillRel.CONVENTION), convertedInput, incomingSort.offset, incomingSort.fetch)); } + } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2b7fd5af/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java ---------------------------------------------------------------------- diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java index 363c064..af7bbc7 100644 --- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java +++ b/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java @@ -20,7 +20,6 @@ package org.apache.drill.optiq; import net.hydromatic.optiq.prepare.OptiqPrepareImpl; import net.hydromatic.optiq.rules.java.JavaRules; -import org.apache.drill.jdbc.DrillHandler; import org.apache.drill.jdbc.Driver; import org.eigenbase.relopt.RelOptPlanner; @@ -38,12 +37,20 @@ public class DrillPrepareImpl extends OptiqPrepareImpl { protected RelOptPlanner createPlanner() { final RelOptPlanner planner = super.createPlanner(); planner.addRule(EnumerableDrillRule.getInstance(driver == null ? null : driver.getClient())); + planner.addRule(DrillValuesRule.INSTANCE); - // Enable when https://issues.apache.org/jira/browse/DRILL-57 fixed - if (false) { - planner.addRule(DrillValuesRule.INSTANCE); - planner.removeRule(JavaRules.ENUMERABLE_VALUES_RULE); - } + planner.removeRule(JavaRules.ENUMERABLE_JOIN_RULE); + planner.removeRule(JavaRules.ENUMERABLE_CALC_RULE); + planner.removeRule(JavaRules.ENUMERABLE_AGGREGATE_RULE); + planner.removeRule(JavaRules.ENUMERABLE_SORT_RULE); + planner.removeRule(JavaRules.ENUMERABLE_LIMIT_RULE); + planner.removeRule(JavaRules.ENUMERABLE_UNION_RULE); + planner.removeRule(JavaRules.ENUMERABLE_INTERSECT_RULE); + planner.removeRule(JavaRules.ENUMERABLE_MINUS_RULE); + planner.removeRule(JavaRules.ENUMERABLE_TABLE_MODIFICATION_RULE); + planner.removeRule(JavaRules.ENUMERABLE_VALUES_RULE); + planner.removeRule(JavaRules.ENUMERABLE_WINDOW_RULE); + planner.removeRule(JavaRules.ENUMERABLE_ONE_ROW_RULE); return planner; } } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2b7fd5af/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRule.java ---------------------------------------------------------------------- diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRule.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRule.java index 871715a..93ffb62 100644 --- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRule.java +++ b/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRule.java @@ -32,17 +32,20 @@ public class DrillSortRule extends RelOptRule { } @Override - public void onMatch(RelOptRuleCall call) { + public boolean matches(RelOptRuleCall call) { final SortRel sort = call.rel(0); + return sort.offset == null && sort.fetch == null; + } - if(sort.offset != null || sort.fetch != null) { - return; - } + @Override + public void onMatch(RelOptRuleCall call) { + + final SortRel sort = call.rel(0); final RelNode input = call.rel(1); final RelTraitSet traits = sort.getTraitSet().plus(DrillRel.CONVENTION); - final RelTraitSet inputTraits = input.getTraitSet().plus(DrillRel.CONVENTION); - final RelNode convertedInput = convert(input, inputTraits); + + final RelNode convertedInput = convert(input, input.getTraitSet().plus(DrillRel.CONVENTION)); call.transformTo(new DrillSortRel(sort.getCluster(), traits, convertedInput, sort.getCollation())); } } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2b7fd5af/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java ---------------------------------------------------------------------- diff --git a/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java b/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java index 4a65748..7574c2c 100644 --- a/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java +++ b/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java @@ -29,6 +29,7 @@ import com.beust.jcommander.internal.Lists; import com.beust.jcommander.internal.Maps; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; + import org.apache.drill.common.JSONOptions; import org.apache.drill.common.PlanProperties; import org.apache.drill.common.logical.LogicalPlan; @@ -37,6 +38,7 @@ import org.apache.drill.common.logical.data.*; import org.apache.drill.exec.ref.ReferenceInterpreter; import org.apache.drill.exec.ref.rse.ClasspathRSE; import org.apache.drill.exec.ref.rse.QueueRSE; +import org.apache.drill.jdbc.test.JdbcAssert.TestDataConnection; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Ignore; @@ -270,6 +272,8 @@ public class JdbcTest { JdbcAssert.withModel(MODEL, "DONUTS").sql("select * from donuts where 3 < 4").returns(EXPECTED); } + + @Ignore @Test public void testValues() throws Exception { JdbcAssert.withModel(MODEL, "DONUTS").sql("values (1)").returns("EXPR$0=1\n"); @@ -478,6 +482,19 @@ public class JdbcTest { .planContains(Limit.class); } + + @Test + public void testLimitOrderBy() throws Exception { + TestDataConnection tdc = JdbcAssert + .withModel(MODEL, "HR") + .sql("select LASTNAME from emp order by LASTNAME limit 2") + .returns("LASTNAME=John\n" + + "LASTNAME=Jones"); + tdc.planContains(Limit.class); + tdc.planContains(Order.class); + + } + @Test public void testOrderByWithOffset() throws Exception { JdbcAssert @@ -485,7 +502,7 @@ public class JdbcTest { .sql("select LASTNAME from emp order by LASTNAME asc offset 3") .returns("LASTNAME=Robinson\n" + "LASTNAME=Smith\n" + - "LASTNAME=John") + "LASTNAME=Steinberg") .planContains(Limit.class); }
