@@ -397,8 +397,8 @@ public void testCombineProjectionWithAggregation() {
397
397
/**
398
398
* Expects
399
399
* Limit[1000[INTEGER]]
400
- * \_Aggregate[[last_name{f}#23, first_name{f}#20, k{r}#4 ],[SUM(salary{f}#24) AS s, last_name{f}#23, first_name{f}#20, first_n
401
- * ame{f}#20 AS k]]
400
+ * \_Aggregate[[last_name{f}#23, first_name{f}#20],[SUM(salary{f}#24) AS s, last_name{f}#23, first_name{f}#20, first_name{f}#2
401
+ * 0 AS k]]
402
402
* \_EsRelation[test][_meta_field{f}#25, emp_no{f}#19, first_name{f}#20, ..]
403
403
*/
404
404
public void testCombineProjectionWithAggregationAndEval () {
@@ -412,7 +412,7 @@ public void testCombineProjectionWithAggregationAndEval() {
412
412
var limit = as (plan , Limit .class );
413
413
var agg = as (limit .child (), Aggregate .class );
414
414
assertThat (Expressions .names (agg .aggregates ()), contains ("s" , "last_name" , "first_name" , "k" ));
415
- assertThat (Expressions .names (agg .groupings ()), contains ("last_name" , "first_name" , "k" ));
415
+ assertThat (Expressions .names (agg .groupings ()), contains ("last_name" , "first_name" ));
416
416
}
417
417
418
418
/**
@@ -454,6 +454,12 @@ public void testQlComparisonOptimizationsApply() {
454
454
assertThat (con .value (), equalTo (5 ));
455
455
}
456
456
457
+ /**
458
+ * Expects
459
+ * Limit[1000[INTEGER]]
460
+ * \_Aggregate[[first_name{f}#12],[COUNT(salary{f}#16) AS count(salary), first_name{f}#12 AS x]]
461
+ * \_EsRelation[test][_meta_field{f}#17, emp_no{f}#11, first_name{f}#12, ..]
462
+ */
457
463
public void testCombineProjectionWithPruning () {
458
464
var plan = plan ("""
459
465
from test
@@ -465,19 +471,17 @@ public void testCombineProjectionWithPruning() {
465
471
var limit = as (plan , Limit .class );
466
472
var agg = as (limit .child (), Aggregate .class );
467
473
assertThat (Expressions .names (agg .aggregates ()), contains ("count(salary)" , "x" ));
468
- assertThat (Expressions .names (agg .groupings ()), contains ("x " ));
474
+ assertThat (Expressions .names (agg .groupings ()), contains ("first_name " ));
469
475
var alias = as (agg .aggregates ().get (1 ), Alias .class );
470
476
var field = as (alias .child (), FieldAttribute .class );
471
477
assertThat (field .name (), is ("first_name" ));
472
- var group = as (agg .groupings ().get (0 ), Attribute .class );
473
- assertThat (group , is (alias .toAttribute ()));
474
478
var from = as (agg .child (), EsRelation .class );
475
479
}
476
480
477
481
/**
478
482
* Expects
479
483
* Limit[1000[INTEGER]]
480
- * \_Aggregate[[f{r}#7 ],[SUM(emp_no{f}#15) AS s, COUNT(first_name{f}#16) AS c, first_name{f}#16 AS f]]
484
+ * \_Aggregate[[first_name{f}#16 ],[SUM(emp_no{f}#15) AS s, COUNT(first_name{f}#16) AS c, first_name{f}#16 AS f]]
481
485
* \_EsRelation[test][_meta_field{f}#21, emp_no{f}#15, first_name{f}#16, ..]
482
486
*/
483
487
public void testCombineProjectionWithAggregationFirstAndAliasedGroupingUsedInAgg () {
@@ -501,13 +505,13 @@ public void testCombineProjectionWithAggregationFirstAndAliasedGroupingUsedInAgg
501
505
as = as (aggs .get (2 ), Alias .class );
502
506
assertThat (Expressions .name (as .child ()), is ("first_name" ));
503
507
504
- assertThat (Expressions .names (agg .groupings ()), contains ("f " ));
508
+ assertThat (Expressions .names (agg .groupings ()), contains ("first_name " ));
505
509
}
506
510
507
511
/**
508
512
* Expects
509
513
* Limit[1000[INTEGER]]
510
- * \_Aggregate[[f{r}#7 ],[SUM(emp_no{f}#15) AS s, first_name{f}#16 AS f]]
514
+ * \_Aggregate[[first_name{f}#16 ],[SUM(emp_no{f}#15) AS s, first_name{f}#16 AS f]]
511
515
* \_EsRelation[test][_meta_field{f}#21, emp_no{f}#15, first_name{f}#16, ..]
512
516
*/
513
517
public void testCombineProjectionWithAggregationFirstAndAliasedGroupingUnused () {
@@ -527,7 +531,7 @@ public void testCombineProjectionWithAggregationFirstAndAliasedGroupingUnused()
527
531
as = as (aggs .get (1 ), Alias .class );
528
532
assertThat (Expressions .name (as .child ()), is ("first_name" ));
529
533
530
- assertThat (Expressions .names (agg .groupings ()), contains ("f " ));
534
+ assertThat (Expressions .names (agg .groupings ()), contains ("first_name " ));
531
535
}
532
536
533
537
/**
@@ -2688,6 +2692,27 @@ public void testEliminateDuplicateAggsNonCount() {
2688
2692
var source = as (agg .child (), EsRelation .class );
2689
2693
}
2690
2694
2695
+ /**
2696
+ * Expects
2697
+ * Limit[1000[INTEGER]]
2698
+ * \_Aggregate[[salary{f}#12],[salary{f}#12, salary{f}#12 AS x]]
2699
+ * \_EsRelation[test][_meta_field{f}#13, emp_no{f}#7, first_name{f}#8, ge..]
2700
+ */
2701
+ public void testEliminateDuplicateRenamedGroupings () {
2702
+ var plan = plan ("""
2703
+ from test
2704
+ | eval x = salary
2705
+ | stats by salary, x
2706
+ """ );
2707
+
2708
+ var limit = as (plan , Limit .class );
2709
+ var agg = as (limit .child (), Aggregate .class );
2710
+ var relation = as (agg .child (), EsRelation .class );
2711
+
2712
+ assertThat (Expressions .names (agg .groupings ()), contains ("salary" ));
2713
+ assertThat (Expressions .names (agg .aggregates ()), contains ("salary" , "x" ));
2714
+ }
2715
+
2691
2716
/**
2692
2717
* Expected
2693
2718
* Limit[2[INTEGER]]
@@ -2734,7 +2759,7 @@ public void testRenameStatsDropGroup() {
2734
2759
/**
2735
2760
* Expected
2736
2761
* Limit[1000[INTEGER]]
2737
- * \_Aggregate[[a{r}#2, bar {r}#8 ],[COUNT([2a][KEYWORD]) AS baz, b{r}#4 AS bar]]
2762
+ * \_Aggregate[[a{r}#3, b {r}#5 ],[COUNT([2a][KEYWORD]) AS baz, b{r}#5 AS bar]]
2738
2763
* \_Row[[1[INTEGER] AS a, 2[INTEGER] AS b]]
2739
2764
*/
2740
2765
public void testMultipleRenameStatsDropGroup () {
@@ -2746,15 +2771,15 @@ public void testMultipleRenameStatsDropGroup() {
2746
2771
2747
2772
var limit = as (plan , Limit .class );
2748
2773
var agg = as (limit .child (), Aggregate .class );
2749
- assertThat (Expressions .names (agg .groupings ()), contains ("a" , "bar " ));
2774
+ assertThat (Expressions .names (agg .groupings ()), contains ("a" , "b " ));
2750
2775
var row = as (agg .child (), Row .class );
2751
2776
}
2752
2777
2753
2778
/**
2754
2779
* Expected
2755
2780
* Limit[1000[INTEGER]]
2756
- * \_Aggregate[[emp_no{f}#11, bar{r}#4 ],[MAX(salary{f}#16 ) AS baz, gender{f}#13 AS bar]]
2757
- * \_EsRelation[test][_meta_field{f}#17 , emp_no{f}#11 , first_name{f}#12 , ..]
2781
+ * \_Aggregate[[emp_no{f}#14, gender{f}#16 ],[MAX(salary{f}#19 ) AS baz, gender{f}#16 AS bar]]
2782
+ * \_EsRelation[test][_meta_field{f}#20 , emp_no{f}#14 , first_name{f}#15 , ..]
2758
2783
*/
2759
2784
public void testMultipleRenameStatsDropGroupMultirow () {
2760
2785
LogicalPlan plan = optimizedPlan ("""
@@ -2765,7 +2790,7 @@ public void testMultipleRenameStatsDropGroupMultirow() {
2765
2790
2766
2791
var limit = as (plan , Limit .class );
2767
2792
var agg = as (limit .child (), Aggregate .class );
2768
- assertThat (Expressions .names (agg .groupings ()), contains ("emp_no" , "bar " ));
2793
+ assertThat (Expressions .names (agg .groupings ()), contains ("emp_no" , "gender " ));
2769
2794
var row = as (agg .child (), EsRelation .class );
2770
2795
}
2771
2796
@@ -2846,7 +2871,7 @@ public void testIsNotNullConstraintForStatsWithAndOnGrouping() {
2846
2871
/**
2847
2872
* Expects
2848
2873
* Limit[1000[INTEGER]]
2849
- * \_Aggregate[[x{r}#4 ],[SUM(salary{f}#13) AS sum(salary), salary{f}#13 AS x]]
2874
+ * \_Aggregate[[salary{f}#13 ],[SUM(salary{f}#13) AS sum(salary), salary{f}#13 AS x]]
2850
2875
* \_EsRelation[test][_meta_field{f}#14, emp_no{f}#8, first_name{f}#9, ge..]
2851
2876
*/
2852
2877
public void testIsNotNullConstraintForStatsWithAndOnGroupingAlias () {
@@ -2858,7 +2883,7 @@ public void testIsNotNullConstraintForStatsWithAndOnGroupingAlias() {
2858
2883
2859
2884
var limit = as (plan , Limit .class );
2860
2885
var agg = as (limit .child (), Aggregate .class );
2861
- assertThat (Expressions .names (agg .groupings ()), contains ("x " ));
2886
+ assertThat (Expressions .names (agg .groupings ()), contains ("salary " ));
2862
2887
assertThat (Expressions .names (agg .aggregates ()), contains ("sum(salary)" , "x" ));
2863
2888
var from = as (agg .child (), EsRelation .class );
2864
2889
}
0 commit comments