57
57
import org .apache .doris .nereids .trees .expressions .functions .agg .AnyValue ;
58
58
import org .apache .doris .nereids .trees .expressions .functions .generator .TableGeneratingFunction ;
59
59
import org .apache .doris .nereids .trees .expressions .functions .scalar .GroupingScalarFunction ;
60
- import org .apache .doris .nereids .trees .expressions .functions .scalar .Lambda ;
61
60
import org .apache .doris .nereids .trees .expressions .functions .scalar .StructElement ;
62
61
import org .apache .doris .nereids .trees .expressions .functions .table .TableValuedFunction ;
63
62
import org .apache .doris .nereids .trees .expressions .literal .IntegerLikeLiteral ;
114
113
import com .google .common .collect .Maps ;
115
114
import com .google .common .collect .Sets ;
116
115
import org .apache .commons .collections .CollectionUtils ;
117
- import org .apache .commons .lang3 .StringUtils ;
118
116
import org .apache .logging .log4j .LogManager ;
119
117
import org .apache .logging .log4j .Logger ;
120
118
import org .jetbrains .annotations .NotNull ;
@@ -267,8 +265,7 @@ private LogicalPlan bindGenerate(MatchingContext<LogicalGenerate<Plan>> ctx) {
267
265
Builder <Slot > outputSlots = ImmutableList .builder ();
268
266
Builder <Function > boundGenerators = ImmutableList .builder ();
269
267
List <Alias > expandAlias = Lists .newArrayList ();
270
- SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (
271
- generate , cascadesContext , generate .children (), true , true );
268
+ SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (generate , cascadesContext , generate .children ());
272
269
for (int i = 0 ; i < generate .getGeneratorOutput ().size (); i ++) {
273
270
UnboundSlot slot = (UnboundSlot ) generate .getGeneratorOutput ().get (i );
274
271
Preconditions .checkState (slot .getNameParts ().size () == 2 ,
@@ -338,7 +335,7 @@ private LogicalSetOperation bindSetOperation(LogicalSetOperation setOperation) {
338
335
Builder <Plan > newChildren = ImmutableList .builderWithExpectedSize (childrenProjectionSize );
339
336
for (int i = 0 ; i < childrenProjectionSize ; i ++) {
340
337
Plan newChild ;
341
- if (childrenProjections .stream ().allMatch (SlotReference .class ::isInstance )) {
338
+ if (childrenProjections .get ( i ). stream ().allMatch (SlotReference .class ::isInstance )) {
342
339
newChild = setOperation .child (i );
343
340
} else {
344
341
newChild = new LogicalProject <>(childrenProjections .get (i ), setOperation .child (i ));
@@ -355,8 +352,7 @@ private LogicalSetOperation bindSetOperation(LogicalSetOperation setOperation) {
355
352
private LogicalOneRowRelation bindOneRowRelation (MatchingContext <UnboundOneRowRelation > ctx ) {
356
353
UnboundOneRowRelation oneRowRelation = ctx .root ;
357
354
CascadesContext cascadesContext = ctx .cascadesContext ;
358
- SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (
359
- oneRowRelation , cascadesContext , ImmutableList .of (), true , true );
355
+ SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (oneRowRelation , cascadesContext , ImmutableList .of ());
360
356
List <NamedExpression > projects = analyzer .analyzeToList (oneRowRelation .getProjects ());
361
357
return new LogicalOneRowRelation (oneRowRelation .getRelationId (), projects );
362
358
}
@@ -555,8 +551,7 @@ private LogicalSort<LogicalSetOperation> bindSortWithSetOperation(
555
551
CascadesContext cascadesContext = ctx .cascadesContext ;
556
552
557
553
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 ());
560
555
Builder <OrderKey > boundKeys = ImmutableList .builderWithExpectedSize (sort .getOrderKeys ().size ());
561
556
for (OrderKey orderKey : sort .getOrderKeys ()) {
562
557
Expression boundKey = bindWithOrdinal (orderKey .getExpr (), analyzer , childOutput );
@@ -571,8 +566,7 @@ private LogicalJoin<Plan, Plan> bindJoin(MatchingContext<LogicalJoin<Plan, Plan>
571
566
572
567
checkConflictAlias (join );
573
568
574
- SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (
575
- join , cascadesContext , join .children (), true , true );
569
+ SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (join , cascadesContext , join .children ());
576
570
577
571
Builder <Expression > hashJoinConjuncts = ImmutableList .builderWithExpectedSize (
578
572
join .getHashJoinConjuncts ().size ());
@@ -670,9 +664,7 @@ private Plan bindProject(MatchingContext<LogicalProject<Plan>> ctx) {
670
664
LogicalProject <Plan > project = ctx .root ;
671
665
CascadesContext cascadesContext = ctx .cascadesContext ;
672
666
673
- SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (
674
- project , cascadesContext , project .children (), true , true );
675
-
667
+ SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (project , cascadesContext , project .children ());
676
668
Builder <NamedExpression > boundProjectionsBuilder
677
669
= ImmutableList .builderWithExpectedSize (project .getProjects ().size ());
678
670
StatementContext statementContext = ctx .statementContext ;
@@ -756,9 +748,7 @@ private Plan bindLoadProject(MatchingContext<LogicalLoadProject<Plan>> ctx) {
756
748
LogicalLoadProject <Plan > project = ctx .root ;
757
749
CascadesContext cascadesContext = ctx .cascadesContext ;
758
750
759
- SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (
760
- project , cascadesContext , project .children (), true , true );
761
-
751
+ SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (project , cascadesContext , project .children ());
762
752
Builder <NamedExpression > boundProjections = ImmutableList .builderWithExpectedSize (project .getProjects ().size ());
763
753
StatementContext statementContext = ctx .statementContext ;
764
754
for (Expression expression : project .getProjects ()) {
@@ -824,8 +814,7 @@ private Plan bindFilter(MatchingContext<LogicalFilter<Plan>> ctx) {
824
814
LogicalFilter <Plan > filter = ctx .root ;
825
815
CascadesContext cascadesContext = ctx .cascadesContext ;
826
816
827
- SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (
828
- filter , cascadesContext , filter .children (), true , true );
817
+ SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (filter , cascadesContext , filter .children ());
829
818
ImmutableSet .Builder <Expression > boundConjuncts = ImmutableSet .builderWithExpectedSize (
830
819
filter .getConjuncts ().size ());
831
820
for (Expression conjunct : filter .getConjuncts ()) {
@@ -840,8 +829,7 @@ private Plan bindPreFilter(MatchingContext<LogicalPreFilter<Plan>> ctx) {
840
829
LogicalPreFilter <Plan > filter = ctx .root ;
841
830
CascadesContext cascadesContext = ctx .cascadesContext ;
842
831
843
- SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (
844
- filter , cascadesContext , filter .children (), true , true );
832
+ SimpleExprAnalyzer analyzer = buildSimpleExprAnalyzer (filter , cascadesContext , filter .children ());
845
833
ImmutableSet .Builder <Expression > boundConjuncts = ImmutableSet .builderWithExpectedSize (
846
834
filter .getConjuncts ().size ());
847
835
for (Expression conjunct : filter .getConjuncts ()) {
@@ -1052,8 +1040,7 @@ private Plan bindAggregate(MatchingContext<LogicalAggregate<Plan>> ctx) {
1052
1040
LogicalAggregate <Plan > agg = ctx .root ;
1053
1041
CascadesContext cascadesContext = ctx .cascadesContext ;
1054
1042
1055
- SimpleExprAnalyzer aggOutputAnalyzer = buildSimpleExprAnalyzer (
1056
- agg , cascadesContext , agg .children (), true , true );
1043
+ SimpleExprAnalyzer aggOutputAnalyzer = buildSimpleExprAnalyzer (agg , cascadesContext , agg .children ());
1057
1044
List <NamedExpression > boundAggOutput = aggOutputAnalyzer .analyzeToList (agg .getOutputExpressions ());
1058
1045
List <NamedExpression > boundProjections = new ArrayList <>(boundAggOutput .size ());
1059
1046
for (int i = 0 ; i < boundAggOutput .size (); i ++) {
@@ -1090,8 +1077,7 @@ private Plan bindRepeat(MatchingContext<LogicalRepeat<Plan>> ctx) {
1090
1077
LogicalRepeat <Plan > repeat = ctx .root ;
1091
1078
CascadesContext cascadesContext = ctx .cascadesContext ;
1092
1079
1093
- SimpleExprAnalyzer repeatOutputAnalyzer = buildSimpleExprAnalyzer (
1094
- repeat , cascadesContext , repeat .children (), true , true );
1080
+ SimpleExprAnalyzer repeatOutputAnalyzer = buildSimpleExprAnalyzer (repeat , cascadesContext , repeat .children ());
1095
1081
List <NamedExpression > boundRepeatOutput = repeatOutputAnalyzer .analyzeToList (repeat .getOutputExpressions ());
1096
1082
Supplier <Scope > aggOutputScopeWithoutAggFun =
1097
1083
buildAggOutputScopeWithoutAggFun (boundRepeatOutput , cascadesContext );
@@ -1395,25 +1381,6 @@ private Expression bindWithOrdinal(
1395
1381
}
1396
1382
}
1397
1383
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
-
1417
1384
private Scope toScope (CascadesContext cascadesContext , List <Slot > slots ) {
1418
1385
Optional <Scope > outerScope = cascadesContext .getOuterScope ();
1419
1386
if (outerScope .isPresent ()) {
@@ -1433,19 +1400,12 @@ private Scope toScope(CascadesContext cascadesContext, List<Slot> slots, List<Sl
1433
1400
}
1434
1401
1435
1402
private SimpleExprAnalyzer buildSimpleExprAnalyzer (
1436
- Plan currentPlan , CascadesContext cascadesContext , List <Plan > children ,
1437
- boolean enableExactMatch , boolean bindSlotInOuterScope ) {
1403
+ Plan currentPlan , CascadesContext cascadesContext , List <Plan > children ) {
1438
1404
Scope scope = toScope (cascadesContext , PlanUtils .fastGetChildrenOutputs (children ),
1439
1405
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 ) {
1446
1406
ExpressionRewriteContext rewriteContext = new ExpressionRewriteContext (cascadesContext );
1447
1407
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer (currentPlan ,
1448
- scope , cascadesContext , enableExactMatch , bindSlotInOuterScope );
1408
+ scope , cascadesContext , true , true );
1449
1409
return expr -> expressionAnalyzer .analyze (expr , rewriteContext );
1450
1410
}
1451
1411
0 commit comments