( expr: BasicExpression, groupByClause: GroupBy, )
| 824 | } |
| 825 | |
| 826 | function replaceGroupByRefsInExpression( |
| 827 | expr: BasicExpression, |
| 828 | groupByClause: GroupBy, |
| 829 | ): BasicExpression { |
| 830 | if (expr.type === `ref`) { |
| 831 | const groupIndex = groupByClause.findIndex((groupExpr) => |
| 832 | expressionsEqual(expr, groupExpr), |
| 833 | ) |
| 834 | return groupIndex === -1 |
| 835 | ? expr |
| 836 | : new PropRef([`$selected`, `${GROUP_KEY_REF_PREFIX}${groupIndex}`]) |
| 837 | } |
| 838 | |
| 839 | if (expr.type === `func`) { |
| 840 | return new Func( |
| 841 | expr.name, |
| 842 | expr.args.map((arg) => |
| 843 | replaceGroupByRefsInExpression(arg, groupByClause), |
| 844 | ), |
| 845 | ) |
| 846 | } |
| 847 | |
| 848 | return expr |
| 849 | } |
| 850 | |
| 851 | function compileGroupedSelectValue( |
| 852 | value: SelectValueExpression, |
no test coverage detected