classAggregateRule
final class AggregateRule
Lowers the aggregate functions: sum_expr with its argument forms, GROUP_CONCAT and JSON_OBJECTAGG.
Rule: MYSQL-CALL-AGGREGATE-001. Scope: sum_expr, in_sum_expr, opt_distinct, opt_gorder_clause, gorder_list, opt_gconcat_separator. Each production names its function, whether DISTINCT is written, the form and position of its argument (an operand with an optional ALL, an expression list, or the star with an optional ALL), and the position of its window (MySQL 8.0 and later). Constructs: Aggregate, GroupConcat, JsonObjectAggregate. Terminates: the ordering list is flattened in a loop; every other child is a strict subtree. Source: https://dev.mysql.com/doc/refman/8.4/en/aggregate-functions.html. Status: Implemented.
Methods§
public function __construct(private Lowering $lowering, private WindowRule $windows)Parameters
$lowering | Lowering | The lowering this rule belongs to |
$windows | WindowRule | The window rules |
Lowers an aggregate: a node of sum_expr.
Parameters
$call | Node |
Returns
Throws
ImplementationGap When a production has no ruleTest cases 2
Called from 1
Calls 12
- method-call Lowering::form() line 114
- function-call
array_key_existsline 115 - class-const AggregateRule::CONCATENATIONS() line 115
- method-call AggregateRule::concatenation() line 116
- class-const AggregateRule::OBJECTS() line 118
- method-call AggregateRule::operand() line 120
- new JsonObjectAggregate line 123
- method-call WindowRule::windowing() line 123
- class-const AggregateRule::AGGREGATES() line 125
- static-call ImplementationGap::production() line 125
- method-call AggregateRule::single() line 127
- new Aggregate line 132
public function concatenation(Form $form, ?int $window): GroupConcatLowers GROUP_CONCAT.
Parameters
$form | Form | |
$window | ?int |
Returns
Test cases 1
Called from 1
Calls 6
- new GroupConcat line 140
- method-call Form::node() line 141
- method-call AggregateRule::distinct() line 142
- method-call AggregateRule::ordering() line 143
- method-call AggregateRule::separator() line 144
- method-call WindowRule::windowing() line 145
public function single(Node $operand): array{bool, list<Scalar>}Lowers the one operand of an aggregate as an argument list.
Parameters
$operand | Node |
Returns
array{bool, list<Scalar>}Test cases 1
Called from 1
Calls 1
- method-call AggregateRule::operand() line 156
public function operand(Node $operand): array{bool, Scalar}Lowers an aggregated operand with its optional ALL: a node of in_sum_expr.
Parameters
$operand | Node |
Returns
array{bool, Scalar}Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 3
- method-call SqlSemantics\Platform\MySql\Lowering\Call\AggregateRule::aggregate() packages/sql-semantics-mysql/src/Lowering/Call/AggregateRule.php:120
- method-call SqlSemantics\Platform\MySql\Lowering\Call\AggregateRule::aggregate() packages/sql-semantics-mysql/src/Lowering/Call/AggregateRule.php:121
- method-call SqlSemantics\Platform\MySql\Lowering\Call\AggregateRule::single() packages/sql-semantics-mysql/src/Lowering/Call/AggregateRule.php:156
Calls 2
- method-call Lowering::form() line 169
- static-call ImplementationGap::production() line 171
public function distinct(Node $option): boolTells whether DISTINCT is written: a node of opt_distinct.
Parameters
$option | Node |
Returns
boolThrows
ImplementationGap When the production has no ruleTest cases 1
Called from 1
Calls 2
- method-call Lowering::form() line 184
- static-call ImplementationGap::production() line 189
Lowers the ordering of GROUP_CONCAT: a node of opt_gorder_clause.
Parameters
$clause | Node |
Returns
list<OrderItem>Throws
ImplementationGap When a production has no ruleTest cases 1
Called from 1
Calls 4
- method-call Lowering::form() line 201
- static-call ImplementationGap::production() line 206
- function-call
array_popline 211 - function-call
array_unshiftline 219
Lowers the separator of GROUP_CONCAT: a node of opt_gconcat_separator.
Parameters
$clause | Node |
Returns
?TextThrows
ImplementationGap When the production has no ruleTest cases 1
Called from 1
Calls 2
- method-call Lowering::form() line 236
- static-call ImplementationGap::production() line 241
Private surface 5§
Implementation details, listed for orientation only.
private const AGGREGATES = ['sum_expr: AVG_SYM ( in_sum_expr )' => [\SqlSemantics\Platform\MySql\Statement…private const CONCATENATIONS = ['sum_expr: GROUP_CONCAT_SYM ( opt_distinct expr_list opt_gorder_clause opt_gco…private const OBJECTS = ['sum_expr: JSON_OBJECTAGG ( in_sum_expr , in_sum_expr )' => null, 'sum_expr: J…private Lowering $loweringprivate WindowRule $windowsTest cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
AggregateRuleTest::testAggregateLowersEveryArgumentFormcallsAggregateRuleTest::testAggregateReportsAnotherNodecallsAggregateRuleTest::testConcatenationLowersGroupConcatcallsAggregateRuleTest::testDistinctTellsWhetherDistinctIsWrittencallsAggregateRuleTest::testOperandLowersAllcallsAggregateRuleTest::testOrderingLowersNoOrderingcallsAggregateRuleTest::testSeparatorLowersNoSeparatorcallsAggregateRuleTest::testSingleLowersOneOperandAsAListcalls