packages/sql-semantics-mysql/src/Rules/Query/Having/GroupedRow.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\MySql\Rules\Query\Having;
6
7use SqlSemantics\Platform\MySql\Model\Construction\Derivation;
8use SqlSemantics\Platform\MySql\Model\Rendering\Output;
9use SqlSemantics\Platform\MySql\Model\Resolution\Environment;
10use SqlSemantics\Platform\MySql\Model\Statement\Fact\RelationFact;
11use SqlSemantics\Platform\MySql\Model\Statement\Reference\Column\ConditionalColumn;
12use SqlSemantics\Platform\MySql\Model\Statement\Relation;
13use SqlSemantics\Platform\MySql\Model\Statement\Shape\Field;
14use SqlSemantics\Platform\MySql\Model\Statement\Shape\OpenStar;
15use SqlSemantics\Platform\MySql\Model\Statement\Shape\RowShape;
16
17/**
18 * The entry of a HAVING environment that hands the select list and the GROUP BY columns to the names written there.
19 *
20 * Rule: MYSQL-HAVING-REFERENCE-001 (see `ResultReferences`). The entry
21 * travels as a visible occurrence with neither alias nor name and without
22 * any column, so no column lookup, qualifier or star can reach it; only
23 * `HavingScope` and `ResultReferences` recognise it, by its class. It is a
24 * working value of one derivation and never part of a statement.
25 * Source: https://dev.mysql.com/doc/refman/8.4/en/select.html. Status: Implemented.
26 *
27 * @visibility SqlSemantics\Platform\MySql
28 */
29final class GroupedRow implements Relation
30{
31 /**
32 * @param list<Field|OpenStar> $selected The output fields of the select list, in order
33 * @param list<Field> $grouping The GROUP BY items that are columns, each with the resolution of its column at the HAVING position
34 * @param bool $grouped Whether the query block groups, aggregates or is DISTINCT
35 * @param list<ConditionalColumn> $undecided The GROUP BY items and select list items that are columns of an incompletely known occurrence
36 */
37 public function __construct(public readonly array $selected, public readonly array $grouping, public readonly bool $grouped, public readonly array $undecided = [])
38 {
39 }
40
41 /**
42 * Answers the row without columns the entry contributes.
43 */
44 public function deriveRelation(Derivation $derivation, Environment $environment): RelationFact
45 {
46 return new RelationFact(new RowShape([]));
47 }
48
49 /**
50 * Writes nothing: the entry is not written.
51 */
52 public function render(Output $out): void
53 {
54 }
55}
56