Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRILL-6798: Planner changes to support semi-join.
- Loading branch information
1 parent
5fff1d8
commit 71809ca
Showing
20 changed files
with
553 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
48 changes: 48 additions & 0 deletions
48
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillJoin.java
This file contains 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,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.rel.RelNode; | ||
import org.apache.calcite.rel.core.JoinRelType; | ||
import org.apache.calcite.rex.RexNode; | ||
import org.apache.drill.exec.planner.common.DrillRelNode; | ||
import java.util.List; | ||
|
||
/** | ||
* Interface which needs to be implemented by all the join relation expressions. | ||
*/ | ||
public interface DrillJoin extends DrillRelNode { | ||
|
||
/* Columns of left table that are part of join condition */ | ||
List<Integer> getLeftKeys(); | ||
|
||
/* Columns of right table that are part of join condition */ | ||
List<Integer> getRightKeys(); | ||
|
||
/* JoinType of the join operation*/ | ||
JoinRelType getJoinType(); | ||
|
||
/* Join condition of the join relation */ | ||
RexNode getCondition(); | ||
|
||
/* Left RelNode of the Join Relation */ | ||
RelNode getLeft(); | ||
|
||
/* Right RelNode of the Join Relation */ | ||
RelNode getRight(); | ||
} |
This file contains 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
This file contains 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
This file contains 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
101 changes: 101 additions & 0 deletions
101
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillSemiJoinRel.java
This file contains 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,101 @@ | ||
/* | ||
* 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.JoinInfo; | ||
import org.apache.calcite.rel.core.JoinRelType; | ||
import org.apache.calcite.rel.core.SemiJoin; | ||
import org.apache.calcite.rex.RexNode; | ||
import org.apache.calcite.util.ImmutableIntList; | ||
import org.apache.calcite.util.Pair; | ||
import org.apache.drill.common.expression.FieldReference; | ||
import org.apache.drill.common.logical.data.Join; | ||
import org.apache.drill.common.logical.data.JoinCondition; | ||
import org.apache.drill.common.logical.data.LogicalOperator; | ||
import org.apache.drill.common.logical.data.LogicalSemiJoin; | ||
import org.apache.drill.shaded.guava.com.google.common.collect.Lists; | ||
import org.apache.drill.shaded.guava.com.google.common.base.Preconditions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DrillSemiJoinRel extends SemiJoin implements DrillJoin, DrillRel { | ||
|
||
public DrillSemiJoinRel( | ||
RelOptCluster cluster, | ||
RelTraitSet traitSet, | ||
RelNode left, | ||
RelNode right, | ||
RexNode condition, | ||
ImmutableIntList leftKeys, | ||
ImmutableIntList rightKeys) { | ||
super(cluster, | ||
traitSet, | ||
left, | ||
right, | ||
condition, | ||
leftKeys, | ||
rightKeys); | ||
} | ||
|
||
public static SemiJoin create(RelNode left, RelNode right, RexNode condition, | ||
ImmutableIntList leftKeys, ImmutableIntList rightKeys) { | ||
final RelOptCluster cluster = left.getCluster(); | ||
return new DrillSemiJoinRel(cluster, cluster.traitSetOf(DrillRel.DRILL_LOGICAL), left, | ||
right, condition, leftKeys, rightKeys); | ||
} | ||
|
||
@Override | ||
public SemiJoin copy(RelTraitSet traitSet, RexNode condition, | ||
RelNode left, RelNode right, JoinRelType joinType, boolean semiJoinDone) { | ||
Preconditions.checkArgument(joinType == JoinRelType.INNER); | ||
final JoinInfo joinInfo = JoinInfo.of(left, right, condition); | ||
Preconditions.checkArgument(joinInfo.isEqui()); | ||
return new DrillSemiJoinRel(getCluster(), traitSet, left, right, condition, | ||
joinInfo.leftKeys, joinInfo.rightKeys); | ||
} | ||
|
||
@Override | ||
public LogicalOperator implement(DrillImplementor implementor) { | ||
List<String> fields = new ArrayList<>(); | ||
fields.addAll(getInput(0).getRowType().getFieldNames()); | ||
fields.addAll(getInput(1).getRowType().getFieldNames()); | ||
Preconditions.checkArgument(DrillJoinRel.isUnique(fields)); | ||
final int leftCount = left.getRowType().getFieldCount(); | ||
final List<String> leftFields = fields.subList(0, leftCount); | ||
final List<String> rightFields = fields.subList(leftCount, leftCount + right.getRowType().getFieldCount()); | ||
|
||
final LogicalOperator leftOp = DrillJoinRel.implementInput(implementor, 0, 0, left, this, fields); | ||
final LogicalOperator rightOp = DrillJoinRel.implementInput(implementor, 1, leftCount, right, this, fields); | ||
|
||
Join.Builder builder = Join.builder(); | ||
builder.type(joinType); | ||
builder.left(leftOp); | ||
builder.right(rightOp); | ||
List<JoinCondition> conditions = Lists.newArrayList(); | ||
for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) { | ||
conditions.add(new JoinCondition(DrillJoinRel.EQUALITY_CONDITION, | ||
new FieldReference(leftFields.get(pair.left)), new FieldReference(rightFields.get(pair.right)))); | ||
} | ||
|
||
return new LogicalSemiJoin(leftOp, rightOp, conditions, joinType); | ||
} | ||
} |
Oops, something went wrong.