Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
Signed-off-by: before-Sunrise <[email protected]>
  • Loading branch information
before-Sunrise committed Feb 11, 2025
1 parent 7c2ebbf commit cd4d88d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@
import com.starrocks.sql.optimizer.operator.scalar.ScalarOperator;

import java.util.List;
import java.util.Map;
import java.util.Objects;

public class PhysicalSplitConsumeOperator extends PhysicalOperator {
private final int splitId;

private ScalarOperator splitPredicate;

private final List<ColumnRefOperator> outputColumnRefOp;
private final ScalarOperator splitPredicate;

public PhysicalSplitConsumeOperator(int splitId, ScalarOperator splitPredicate, DistributionSpec distributionSpec,
List<ColumnRefOperator> outputColumnRefOp) {
Expand Down Expand Up @@ -74,8 +71,7 @@ public boolean equals(Object o) {
}

PhysicalSplitConsumeOperator that = (PhysicalSplitConsumeOperator) o;
return Objects.equals(splitId, that.splitId) &&
Objects.equals(splitPredicate, that.splitPredicate);
return Objects.equals(splitId, that.splitId) && Objects.equals(splitPredicate, that.splitPredicate);
}

@Override
Expand All @@ -85,10 +81,7 @@ public int hashCode() {

@Override
public String toString() {
return "PhysicalSplitConsumeOperator{" +
"splitId='" + splitId + '\'' +
", predicate=" + splitPredicate +
'}';
return "PhysicalSplitConsumeOperator{" + "splitId='" + splitId + '\'' + ", predicate=" + splitPredicate + '}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
* child1 child2
*/
public class SkewShuffleJoinEliminationRule implements TreeRewriteRule {
private AtomicInteger uniqueSplitId;
private final AtomicInteger uniqueSplitId;

private SkewShuffleJoinEliminationVisitor handler = null;

Expand All @@ -99,31 +99,31 @@ public OptExpression rewrite(OptExpression root, TaskContext taskContext) {
}

private class SkewShuffleJoinEliminationVisitor extends OptExpressionVisitor<OptExpression, Void> {
private ColumnRefFactory columnRefFactory;
private final ColumnRefFactory columnRefFactory;

public SkewShuffleJoinEliminationVisitor(ColumnRefFactory columnRefFactory) {
this.columnRefFactory = columnRefFactory;
}

@Override
public OptExpression visit(OptExpression optExpr, Void Context) {
return visitChild(optExpr, Context);
public OptExpression visit(OptExpression optExpr, Void context) {
return visitChild(optExpr, context);
}

private OptExpression visitChild(OptExpression opt, Void Context) {
private OptExpression visitChild(OptExpression opt, Void context) {
for (int idx = 0; idx < opt.arity(); ++idx) {
OptExpression child = opt.inputAt(idx);
opt.setChild(idx, child.getOp().accept(this, child, null));
opt.setChild(idx, child.getOp().accept(this, child, context));
}
return opt;
}

@Override
public OptExpression visitPhysicalHashJoin(OptExpression opt, Void Context) {
public OptExpression visitPhysicalHashJoin(OptExpression opt, Void context) {
PhysicalHashJoinOperator originalShuffleJoinOperator = (PhysicalHashJoinOperator) opt.getOp();

if (!canOptimize(originalShuffleJoinOperator, opt)) {
return visitChild(opt, null);
return visitChild(opt, context);
}

// find skew columns, rewrite skew values if needed
Expand Down Expand Up @@ -205,7 +205,6 @@ public OptExpression visitPhysicalHashJoin(OptExpression opt, Void Context) {
originalShuffleJoinOperator.getPredicate(), projectionOnJoin,
leftSkewColumn, skewValues);


LocalExchangerType localExchangerType =
opt.isExistRequiredDistribution() ? LocalExchangerType.PASS_THROUGH : LocalExchangerType.DIRECT;
PhysicalConcatenateOperator concatenateOperator =
Expand Down Expand Up @@ -315,7 +314,6 @@ public OptExpression visitPhysicalHashJoin(OptExpression opt, Void Context) {
return cteAnchorOptExp2;
}


private Pair<ScalarOperator, ScalarOperator> generateInAndNotInPredicate(ScalarOperator skewColumn,
List<ScalarOperator> skewValues) {
List<ScalarOperator> inPredicateParams = new ArrayList<>();
Expand Down Expand Up @@ -346,7 +344,7 @@ private boolean isExchangeWithDistributionType(Operator child, DistributionSpec.

private PhysicalConcatenateOperator buildConcatenateOperator(List<ColumnRefOperator> outputColumns,
int childNum,
LocalExchangerType localExchangeType, long limit) {
LocalExchangerType localExchangeType, long limit) {
List<List<ColumnRefOperator>> childOutputColumns = new ArrayList<>();
for (int i = 0; i < childNum; i++) {
childOutputColumns.add(outputColumns);
Expand Down Expand Up @@ -401,7 +399,7 @@ private SkewColumnAndValues findSkewColumns(OptExpression input) {
}

Map<ColumnRefOperator, ScalarOperator> leftColumnRefMap = leftProjection.getAllMaps();
if (leftColumnRefMap.keySet().contains(leftSkewColumn)) {
if (leftColumnRefMap.containsKey(leftSkewColumn)) {
// this means leftSkewColumn is not a simple columnRef operator, so we need to rewrite skew values
// for example: if leftSkewColumn is cast(t1.c_tinyint as int), and skew values are (1,2,3)
// then we need to rewrite skew values as (cast(1 as int), cast(2 as int), cast(3 as int))
Expand Down Expand Up @@ -467,13 +465,10 @@ private boolean isShuffleJoin(OptExpression opt) {
if (opt.getOp().getOpType() != OperatorType.PHYSICAL_HASH_JOIN) {
return false;
}
if (!isExchangeWithDistributionType(opt.getInputs().get(0).getOp(),
DistributionSpec.DistributionType.SHUFFLE) ||
!isExchangeWithDistributionType(opt.getInputs().get(1).getOp(),
DistributionSpec.DistributionType.SHUFFLE)) {
return false;
}
return true;
return isExchangeWithDistributionType(opt.getInputs().get(0).getOp(),
DistributionSpec.DistributionType.SHUFFLE) &&
isExchangeWithDistributionType(opt.getInputs().get(1).getOp(),
DistributionSpec.DistributionType.SHUFFLE);
}

// right now only support join hint with left skew table, since left table is bigger
Expand All @@ -487,11 +482,7 @@ private boolean isSkew(OptExpression opt) {
}

// respect join hint
if (joinOperator.getJoinHint().equals(JoinOperator.HINT_SKEW)) {
return true;
}

return false;
return joinOperator.getJoinHint().equals(JoinOperator.HINT_SKEW);
}
}

Expand Down

0 comments on commit cd4d88d

Please sign in to comment.