Partial implementation of SQL VALUES operator. Signed-off-by: Jacques Nadeau <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/253a8dfe Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/253a8dfe Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/253a8dfe Branch: refs/heads/execwork Commit: 253a8dfe065ea8e9ba5e12e8313fdcbca774e77a Parents: 82d10d0 Author: Julian Hyde <[email protected]> Authored: Fri Mar 29 14:51:16 2013 -0700 Committer: Jacques Nadeau <[email protected]> Committed: Thu Jun 6 11:06:42 2013 -0700 ---------------------------------------------------------------------- sandbox/prototype/sqlparser/pom.xml | 2 +- .../main/java/org/apache/drill/jdbc/Driver.java | 20 +++- .../java/org/apache/drill/optiq/DrillOptiq.java | 3 + .../org/apache/drill/optiq/DrillPrepareImpl.java | 47 +++++++++ .../org/apache/drill/optiq/DrillValuesRel.java | 73 +++++++++++++++ .../org/apache/drill/optiq/DrillValuesRule.java | 48 ++++++++++ .../java/org/apache/drill/jdbc/test/JdbcTest.java | 10 ++- 7 files changed, 195 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/253a8dfe/sandbox/prototype/sqlparser/pom.xml ---------------------------------------------------------------------- diff --git a/sandbox/prototype/sqlparser/pom.xml b/sandbox/prototype/sqlparser/pom.xml index 2e65585..564eea6 100644 --- a/sandbox/prototype/sqlparser/pom.xml +++ b/sandbox/prototype/sqlparser/pom.xml @@ -29,7 +29,7 @@ <dependency> <groupId>net.hydromatic</groupId> <artifactId>optiq</artifactId> - <version>0.2</version> + <version>0.3</version> </dependency> <dependency> <groupId>net.hydromatic</groupId> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/253a8dfe/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/jdbc/Driver.java ---------------------------------------------------------------------- diff --git a/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/jdbc/Driver.java b/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/jdbc/Driver.java index 1155f31..33a7294 100644 --- a/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/jdbc/Driver.java +++ b/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/jdbc/Driver.java @@ -20,12 +20,10 @@ package org.apache.drill.jdbc; import java.io.IOException; import java.sql.SQLException; -import net.hydromatic.optiq.jdbc.DriverVersion; -import net.hydromatic.optiq.jdbc.Handler; -import net.hydromatic.optiq.jdbc.HandlerImpl; -import net.hydromatic.optiq.jdbc.OptiqConnection; -import net.hydromatic.optiq.jdbc.UnregisteredDriver; +import net.hydromatic.linq4j.function.Function0; +import net.hydromatic.optiq.jdbc.*; import net.hydromatic.optiq.model.ModelHandler; +import org.apache.drill.optiq.DrillPrepareImpl; /** * JDBC driver for Apache Drill. @@ -46,6 +44,16 @@ public class Driver extends UnregisteredDriver { } @Override + protected Function0<OptiqPrepare> createPrepareFactory() { + return new Function0<OptiqPrepare>() { + @Override + public OptiqPrepare apply() { + return new DrillPrepareImpl(); + } + }; + } + + @Override protected Handler createHandler() { return new DrillHandler(); } @@ -75,7 +83,7 @@ public class Driver extends UnregisteredDriver { } } -/* + /* optiq work ========== http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/253a8dfe/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillOptiq.java ---------------------------------------------------------------------- diff --git a/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillOptiq.java b/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillOptiq.java index 388a259..0a12fc3 100644 --- a/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillOptiq.java +++ b/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillOptiq.java @@ -36,6 +36,9 @@ public class DrillOptiq { planner.addRule(DrillFilterRule.INSTANCE); planner.addRule(DrillProjectRule.INSTANCE); + + // Enable when https://issues.apache.org/jira/browse/DRILL-57 fixed + if (false) planner.addRule(DrillValuesRule.INSTANCE); // planner.addRule(DrillSortRule.INSTANCE); // planner.addRule(DrillJoinRule.INSTANCE); // planner.addRule(DrillUnionRule.INSTANCE); http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/253a8dfe/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java ---------------------------------------------------------------------- diff --git a/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java b/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java new file mode 100644 index 0000000..2a39de5 --- /dev/null +++ b/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package org.apache.drill.optiq; + +import net.hydromatic.optiq.prepare.OptiqPrepareImpl; +import net.hydromatic.optiq.rules.java.JavaRules; +import org.eigenbase.relopt.volcano.VolcanoPlanner; + +/** + * Implementation of {@link net.hydromatic.optiq.jdbc.OptiqPrepare} for Drill. + */ +public class DrillPrepareImpl extends OptiqPrepareImpl { + public DrillPrepareImpl() { + super(); + } + + @Override + protected VolcanoPlanner createPlanner() { + final VolcanoPlanner planner = super.createPlanner(); + planner.addRule(EnumerableDrillRule.ARRAY_INSTANCE); + planner.addRule(EnumerableDrillRule.CUSTOM_INSTANCE); + + // Enable when https://issues.apache.org/jira/browse/DRILL-57 fixed + if (false) { + planner.addRule(DrillValuesRule.INSTANCE); + planner.removeRule(JavaRules.ENUMERABLE_VALUES_RULE); + } + return planner; + } +} + +// End DrillPrepareImpl.java http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/253a8dfe/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRel.java ---------------------------------------------------------------------- diff --git a/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRel.java b/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRel.java new file mode 100644 index 0000000..cc24afc --- /dev/null +++ b/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRel.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package org.apache.drill.optiq; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.eigenbase.rel.ValuesRelBase; +import org.eigenbase.rel.RelCollation; +import org.eigenbase.rel.RelNode; +import org.eigenbase.relopt.*; +import org.eigenbase.reltype.RelDataType; +import org.eigenbase.reltype.RelDataTypeField; +import org.eigenbase.rex.RexLiteral; +import org.eigenbase.rex.RexNode; +import org.eigenbase.sql.type.SqlTypeName; +import org.eigenbase.util.Pair; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * Values implemented in Drill. + */ +public class DrillValuesRel extends ValuesRelBase implements DrillRel { + protected DrillValuesRel(RelOptCluster cluster, + RelDataType rowType, + List<List<RexLiteral>> tuples, + RelTraitSet traits) { + super(cluster, rowType, tuples, traits); + assert getConvention() == CONVENTION; + } + + @Override + public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) { + assert inputs.isEmpty(); + return new DrillValuesRel(getCluster(), rowType, tuples, traitSet); + } + + @Override + public String getHolder() { + return "xxx"; + } + + @Override + public RelOptCost computeSelfCost(RelOptPlanner planner) { + return super.computeSelfCost(planner).multiplyBy(0.1); + } + + @Override + public void implement(DrillImplementor implementor) { + // Update when https://issues.apache.org/jira/browse/DRILL-57 fixed + throw new UnsupportedOperationException(); + } +} + +// End DrillValuesRel.java http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/253a8dfe/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRule.java ---------------------------------------------------------------------- diff --git a/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRule.java b/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRule.java new file mode 100644 index 0000000..faa93ee --- /dev/null +++ b/sandbox/prototype/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRule.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package org.apache.drill.optiq; + +import org.eigenbase.rel.ValuesRel; +import org.eigenbase.relopt.*; + +/** + * Rule that converts a {@link ValuesRel} to a Drill + * "values" operation. + */ +public class DrillValuesRule extends RelOptRule { + public static final RelOptRule INSTANCE = new DrillValuesRule(); + + private DrillValuesRule() { + super( + new RelOptRuleOperand( + ValuesRel.class, + Convention.NONE), + "DrillValuesRule"); + } + + @Override + public void onMatch(RelOptRuleCall call) { + final ValuesRel values = (ValuesRel) call.getRels()[0]; + final RelTraitSet traits = values.getTraitSet().plus(DrillRel.CONVENTION); + call.transformTo( + new DrillValuesRel(values.getCluster(), values.getRowType(), + values.getTuples(), traits)); + } +} + +// End DrillValuesRule.java http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/253a8dfe/sandbox/prototype/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java ---------------------------------------------------------------------- diff --git a/sandbox/prototype/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java b/sandbox/prototype/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java index eb60844..1fb9da2 100644 --- a/sandbox/prototype/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java +++ b/sandbox/prototype/sqlparser/src/test/java/org/apache/drill/jdbc/test/JdbcTest.java @@ -21,7 +21,6 @@ import com.google.common.base.Function; import junit.framework.TestCase; -import org.apache.drill.exec.ref.ReferenceInterpreter; import org.apache.drill.jdbc.DrillTable; import java.sql.*; @@ -189,6 +188,15 @@ public class JdbcTest extends TestCase { .sql("select * from donuts where 3 < 4") .returns(EXPECTED); } + + public void testValues() throws Exception { + JdbcAssert.withModel(MODEL, "DONUTS") + .sql("values (1)") + .returns("EXPR$0=1\n"); + + // Enable when https://issues.apache.org/jira/browse/DRILL-57 fixed + // .planContains("store"); + } } // End JdbcTest.java
