classAggregate
final class Aggregate
implements SetFunction
uses Snapshot
@visibility public.A call of an aggregate function with one argument, COUNT(*), or COUNT(DISTINCT ...) with several arguments.
Rule: MYSQL-AGGREGATE-001. The server builds the Item_sum classes. DISTINCT counts each distinct value once; ALL, written before the argument, is the default. With OVER the call is a window function (MySQL 8.0 and later). The result follows MYSQL-AGGREGATE-RESULT-001. Terminates: the arguments and the window are strict parts. Source: https://dev.mysql.com/doc/refman/8.4/en/aggregate-functions.html. Status: Implemented.
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT COUNT(*)');
[$query->field(0)->type->descriptor->name(), $query->field(0)->nullability] // => ['BIGINT', \SqlSemantics\Platform\MySql\Model\Statement\Type\Nullability::NotNull]new \SqlSemantics\Platform\MySql\Statement\Call\Aggregate\Aggregate(\SqlSemantics\Platform\MySql\Statement\Call\Aggregate\AggregateFunction::Sum, [new \SqlSemantics\Platform\MySql\Statement\Literal\NullLiteral(), new \SqlSemantics\Platform\MySql\Statement\Literal\NullLiteral()]) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\InvalidConstructionProperties§
public list<Scalar> $argumentspublic AggregateFunction $functionpublic bool $distinct = falsepublic bool $all = falsepublic Name|WindowSpecification|null $over = nullMethods§
public function __construct(
public AggregateFunction $function,
list<Scalar> $arguments,
public bool $distinct = false,
public bool $all = false,
public Name|WindowSpecification|null $over = null,
)Parameters
$function | AggregateFunction | The function |
$arguments | list<Scalar> | The arguments in order; none for COUNT(*) |
$distinct | bool | Whether DISTINCT is written |
$all | bool | Whether ALL is written before the argument or the star |
$over | Name|WindowSpecification|null | The window written after OVER |
Calls 6
- static-call Check::listOf() line 63
- class-const Scalar::class() line 63
- static-call Check::input() line 65
- class-const AggregateFunction::Count() line 65
- function-call
countline 66 - method-call AggregateFunction::distinctive() line 67
public function star(): boolTells whether the call is COUNT(*).
Returns
boolTest cases 1
public function aggregates(): boolTells whether the call aggregates its query block: it has no window.
Returns
boolTest cases 1
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the arguments, the window and the result.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 9
- method-call Aggregate::aggregates() line 92
- method-call HavingScope::leave() line 92
- new HavingScope line 92
- method-call Arguments::one() line 95
- new Arguments line 95
- method-call Windows::derive() line 97
- new Windows line 97
- method-call AggregateResults::aggregate() line 99
- new AggregateResults line 99
public function render(Output $out): voidWrites the call and its window.
Parameters
$out | Output |
Test cases 1
Calls 6
- method-call Output::keyword() line 107
- method-call Aggregate::star() line 114
- method-call Output::symbol() line 115
- method-call Output::list() line 117
- method-call Windows::render() line 118
- new Windows line 118
Test cases 10§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 4
Other tests reaching this symbol 6
AggregateRuleTest::testAggregateLowersEveryArgumentFormcallsCallRulesTest::testCallDispatchesEveryFamilyOfCallscallsAggregateResultsTest::testAggregateReportsDistinctInAWindowcallsAggregateResultsTest::testAggregateTypesEachFunctioncallsHavingScopeTest::testLeaveLetsTheArgumentsOfASetFunctionSeeTheColumnscallsSetFunctionTest::testAggregatesTellsAnAggregateFromItsWindowedFormcalls