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
DRILL-6545: Projection Push down into Lateral Join operator. #1347
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,12 @@ | |
package org.apache.drill.exec.planner.common; | ||
|
||
import java.util.AbstractList; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.Lists; | ||
import org.apache.calcite.plan.RelOptUtil; | ||
import org.apache.calcite.rel.RelNode; | ||
|
@@ -29,6 +32,7 @@ | |
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.rel.type.RelDataTypeFactory; | ||
import org.apache.calcite.rel.type.RelDataTypeField; | ||
import org.apache.calcite.rex.RexBuilder; | ||
import org.apache.calcite.rex.RexCall; | ||
import org.apache.calcite.rex.RexInputRef; | ||
import org.apache.calcite.rex.RexLiteral; | ||
|
@@ -282,4 +286,58 @@ public Void visitCall(RexCall call) { | |
} | ||
return false; | ||
} | ||
|
||
public static class InputRefVisitor extends RexVisitorImpl<Void> { | ||
private final List<RexInputRef> inputRefList; | ||
|
||
public InputRefVisitor() { | ||
super(true); | ||
inputRefList = new ArrayList<>(); | ||
} | ||
|
||
public Void visitInputRef(RexInputRef ref) { | ||
inputRefList.add(ref); | ||
return null; | ||
} | ||
|
||
public Void visitCall(RexCall call) { | ||
for (RexNode operand : call.operands) { | ||
operand.accept(this); | ||
} | ||
return null; | ||
} | ||
|
||
public List<RexInputRef> getInputRefs() { | ||
return inputRefList; | ||
} | ||
} | ||
|
||
public static class RexFieldsTransformer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a generic transformer for Rex exprs ? If so, pls add a java doc for future use of this class. |
||
private final RexBuilder rexBuilder; | ||
private final Map<Integer, Integer> inputRefMap; | ||
|
||
public RexFieldsTransformer( | ||
RexBuilder rexBuilder, | ||
Map<Integer, Integer> inputRefMap) { | ||
this.rexBuilder = rexBuilder; | ||
this.inputRefMap = inputRefMap; | ||
} | ||
|
||
public RexNode go(RexNode rex) { | ||
if (rex instanceof RexCall) { | ||
ImmutableList.Builder<RexNode> builder = ImmutableList.builder(); | ||
final RexCall call = (RexCall) rex; | ||
for (RexNode operand : call.operands) { | ||
builder.add(go(operand)); | ||
} | ||
return call.clone(call.getType(), builder.build()); | ||
} else if (rex instanceof RexInputRef) { | ||
RexInputRef var = (RexInputRef) rex; | ||
int index = var.getIndex(); | ||
return rexBuilder.makeInputRef(var.getType(), inputRefMap.get(index)); | ||
} else { | ||
return rex; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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.RelOptRuleCall; | ||
import org.apache.calcite.rel.core.Correlate; | ||
import org.apache.calcite.rel.core.RelFactories; | ||
import org.apache.calcite.rel.rules.ProjectCorrelateTransposeRule; | ||
import org.apache.calcite.rel.rules.PushProjector; | ||
import org.apache.calcite.tools.RelBuilderFactory; | ||
|
||
public class DrillProjectLateralJoinTransposeRule extends ProjectCorrelateTransposeRule { | ||
|
||
public static final DrillProjectLateralJoinTransposeRule INSTANCE = new DrillProjectLateralJoinTransposeRule(PushProjector.ExprCondition.TRUE, RelFactories.LOGICAL_BUILDER); | ||
|
||
public DrillProjectLateralJoinTransposeRule(PushProjector.ExprCondition preserveExprCondition, RelBuilderFactory relFactory) { | ||
super(preserveExprCondition, relFactory); | ||
} | ||
|
||
@Override | ||
public boolean matches(RelOptRuleCall call) { | ||
Correlate correlate = call.rel(1); | ||
|
||
if (correlate instanceof DrillLateralJoinRel && ((DrillLateralJoinRel)correlate).excludeCorrelateColumn) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pls add a comment why this should not match if excludeCorrelateColumn is true. |
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
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.
An assumption here is that there is only 1 correlated column which is true for Drill's Lateral-Unnest implementation but I believe Calcite allows multiple. You could just put a Preconditions check here to be safe.