classUnification
final class Unification
Resolves the common type of values that UNION, CASE, ARRAY, VALUES, IN and the conditional functions combine.
Rule: PG-UNIFICATION-001. An invalid input makes the result invalid; an input of a type that depends on missing declarations makes it depend on them. Values of one type keep it, modifiers included. When every input is of the pseudo-type unknown (a string constant or NULL), the result is text. Otherwise unknown inputs are ignored; the other inputs must share a category (PG-TYPE-CATEGORY-001), else the types cannot be matched. The first input is the candidate; each later input replaces it when the candidate converts to it implicitly but not back, unless the candidate is the preferred type of the category. Every input must then convert to the candidate implicitly. A type outside the category tables matches only itself. Minimum precision: Known for the catalog types of the tables. Termination: one pass over the inputs. Source: https://www.postgresql.org/docs/17/typeconv-union-case.html. Status: Implemented.
Methods§
public function resolve(
AnalysisContext $context,
list<TypeFact> $types,
string $construct = 'UNION',
): TypeFactAnswers the common type of the inputs; a conflict is an Invalid fact the caller reports.
Parameters
$context | AnalysisContext | |
$types | list<TypeFact> | The input types in order; at least one |
$construct | string | The construct that combines them, for the conflict message |
Returns
Test cases 3
Called from 8
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\ArrayTyping::items() packages/sql-semantics-postgres/src/Rules/Expression/Typing/ArrayTyping.php:51
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\CaseTyping::derive() packages/sql-semantics-postgres/src/Rules/Expression/Typing/CaseTyping.php:57
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\CommonTableFacts::mark() packages/sql-semantics-postgres/src/Rules/Query/Facts/CommonTableFacts.php:212
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SetOperationFacts::combined() packages/sql-semantics-postgres/src/Rules/Query/Facts/SetOperationFacts.php:79
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\ValuesFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/ValuesFacts.php:56
- method-call SqlSemantics\Platform\PostgreSql\Rules\Resolution\Joining::merged() packages/sql-semantics-postgres/src/Rules/Resolution/Joining.php:168
- method-call SqlSemantics\Platform\PostgreSql\Statement\Invocation\Conditional\Coalesce::deriveScalar() packages/sql-semantics-postgres/src/Statement/Invocation/Conditional/Coalesce.php:71
- method-call SqlSemantics\Platform\PostgreSql\Statement\Invocation\Conditional\MinMax::deriveScalar() packages/sql-semantics-postgres/src/Statement/Invocation/Conditional/MinMax.php:71
Calls 7
- function-call
array_pushline 55 - class-const Builtin::Unknown() line 56
- new Dependent line 61
- method-call Unification::distinct() line 61
- new Known line 64
- class-const Builtin::Text() line 64
- method-call Unification::candidate() line 67
Selects the candidate among inputs of known types.
Parameters
$types | non-empty-list<Known> | |
$construct | string |
Returns
Test cases 1
Called from 1
Calls 8
- new Categories line 85
- method-call Categories::builtin() line 86
- method-call Categories::category() line 89
- new Invalid line 90
- new TypeConflict line 90
- method-call Categories::preferred() line 92
- method-call Categories::implicit() line 92
- new Known line 103
public function nullability(list<Nullability> $values): NullabilityAnswers whether a value combined from inputs can be NULL: when any can; dependent when any is and none can.
Parameters
$values | list<Nullability> |
Returns
Test cases 1
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SetOperationFacts::combined() packages/sql-semantics-postgres/src/Rules/Query/Facts/SetOperationFacts.php:83
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\ValuesFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/ValuesFacts.php:60
- method-call SqlSemantics\Platform\PostgreSql\Rules\Resolution\Joining::merged() packages/sql-semantics-postgres/src/Rules/Resolution/Joining.php:173
Calls 1
- class-const Nullability::NotNull() line 113
public function distinct(non-empty-list<MissingInput> $missing): non-empty-list<MissingInput>Removes repeated missing inputs, keeping the first of equal ones.
Parameters
$missing | non-empty-list<MissingInput> |
Returns
non-empty-list<MissingInput>Test cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\OperatorTyping::both() packages/sql-semantics-postgres/src/Rules/Expression/Typing/OperatorTyping.php:223
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Unification::resolve() packages/sql-semantics-postgres/src/Rules/Expression/Unification.php:61
Calls 1
- function-call
array_valuesline 135
Test cases 6§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 6
UnificationTest::testCandidateReportsDifferentCategoriescallsUnificationTest::testDistinctRemovesRepeatedInputscallsUnificationTest::testNullabilityIsNullableWhenAnyInputIscallsUnificationTest::testResolveDependsOnMissingInputscallsUnificationTest::testResolveGivesTextForUnknownInputscallsUnificationTest::testResolvePromotesWithinACategorycalls
Relations§
Instantiated in 10
- new SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\ArrayTyping::items() packages/sql-semantics-postgres/src/Rules/Expression/Typing/ArrayTyping.php:51
- new SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\CaseTyping::derive() packages/sql-semantics-postgres/src/Rules/Expression/Typing/CaseTyping.php:57
- new SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\OperatorTyping::both() packages/sql-semantics-postgres/src/Rules/Expression/Typing/OperatorTyping.php:223
- new SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\CommonTableFacts::mark() packages/sql-semantics-postgres/src/Rules/Query/Facts/CommonTableFacts.php:212
- new SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SetOperationFacts::combined() packages/sql-semantics-postgres/src/Rules/Query/Facts/SetOperationFacts.php:75
- new SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\ValuesFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/ValuesFacts.php:52
- new SqlSemantics\Platform\PostgreSql\Rules\Resolution\Joining::merged() packages/sql-semantics-postgres/src/Rules/Resolution/Joining.php:168
- new SqlSemantics\Platform\PostgreSql\Rules\Resolution\Joining::merged() packages/sql-semantics-postgres/src/Rules/Resolution/Joining.php:173
- new SqlSemantics\Platform\PostgreSql\Statement\Invocation\Conditional\Coalesce::deriveScalar() packages/sql-semantics-postgres/src/Statement/Invocation/Conditional/Coalesce.php:71
- new SqlSemantics\Platform\PostgreSql\Statement\Invocation\Conditional\MinMax::deriveScalar() packages/sql-semantics-postgres/src/Statement/Invocation/Conditional/MinMax.php:71
Method calls 12
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\ArrayTyping::items() packages/sql-semantics-postgres/src/Rules/Expression/Typing/ArrayTyping.php:51
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\CaseTyping::derive() packages/sql-semantics-postgres/src/Rules/Expression/Typing/CaseTyping.php:57
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\OperatorTyping::both() packages/sql-semantics-postgres/src/Rules/Expression/Typing/OperatorTyping.php:223
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\CommonTableFacts::mark() packages/sql-semantics-postgres/src/Rules/Query/Facts/CommonTableFacts.php:212
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SetOperationFacts::combined() packages/sql-semantics-postgres/src/Rules/Query/Facts/SetOperationFacts.php:79
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SetOperationFacts::combined() packages/sql-semantics-postgres/src/Rules/Query/Facts/SetOperationFacts.php:83
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\ValuesFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/ValuesFacts.php:56
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\ValuesFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/ValuesFacts.php:60
- method-call SqlSemantics\Platform\PostgreSql\Rules\Resolution\Joining::merged() packages/sql-semantics-postgres/src/Rules/Resolution/Joining.php:168
- method-call SqlSemantics\Platform\PostgreSql\Rules\Resolution\Joining::merged() packages/sql-semantics-postgres/src/Rules/Resolution/Joining.php:173
- method-call SqlSemantics\Platform\PostgreSql\Statement\Invocation\Conditional\Coalesce::deriveScalar() packages/sql-semantics-postgres/src/Statement/Invocation/Conditional/Coalesce.php:71
- method-call SqlSemantics\Platform\PostgreSql\Statement\Invocation\Conditional\MinMax::deriveScalar() packages/sql-semantics-postgres/src/Statement/Invocation/Conditional/MinMax.php:71