Skip to content

Commit adda628

Browse files
authored
[chore](Nereids) remove some useless code (#50953)
1 parent 7b259d3 commit adda628

File tree

8 files changed

+14
-249
lines changed

8 files changed

+14
-249
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundFunction.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class UnboundFunction extends Function implements Unbound, PropagateNulla
4646
/**
4747
* FunctionIndexInSql
4848
*/
49-
public static class FunctionIndexInSql implements Comparable<FunctionIndexInSql> {
49+
public static class FunctionIndexInSql {
5050
public final int functionNameBegin;
5151
public final int functionNameEnd;
5252
public final int functionExpressionEnd;
@@ -57,11 +57,6 @@ public FunctionIndexInSql(int nameBegin, int nameEnd, int expressionEnd) {
5757
this.functionExpressionEnd = expressionEnd;
5858
}
5959

60-
@Override
61-
public int compareTo(FunctionIndexInSql functionIndexInSql) {
62-
return this.functionNameBegin - functionIndexInSql.functionNameBegin;
63-
}
64-
6560
public FunctionIndexInSql indexInQueryPart(int offset) {
6661
return new FunctionIndexInSql(functionNameBegin - offset, functionNameEnd - offset,
6762
functionExpressionEnd - offset);

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import org.apache.doris.nereids.trees.expressions.functions.agg.AnyValue;
5858
import org.apache.doris.nereids.trees.expressions.functions.generator.TableGeneratingFunction;
5959
import org.apache.doris.nereids.trees.expressions.functions.scalar.GroupingScalarFunction;
60-
import org.apache.doris.nereids.trees.expressions.functions.scalar.Lambda;
6160
import org.apache.doris.nereids.trees.expressions.functions.scalar.StructElement;
6261
import org.apache.doris.nereids.trees.expressions.functions.table.TableValuedFunction;
6362
import org.apache.doris.nereids.trees.expressions.literal.IntegerLikeLiteral;
@@ -114,7 +113,6 @@
114113
import com.google.common.collect.Maps;
115114
import com.google.common.collect.Sets;
116115
import org.apache.commons.collections.CollectionUtils;
117-
import org.apache.commons.lang3.StringUtils;
118116
import org.apache.logging.log4j.LogManager;
119117
import org.apache.logging.log4j.Logger;
120118
import org.jetbrains.annotations.NotNull;
@@ -267,8 +265,7 @@ private LogicalPlan bindGenerate(MatchingContext<LogicalGenerate<Plan>> ctx) {
267265
Builder<Slot> outputSlots = ImmutableList.builder();
268266
Builder<Function> boundGenerators = ImmutableList.builder();
269267
List<Alias> expandAlias = Lists.newArrayList();
270-
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(
271-
generate, cascadesContext, generate.children(), true, true);
268+
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(generate, cascadesContext, generate.children());
272269
for (int i = 0; i < generate.getGeneratorOutput().size(); i++) {
273270
UnboundSlot slot = (UnboundSlot) generate.getGeneratorOutput().get(i);
274271
Preconditions.checkState(slot.getNameParts().size() == 2,
@@ -338,7 +335,7 @@ private LogicalSetOperation bindSetOperation(LogicalSetOperation setOperation) {
338335
Builder<Plan> newChildren = ImmutableList.builderWithExpectedSize(childrenProjectionSize);
339336
for (int i = 0; i < childrenProjectionSize; i++) {
340337
Plan newChild;
341-
if (childrenProjections.stream().allMatch(SlotReference.class::isInstance)) {
338+
if (childrenProjections.get(i).stream().allMatch(SlotReference.class::isInstance)) {
342339
newChild = setOperation.child(i);
343340
} else {
344341
newChild = new LogicalProject<>(childrenProjections.get(i), setOperation.child(i));
@@ -355,8 +352,7 @@ private LogicalSetOperation bindSetOperation(LogicalSetOperation setOperation) {
355352
private LogicalOneRowRelation bindOneRowRelation(MatchingContext<UnboundOneRowRelation> ctx) {
356353
UnboundOneRowRelation oneRowRelation = ctx.root;
357354
CascadesContext cascadesContext = ctx.cascadesContext;
358-
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(
359-
oneRowRelation, cascadesContext, ImmutableList.of(), true, true);
355+
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(oneRowRelation, cascadesContext, ImmutableList.of());
360356
List<NamedExpression> projects = analyzer.analyzeToList(oneRowRelation.getProjects());
361357
return new LogicalOneRowRelation(oneRowRelation.getRelationId(), projects);
362358
}
@@ -555,8 +551,7 @@ private LogicalSort<LogicalSetOperation> bindSortWithSetOperation(
555551
CascadesContext cascadesContext = ctx.cascadesContext;
556552

557553
List<Slot> childOutput = sort.child().getOutput();
558-
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(
559-
sort, cascadesContext, sort.children(), true, true);
554+
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(sort, cascadesContext, sort.children());
560555
Builder<OrderKey> boundKeys = ImmutableList.builderWithExpectedSize(sort.getOrderKeys().size());
561556
for (OrderKey orderKey : sort.getOrderKeys()) {
562557
Expression boundKey = bindWithOrdinal(orderKey.getExpr(), analyzer, childOutput);
@@ -571,8 +566,7 @@ private LogicalJoin<Plan, Plan> bindJoin(MatchingContext<LogicalJoin<Plan, Plan>
571566

572567
checkConflictAlias(join);
573568

574-
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(
575-
join, cascadesContext, join.children(), true, true);
569+
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(join, cascadesContext, join.children());
576570

577571
Builder<Expression> hashJoinConjuncts = ImmutableList.builderWithExpectedSize(
578572
join.getHashJoinConjuncts().size());
@@ -670,9 +664,7 @@ private Plan bindProject(MatchingContext<LogicalProject<Plan>> ctx) {
670664
LogicalProject<Plan> project = ctx.root;
671665
CascadesContext cascadesContext = ctx.cascadesContext;
672666

673-
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(
674-
project, cascadesContext, project.children(), true, true);
675-
667+
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(project, cascadesContext, project.children());
676668
Builder<NamedExpression> boundProjectionsBuilder
677669
= ImmutableList.builderWithExpectedSize(project.getProjects().size());
678670
StatementContext statementContext = ctx.statementContext;
@@ -756,9 +748,7 @@ private Plan bindLoadProject(MatchingContext<LogicalLoadProject<Plan>> ctx) {
756748
LogicalLoadProject<Plan> project = ctx.root;
757749
CascadesContext cascadesContext = ctx.cascadesContext;
758750

759-
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(
760-
project, cascadesContext, project.children(), true, true);
761-
751+
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(project, cascadesContext, project.children());
762752
Builder<NamedExpression> boundProjections = ImmutableList.builderWithExpectedSize(project.getProjects().size());
763753
StatementContext statementContext = ctx.statementContext;
764754
for (Expression expression : project.getProjects()) {
@@ -824,8 +814,7 @@ private Plan bindFilter(MatchingContext<LogicalFilter<Plan>> ctx) {
824814
LogicalFilter<Plan> filter = ctx.root;
825815
CascadesContext cascadesContext = ctx.cascadesContext;
826816

827-
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(
828-
filter, cascadesContext, filter.children(), true, true);
817+
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(filter, cascadesContext, filter.children());
829818
ImmutableSet.Builder<Expression> boundConjuncts = ImmutableSet.builderWithExpectedSize(
830819
filter.getConjuncts().size());
831820
for (Expression conjunct : filter.getConjuncts()) {
@@ -840,8 +829,7 @@ private Plan bindPreFilter(MatchingContext<LogicalPreFilter<Plan>> ctx) {
840829
LogicalPreFilter<Plan> filter = ctx.root;
841830
CascadesContext cascadesContext = ctx.cascadesContext;
842831

843-
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(
844-
filter, cascadesContext, filter.children(), true, true);
832+
SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer(filter, cascadesContext, filter.children());
845833
ImmutableSet.Builder<Expression> boundConjuncts = ImmutableSet.builderWithExpectedSize(
846834
filter.getConjuncts().size());
847835
for (Expression conjunct : filter.getConjuncts()) {
@@ -1052,8 +1040,7 @@ private Plan bindAggregate(MatchingContext<LogicalAggregate<Plan>> ctx) {
10521040
LogicalAggregate<Plan> agg = ctx.root;
10531041
CascadesContext cascadesContext = ctx.cascadesContext;
10541042

1055-
SimpleExprAnalyzer aggOutputAnalyzer = buildSimpleExprAnalyzer(
1056-
agg, cascadesContext, agg.children(), true, true);
1043+
SimpleExprAnalyzer aggOutputAnalyzer = buildSimpleExprAnalyzer(agg, cascadesContext, agg.children());
10571044
List<NamedExpression> boundAggOutput = aggOutputAnalyzer.analyzeToList(agg.getOutputExpressions());
10581045
List<NamedExpression> boundProjections = new ArrayList<>(boundAggOutput.size());
10591046
for (int i = 0; i < boundAggOutput.size(); i++) {
@@ -1090,8 +1077,7 @@ private Plan bindRepeat(MatchingContext<LogicalRepeat<Plan>> ctx) {
10901077
LogicalRepeat<Plan> repeat = ctx.root;
10911078
CascadesContext cascadesContext = ctx.cascadesContext;
10921079

1093-
SimpleExprAnalyzer repeatOutputAnalyzer = buildSimpleExprAnalyzer(
1094-
repeat, cascadesContext, repeat.children(), true, true);
1080+
SimpleExprAnalyzer repeatOutputAnalyzer = buildSimpleExprAnalyzer(repeat, cascadesContext, repeat.children());
10951081
List<NamedExpression> boundRepeatOutput = repeatOutputAnalyzer.analyzeToList(repeat.getOutputExpressions());
10961082
Supplier<Scope> aggOutputScopeWithoutAggFun =
10971083
buildAggOutputScopeWithoutAggFun(boundRepeatOutput, cascadesContext);
@@ -1395,25 +1381,6 @@ private Expression bindWithOrdinal(
13951381
}
13961382
}
13971383

1398-
private <E extends Expression> E checkBoundExceptLambda(E expression, Plan plan) {
1399-
if (expression instanceof Lambda) {
1400-
return expression;
1401-
}
1402-
if (expression instanceof UnboundSlot) {
1403-
UnboundSlot unboundSlot = (UnboundSlot) expression;
1404-
String tableName = StringUtils.join(unboundSlot.getQualifier(), ".");
1405-
if (tableName.isEmpty()) {
1406-
tableName = "table list";
1407-
}
1408-
throw new AnalysisException("Unknown column '"
1409-
+ unboundSlot.getNameParts().get(unboundSlot.getNameParts().size() - 1)
1410-
+ "' in '" + tableName + "' in "
1411-
+ plan.getType().toString().substring("LOGICAL_".length()) + " clause");
1412-
}
1413-
expression.children().forEach(e -> checkBoundExceptLambda(e, plan));
1414-
return expression;
1415-
}
1416-
14171384
private Scope toScope(CascadesContext cascadesContext, List<Slot> slots) {
14181385
Optional<Scope> outerScope = cascadesContext.getOuterScope();
14191386
if (outerScope.isPresent()) {
@@ -1433,19 +1400,12 @@ private Scope toScope(CascadesContext cascadesContext, List<Slot> slots, List<Sl
14331400
}
14341401

14351402
private SimpleExprAnalyzer buildSimpleExprAnalyzer(
1436-
Plan currentPlan, CascadesContext cascadesContext, List<Plan> children,
1437-
boolean enableExactMatch, boolean bindSlotInOuterScope) {
1403+
Plan currentPlan, CascadesContext cascadesContext, List<Plan> children) {
14381404
Scope scope = toScope(cascadesContext, PlanUtils.fastGetChildrenOutputs(children),
14391405
PlanUtils.fastGetChildrenAsteriskOutputs(children));
1440-
return buildSimpleExprAnalyzer(currentPlan, cascadesContext, scope, enableExactMatch, bindSlotInOuterScope);
1441-
}
1442-
1443-
private SimpleExprAnalyzer buildSimpleExprAnalyzer(
1444-
Plan currentPlan, CascadesContext cascadesContext, Scope scope,
1445-
boolean enableExactMatch, boolean bindSlotInOuterScope) {
14461406
ExpressionRewriteContext rewriteContext = new ExpressionRewriteContext(cascadesContext);
14471407
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(currentPlan,
1448-
scope, cascadesContext, enableExactMatch, bindSlotInOuterScope);
1408+
scope, cascadesContext, true, true);
14491409
return expr -> expressionAnalyzer.analyze(expr, rewriteContext);
14501410
}
14511411

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateLogicalSelectHint.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ private void extractLeading(SelectHintLeading selectHint, CascadesContext contex
112112
} else {
113113
context.setLeadingJoin(true);
114114
}
115-
assert (selectHint != null);
116-
assert (context != null);
117115
}
118116

119117
private void extractRule(SelectHintUseCboRule selectHint, StatementContext statementContext) {

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import org.apache.doris.nereids.trees.expressions.InSubquery;
5757
import org.apache.doris.nereids.trees.expressions.IntegralDivide;
5858
import org.apache.doris.nereids.trees.expressions.Match;
59-
import org.apache.doris.nereids.trees.expressions.NamedExpression;
6059
import org.apache.doris.nereids.trees.expressions.Not;
6160
import org.apache.doris.nereids.trees.expressions.Or;
6261
import org.apache.doris.nereids.trees.expressions.Placeholder;
@@ -67,7 +66,6 @@
6766
import org.apache.doris.nereids.trees.expressions.WhenClause;
6867
import org.apache.doris.nereids.trees.expressions.functions.BoundFunction;
6968
import org.apache.doris.nereids.trees.expressions.functions.FunctionBuilder;
70-
import org.apache.doris.nereids.trees.expressions.functions.scalar.ElementAt;
7169
import org.apache.doris.nereids.trees.expressions.functions.scalar.Lambda;
7270
import org.apache.doris.nereids.trees.expressions.functions.udf.AliasUdfBuilder;
7371
import org.apache.doris.nereids.trees.expressions.functions.udf.JavaUdaf;
@@ -266,10 +264,6 @@ public Expression visitUnboundAlias(UnboundAlias unboundAlias, ExpressionRewrite
266264
Expression child = unboundAlias.child().accept(this, context);
267265
if (unboundAlias.getAlias().isPresent()) {
268266
return new Alias(child, unboundAlias.getAlias().get(), unboundAlias.isNameFromChild());
269-
// TODO: the variant bind element_at(slot, 'name') will return a slot, and we should
270-
// assign an Alias to this function, this is trick and should refactor it
271-
} else if (!(unboundAlias.child() instanceof ElementAt) && child instanceof NamedExpression) {
272-
return new Alias(child, ((NamedExpression) child).getName());
273267
} else {
274268
return new Alias(child);
275269
}
@@ -891,10 +885,6 @@ public List<Slot> bindSlotByScope(UnboundSlot unboundSlot, Scope scope) {
891885
}
892886
}
893887

894-
public static boolean compareDbName(String boundedDbName, String unBoundDbName) {
895-
return unBoundDbName.equalsIgnoreCase(boundedDbName);
896-
}
897-
898888
public static boolean sameTableName(String boundSlot, String unboundSlot) {
899889
if (GlobalVariable.lowerCaseTableNames != 1) {
900890
return boundSlot.equals(unboundSlot);

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SubqueryToApply.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.doris.nereids.rules.expression.ExpressionRewriteContext;
2727
import org.apache.doris.nereids.rules.expression.rules.TrySimplifyPredicateWithMarkJoinSlot;
2828
import org.apache.doris.nereids.trees.expressions.Alias;
29-
import org.apache.doris.nereids.trees.expressions.And;
3029
import org.apache.doris.nereids.trees.expressions.CompoundPredicate;
3130
import org.apache.doris.nereids.trees.expressions.Exists;
3231
import org.apache.doris.nereids.trees.expressions.Expression;
@@ -35,7 +34,6 @@
3534
import org.apache.doris.nereids.trees.expressions.LessThanEqual;
3635
import org.apache.doris.nereids.trees.expressions.MarkJoinSlotReference;
3736
import org.apache.doris.nereids.trees.expressions.NamedExpression;
38-
import org.apache.doris.nereids.trees.expressions.Not;
3937
import org.apache.doris.nereids.trees.expressions.Or;
4038
import org.apache.doris.nereids.trees.expressions.ScalarSubquery;
4139
import org.apache.doris.nereids.trees.expressions.Slot;
@@ -677,24 +675,6 @@ private enum SearchState {
677675
SearchExistsOrInSubquery
678676
}
679677

680-
private boolean shouldOutputMarkJoinSlot(Expression expr, SearchState searchState) {
681-
if (searchState == SearchState.SearchNot && expr instanceof Not) {
682-
if (shouldOutputMarkJoinSlot(((Not) expr).child(), SearchState.SearchAnd)) {
683-
return true;
684-
}
685-
} else if (searchState == SearchState.SearchAnd && expr instanceof And) {
686-
for (Expression child : expr.children()) {
687-
if (shouldOutputMarkJoinSlot(child, SearchState.SearchExistsOrInSubquery)) {
688-
return true;
689-
}
690-
}
691-
} else if (searchState == SearchState.SearchExistsOrInSubquery
692-
&& (expr instanceof InSubquery || expr instanceof Exists)) {
693-
return true;
694-
}
695-
return false;
696-
}
697-
698678
private List<Boolean> shouldOutputMarkJoinSlot(Collection<Expression> conjuncts) {
699679
ImmutableList.Builder<Boolean> result = ImmutableList.builderWithExpectedSize(conjuncts.size());
700680
for (Expression expr : conjuncts) {

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateMarkJoin.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)