Commit c5c65d2
committed
[SPARK-54292][SQL] Support aggregate functions and GROUP BY in |> SELECT pipe operators
### What changes were proposed in this pull request?
This PR allows aggregate functions and `GROUP BY` to be used in `|> SELECT` pipe operators. Previously, these were only allowed in `|> AGGREGATE` pipe operators.
**Example queries now supported:**
-- Aggregate in SELECT
table employees |> select sum(salary) as total_salary;
-- Aggregate with GROUP BY
table orders |> select customer_id, count(*) as order_count group by customer_id;
-- Chained operations
table data |> where status = 'active' |> select sum(value) as total;
### Why are the changes needed?
By lifting this restriction (with an opt-out mechanism), we make the SQL pipe operator syntax more intuitive while maintaining backwards compatibility.
### Does this PR introduce _any_ user-facing change?
**Yes**, but it is **backwards compatible**:
- **Previously failing queries now succeed**: Queries using aggregate functions in `|> SELECT` will now work instead of throwing `PIPE_OPERATOR_CONTAINS_AGGREGATE_FUNCTION` errors
- **All previously succeeding queries continue to work**: No regression; queries using `|> AGGREGATE` or non-aggregate pipe operators are unaffected
**Backwards Compatibility Guarantee:**
- ✅ No queries that worked before will break
- ✅ Only queries that previously failed will now succeed
### How was this patch tested?
1. **Unit Tests**: Added comprehensive test coverage in `pipe-operators.sql`:
- Positive tests: aggregates in SELECT, with WHERE, with chaining, with GROUP BY
- Negative tests: aggregates in WHERE (still fails as expected)
- Regression tests: verified `|> AGGREGATE` still works correctly
2. **Golden Files**: Regenerated and verified `pipe-operators.sql.out` and analyzer results
3. **Test Execution**: All tests pass successfully:
### Was this patch authored or co-authored using generative AI tooling?
Yes, `claude-4.5-sonnet` with manual editing and approval.
Closes #52987 from dtenedor/select-keyword-for-aggregates-pipe-syntax.
Authored-by: Daniel Tenedorio <[email protected]>
Signed-off-by: Daniel Tenedorio <[email protected]>1 parent 1214830 commit c5c65d2
File tree
6 files changed
+391
-291
lines changed- sql
- api/src/main/antlr4/org/apache/spark/sql/catalyst/parser
- catalyst/src/main/scala/org/apache/spark/sql/catalyst
- expressions
- parser
- core/src/test/resources/sql-tests
- analyzer-results
- inputs
- results
6 files changed
+391
-291
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1793 | 1793 | | |
1794 | 1794 | | |
1795 | 1795 | | |
1796 | | - | |
| 1796 | + | |
1797 | 1797 | | |
1798 | 1798 | | |
1799 | 1799 | | |
| |||
Lines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
83 | 88 | | |
84 | 89 | | |
85 | 90 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6605 | 6605 | | |
6606 | 6606 | | |
6607 | 6607 | | |
6608 | | - | |
| 6608 | + | |
6609 | 6609 | | |
6610 | 6610 | | |
6611 | 6611 | | |
| |||
6614 | 6614 | | |
6615 | 6615 | | |
6616 | 6616 | | |
6617 | | - | |
| 6617 | + | |
6618 | 6618 | | |
6619 | 6619 | | |
6620 | 6620 | | |
| |||
Lines changed: 157 additions & 125 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
632 | 632 | | |
633 | 633 | | |
634 | 634 | | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
667 | | - | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | 635 | | |
739 | 636 | | |
740 | 637 | | |
| |||
3683 | 3580 | | |
3684 | 3581 | | |
3685 | 3582 | | |
3686 | | - | |
3687 | | - | |
3688 | | - | |
3689 | | - | |
3690 | | - | |
3691 | | - | |
3692 | | - | |
3693 | | - | |
3694 | | - | |
3695 | | - | |
3696 | | - | |
3697 | | - | |
3698 | | - | |
3699 | | - | |
3700 | | - | |
3701 | | - | |
3702 | | - | |
3703 | | - | |
3704 | | - | |
3705 | | - | |
3706 | | - | |
3707 | | - | |
3708 | 3583 | | |
3709 | 3584 | | |
3710 | 3585 | | |
| |||
4947 | 4822 | | |
4948 | 4823 | | |
4949 | 4824 | | |
| 4825 | + | |
| 4826 | + | |
| 4827 | + | |
| 4828 | + | |
| 4829 | + | |
| 4830 | + | |
| 4831 | + | |
| 4832 | + | |
| 4833 | + | |
| 4834 | + | |
| 4835 | + | |
| 4836 | + | |
| 4837 | + | |
| 4838 | + | |
| 4839 | + | |
| 4840 | + | |
| 4841 | + | |
| 4842 | + | |
| 4843 | + | |
| 4844 | + | |
| 4845 | + | |
| 4846 | + | |
| 4847 | + | |
| 4848 | + | |
| 4849 | + | |
| 4850 | + | |
| 4851 | + | |
| 4852 | + | |
| 4853 | + | |
| 4854 | + | |
| 4855 | + | |
| 4856 | + | |
| 4857 | + | |
| 4858 | + | |
| 4859 | + | |
| 4860 | + | |
| 4861 | + | |
| 4862 | + | |
| 4863 | + | |
| 4864 | + | |
| 4865 | + | |
| 4866 | + | |
| 4867 | + | |
| 4868 | + | |
| 4869 | + | |
| 4870 | + | |
| 4871 | + | |
| 4872 | + | |
| 4873 | + | |
| 4874 | + | |
| 4875 | + | |
| 4876 | + | |
| 4877 | + | |
| 4878 | + | |
| 4879 | + | |
| 4880 | + | |
| 4881 | + | |
| 4882 | + | |
| 4883 | + | |
| 4884 | + | |
| 4885 | + | |
| 4886 | + | |
| 4887 | + | |
| 4888 | + | |
| 4889 | + | |
| 4890 | + | |
| 4891 | + | |
| 4892 | + | |
| 4893 | + | |
| 4894 | + | |
| 4895 | + | |
| 4896 | + | |
| 4897 | + | |
| 4898 | + | |
| 4899 | + | |
| 4900 | + | |
| 4901 | + | |
| 4902 | + | |
| 4903 | + | |
| 4904 | + | |
| 4905 | + | |
| 4906 | + | |
| 4907 | + | |
| 4908 | + | |
| 4909 | + | |
| 4910 | + | |
| 4911 | + | |
| 4912 | + | |
| 4913 | + | |
| 4914 | + | |
| 4915 | + | |
| 4916 | + | |
| 4917 | + | |
| 4918 | + | |
| 4919 | + | |
| 4920 | + | |
| 4921 | + | |
| 4922 | + | |
| 4923 | + | |
| 4924 | + | |
| 4925 | + | |
| 4926 | + | |
| 4927 | + | |
| 4928 | + | |
| 4929 | + | |
| 4930 | + | |
| 4931 | + | |
| 4932 | + | |
| 4933 | + | |
| 4934 | + | |
| 4935 | + | |
| 4936 | + | |
| 4937 | + | |
| 4938 | + | |
| 4939 | + | |
| 4940 | + | |
| 4941 | + | |
| 4942 | + | |
| 4943 | + | |
| 4944 | + | |
| 4945 | + | |
| 4946 | + | |
| 4947 | + | |
| 4948 | + | |
| 4949 | + | |
| 4950 | + | |
| 4951 | + | |
| 4952 | + | |
| 4953 | + | |
| 4954 | + | |
| 4955 | + | |
| 4956 | + | |
| 4957 | + | |
| 4958 | + | |
| 4959 | + | |
| 4960 | + | |
| 4961 | + | |
| 4962 | + | |
| 4963 | + | |
| 4964 | + | |
| 4965 | + | |
| 4966 | + | |
| 4967 | + | |
| 4968 | + | |
| 4969 | + | |
| 4970 | + | |
| 4971 | + | |
| 4972 | + | |
| 4973 | + | |
| 4974 | + | |
| 4975 | + | |
| 4976 | + | |
| 4977 | + | |
| 4978 | + | |
| 4979 | + | |
| 4980 | + | |
| 4981 | + | |
4950 | 4982 | | |
4951 | 4983 | | |
4952 | 4984 | | |
| |||
0 commit comments