diff options
author | chunhui-shi <cshi@maprtech.com> | 2018-03-26 12:15:09 -0700 |
---|---|---|
committer | Parth Chandra <parthc@apache.org> | 2018-05-15 11:14:52 -0700 |
commit | 0a4a37e11f2f2ad66de80918a4b34665e42803fc (patch) | |
tree | c1e75bc6b45266f79eeef9e2f1f2273b529fe45f /exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical | |
parent | ca90229b6deea40282927f8ab5c07715a4e18620 (diff) |
DRILL-6321: Lateral Join and Unnest - initial implementation for parser and planning
Diffstat (limited to 'exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical')
4 files changed, 196 insertions, 0 deletions
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillCorrelateRel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillCorrelateRel.java new file mode 100644 index 000000000..e5eee4eef --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillCorrelateRel.java @@ -0,0 +1,51 @@ +/* + * 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.exec.planner.logical; + +import org.apache.calcite.plan.RelOptCluster; +import org.apache.calcite.plan.RelTraitSet; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.core.Correlate; +import org.apache.calcite.rel.core.CorrelationId; +import org.apache.calcite.sql.SemiJoinType; +import org.apache.calcite.util.ImmutableBitSet; +import org.apache.drill.common.logical.data.LogicalOperator; +import org.apache.drill.exec.planner.common.DrillCorrelateRelBase; + + +public class DrillCorrelateRel extends DrillCorrelateRelBase implements DrillRel { + + protected DrillCorrelateRel(RelOptCluster cluster, RelTraitSet traits, RelNode left, RelNode right, + CorrelationId correlationId, ImmutableBitSet requiredColumns, SemiJoinType semiJoinType) { + super(cluster, traits, left, right, correlationId, requiredColumns, semiJoinType); + } + + @Override + public Correlate copy(RelTraitSet traitSet, + RelNode left, RelNode right, CorrelationId correlationId, + ImmutableBitSet requiredColumns, SemiJoinType joinType) { + return new DrillCorrelateRel(this.getCluster(), this.getTraitSet(), left, right, correlationId, requiredColumns, + this.getJoinType()); + } + + @Override + public LogicalOperator implement(DrillImplementor implementor) { + //TODO: implementation for direct convert from RelNode to logical operator for explainPlan + return null; + } +} diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillCorrelateRule.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillCorrelateRule.java new file mode 100644 index 000000000..8ac4fb1a6 --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillCorrelateRule.java @@ -0,0 +1,53 @@ +/* + * 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.exec.planner.logical; + +import org.apache.calcite.plan.Convention; +import org.apache.calcite.plan.RelOptRule; +import org.apache.calcite.plan.RelOptRuleCall; +import org.apache.calcite.plan.RelTraitSet; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.logical.LogicalCorrelate; +import org.apache.calcite.util.trace.CalciteTrace; +import org.slf4j.Logger; + +public class DrillCorrelateRule extends RelOptRule { + public static final RelOptRule INSTANCE = new DrillCorrelateRule(); + protected static final Logger tracer = CalciteTrace.getPlannerTracer(); + + private DrillCorrelateRule() { + super(RelOptHelper.any(LogicalCorrelate.class, Convention.NONE), + DrillRelFactories.LOGICAL_BUILDER, + "DrillCorrelateRule"); + } + + @Override + public void onMatch(RelOptRuleCall call) { + final LogicalCorrelate correlate = call.rel(0); + final RelNode left = correlate.getLeft(); + final RelNode right = correlate.getRight(); + final RelNode convertedLeft = convert(left, left.getTraitSet().plus(DrillRel.DRILL_LOGICAL).simplify()); + final RelNode convertedRight = convert(right, right.getTraitSet().plus(DrillRel.DRILL_LOGICAL).simplify()); + + final RelTraitSet traits = correlate.getTraitSet().plus(DrillRel.DRILL_LOGICAL); + DrillCorrelateRel correlateRel = new DrillCorrelateRel(correlate.getCluster(), + traits, convertedLeft, convertedRight, correlate.getCorrelationId(), + correlate.getRequiredColumns(), correlate.getJoinType()); + call.transformTo(correlateRel); + } +} diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillUnnestRel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillUnnestRel.java new file mode 100644 index 000000000..ab827e577 --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillUnnestRel.java @@ -0,0 +1,44 @@ +/* + * 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.exec.planner.logical; + +import org.apache.calcite.plan.RelOptCluster; +import org.apache.calcite.plan.RelTraitSet; + +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rex.RexNode; +import org.apache.drill.common.logical.data.LogicalOperator; +import org.apache.drill.exec.planner.common.DrillUnnestRelBase; + + +public class DrillUnnestRel extends DrillUnnestRelBase implements DrillRel { + + + public DrillUnnestRel(RelOptCluster cluster, RelTraitSet traits, + RelDataType rowType, RexNode ref) { + super(cluster, traits, ref); + this.rowType = rowType; + } + + @Override + public LogicalOperator implement(DrillImplementor implementor) { + //TODO: implementation for direct convert from RelNode to logical operator for explainPlan + return null; + } + +} diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillUnnestRule.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillUnnestRule.java new file mode 100644 index 000000000..762eb46f3 --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillUnnestRule.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.exec.planner.logical; + +import org.apache.calcite.plan.Convention; +import org.apache.calcite.plan.RelOptRule; +import org.apache.calcite.plan.RelOptRuleCall; +import org.apache.calcite.plan.RelTraitSet; +import org.apache.calcite.rel.core.Uncollect; +import org.apache.calcite.rel.logical.LogicalProject; +import org.apache.calcite.rel.logical.LogicalValues; + +public class DrillUnnestRule extends RelOptRule { + public static final RelOptRule INSTANCE = new DrillUnnestRule(); + + private DrillUnnestRule() { + super(RelOptHelper.some(Uncollect.class, + RelOptHelper.some(LogicalProject.class, RelOptHelper.any(LogicalValues.class, Convention.NONE))), + DrillRelFactories.LOGICAL_BUILDER, "DrillUnnestRule"); + } + + @Override + public void onMatch(RelOptRuleCall call) { + final Uncollect uncollect = call.rel(0); + final LogicalProject project = call.rel(1); + final LogicalValues values = call.rel(2); + + final RelTraitSet traits = uncollect.getTraitSet().plus(DrillRel.DRILL_LOGICAL); + DrillUnnestRel unnest = new DrillUnnestRel(uncollect.getCluster(), traits, uncollect.getRowType(), + project.getProjects().iterator().next()); + call.transformTo(unnest); + } +} |