classColumnResolver
final class ColumnResolver
Resolves a column name the way SQLite does.
Rule: SQLITE-COLUMN-LOOKUP-001. The lookup starts at the innermost query and moves outwards one query at a time. In a query, every input relation the qualifier admits is asked for the name; a relation answers with its first column of that name, an unqualified name skips the columns a USING or NATURAL join merged away, and a relation without such a column answers with its implicit column of that name. One answer resolves the name, more than one makes it ambiguous. With no answer, an unqualified name that is a result column alias of the query denotes that result column. A relation whose columns are not all known (an undeclared table, or a column of a subquery whose name follows an unexpanded star or is picked at random) that does not answer makes the outcome conditional on what is missing: the inputs of its open shape and those its unnamed columns depend on (LookupLevel::undecided()), or else the random name. A relation whose hidden list holds QUALIFIED_ONLY is reachable with a qualifier only (NEW, OLD, excluded). An environment that holds nothing but common tables is no query level. Terminates: the scopes form a finite chain. Source: https://sqlite.org/lang_expr.html#column_names, https://sqlite.org/lang_select.html. Status: Implemented.
Constants§
public const QUALIFIED_ONLY = -1The hidden-list entry that marks a relation as reachable with a qualifier only.
Methods§
public function find(
Environment $environment,
Name $column,
?QualifiedName $qualifier = null,
): ResolutionResolves a column name at a position.
Parameters
$environment | Environment | |
$column | Name | |
$qualifier | ?QualifiedName |
Returns
Test cases 5
ColumnResolverTest::testFindIsConditionalWhenAnOpenRelationMayHoldTheNamecallsColumnResolverTest::testFindPrefersARelationColumnOverAnAliasAndAnAliasOverOuterScopescallsColumnResolverTest::testFindReportsAmbiguityAndHonoursHiddenAndQualifiedOnlyRelationscallsColumnResolverTest::testFindResolvesUnqualifiedQualifiedAndImplicitNamescallsColumnResolverTest::testMatchAnswersTheInputsTheNameOfAnUnnamedColumnDependsOncalls
Called from 7
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\GeneratedWrites::supplied() packages/sql-semantics-sqlite/src/Rules/Mutation/GeneratedWrites.php:173
- method-call SqlSemantics\Platform\Sqlite\Rules\Resolution\ColumnFacts::denoted() packages/sql-semantics-sqlite/src/Rules/Resolution/ColumnFacts.php:73
- method-call SqlSemantics\Platform\Sqlite\Rules\Resolution\ColumnFacts::denoted() packages/sql-semantics-sqlite/src/Rules/Resolution/ColumnFacts.php:78
- method-call SqlSemantics\Platform\Sqlite\Statement\Expression\ColumnUse::deriveScalar() packages/sql-semantics-sqlite/src/Statement/Expression/ColumnUse.php:53
- method-call SqlSemantics\Platform\Sqlite\Statement\Expression\DoubleQuotedWord::deriveScalar() packages/sql-semantics-sqlite/src/Statement/Expression/DoubleQuotedWord.php:58
- method-call SqlSemantics\Platform\Sqlite\Statement\Expression\TruthWord::deriveScalar() packages/sql-semantics-sqlite/src/Statement/Expression/TruthWord.php:52
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\LiteralColumn::deriveScalar() packages/sql-semantics-sqlite/src/Statement/Schema/LiteralColumn.php:67
Calls 8
- method-call ColumnResolver::admits() line 64
- method-call ColumnResolver::match() line 67
- function-call
array_pushline 72 - new ConditionalColumn line 78
- function-call
countline 81 - new AmbiguousColumn line 81
- new AliasTarget line 84
- new MissingColumn line 91
public function admits(
Environment $scope,
VisibleRelation $relation,
?QualifiedName $qualifier,
): boolTells whether a qualifier admits a relation; no qualifier admits every relation that is not reachable by qualifier only.
Parameters
$scope | Environment | |
$relation | VisibleRelation | |
$qualifier | ?QualifiedName |
Returns
boolCalled from 2
Calls 2
- function-call
in_arrayline 100 - class-const ColumnResolver::QUALIFIED_ONLY() line 100
public function match(
Environment $scope,
VisibleRelation $relation,
Name $column,
bool $merged,
int $depth,
): ResolvedColumn|list<MissingInput>Asks one relation for a column: the column found, or the inputs whose absence leaves the answer open (none when the relation certainly has no such column).
Parameters
$scope | Environment | |
$relation | VisibleRelation | |
$column | Name | |
$merged | bool | |
$depth | int |
Returns
ResolvedColumn|list<MissingInput>Test cases 2
Called from 1
Calls 4
- function-call
in_arrayline 126 - new ResolvedColumn line 127
- static-call LookupLevel::undecided() line 138
- new RandomColumnName line 140
Test cases 11§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
ColumnResolverTest::testAdmitsMatchesTheAliasOrTheNameWithAnOptionalSchemacallsColumnResolverTest::testFindIsConditionalWhenAnOpenRelationMayHoldTheNamecallsColumnResolverTest::testFindPrefersARelationColumnOverAnAliasAndAnAliasOverOuterScopescallsColumnResolverTest::testFindReportsAmbiguityAndHonoursHiddenAndQualifiedOnlyRelationscallsColumnResolverTest::testFindResolvesUnqualifiedQualifiedAndImplicitNamescallsColumnResolverTest::testMatchAnswersTheInputsTheNameOfAnUnnamedColumnDependsOncallsColumnResolverTest::testMatchFindsSlotsOrImplicitNamesAndOtherwiseAnswersTheMissingInputscallsColumnResolverTest::testQualifiedOnlyIsAPositionNoSlotCanHavecalls
Other tests reaching this symbol 3
Relations§
Instantiated in 8
- new SqlSemantics\Platform\Sqlite\Rules\Mutation\GeneratedWrites::supplied() packages/sql-semantics-sqlite/src/Rules/Mutation/GeneratedWrites.php:173
- new SqlSemantics\Platform\Sqlite\Rules\Query\Projection::items() packages/sql-semantics-sqlite/src/Rules/Query/Projection.php:71
- new SqlSemantics\Platform\Sqlite\Rules\Resolution\ColumnFacts::denoted() packages/sql-semantics-sqlite/src/Rules/Resolution/ColumnFacts.php:73
- new SqlSemantics\Platform\Sqlite\Rules\Resolution\ColumnFacts::denoted() packages/sql-semantics-sqlite/src/Rules/Resolution/ColumnFacts.php:78
- new SqlSemantics\Platform\Sqlite\Statement\Expression\ColumnUse::deriveScalar() packages/sql-semantics-sqlite/src/Statement/Expression/ColumnUse.php:53
- new SqlSemantics\Platform\Sqlite\Statement\Expression\DoubleQuotedWord::deriveScalar() packages/sql-semantics-sqlite/src/Statement/Expression/DoubleQuotedWord.php:58
- new SqlSemantics\Platform\Sqlite\Statement\Expression\TruthWord::deriveScalar() packages/sql-semantics-sqlite/src/Statement/Expression/TruthWord.php:52
- new SqlSemantics\Platform\Sqlite\Statement\Schema\LiteralColumn::deriveScalar() packages/sql-semantics-sqlite/src/Statement/Schema/LiteralColumn.php:67
Method calls 8
- method-call SqlSemantics\Platform\Sqlite\Rules\Mutation\GeneratedWrites::supplied() packages/sql-semantics-sqlite/src/Rules/Mutation/GeneratedWrites.php:173
- method-call SqlSemantics\Platform\Sqlite\Rules\Query\Projection::items() packages/sql-semantics-sqlite/src/Rules/Query/Projection.php:71
- method-call SqlSemantics\Platform\Sqlite\Rules\Resolution\ColumnFacts::denoted() packages/sql-semantics-sqlite/src/Rules/Resolution/ColumnFacts.php:73
- method-call SqlSemantics\Platform\Sqlite\Rules\Resolution\ColumnFacts::denoted() packages/sql-semantics-sqlite/src/Rules/Resolution/ColumnFacts.php:78
- method-call SqlSemantics\Platform\Sqlite\Statement\Expression\ColumnUse::deriveScalar() packages/sql-semantics-sqlite/src/Statement/Expression/ColumnUse.php:53
- method-call SqlSemantics\Platform\Sqlite\Statement\Expression\DoubleQuotedWord::deriveScalar() packages/sql-semantics-sqlite/src/Statement/Expression/DoubleQuotedWord.php:58
- method-call SqlSemantics\Platform\Sqlite\Statement\Expression\TruthWord::deriveScalar() packages/sql-semantics-sqlite/src/Statement/Expression/TruthWord.php:52
- method-call SqlSemantics\Platform\Sqlite\Statement\Schema\LiteralColumn::deriveScalar() packages/sql-semantics-sqlite/src/Statement/Schema/LiteralColumn.php:67
Constant reads 6
- class-const SqlSemantics\Platform\Sqlite\Rules\Mutation\InsertFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/InsertFacts.php:69
- class-const SqlSemantics\Platform\Sqlite\Rules\Mutation\TriggerFacts::derive() packages/sql-semantics-sqlite/src/Rules/Mutation/TriggerFacts.php:61
- class-const SqlSemantics\Platform\Sqlite\Rules\Resolution\FromScope::nested() packages/sql-semantics-sqlite/src/Rules/Resolution/FromScope.php:117
- class-const SqlSemantics\Platform\Sqlite\Rules\Resolution\FromScope::nested() packages/sql-semantics-sqlite/src/Rules/Resolution/FromScope.php:122
- class-const SqlSemantics\Platform\Sqlite\Rules\Resolution\FromScope::star() packages/sql-semantics-sqlite/src/Rules/Resolution/FromScope.php:138
- class-const SqlSemantics\Platform\Sqlite\Rules\Resolution\Joining::locate() packages/sql-semantics-sqlite/src/Rules/Resolution/Joining.php:113