Repository navigation
fix(jdbc): resolve table metadata for aliases, joins, subqueries, RETURNING, and views - #70
Merged
Merged
Conversation
Resolve the origin table of each result column from the statement shape instead of assuming a single simple FROM target. Aliases keep the origin table and follow xerial's nullability rule: a label that is not a column of the origin table reports columnNullable. Expressions and literals remain unresolved and report an empty table name with columnNullableUnknown.
Assert per-column origins and nullability for explicit and comma joins, source aliases, and star expansion across joined tables.
Assert origins for FROM subqueries, scalar subqueries, common table expressions, and the leftmost branch of a compound SELECT.
Assert INSERT, UPDATE, and DELETE RETURNING columns resolve to the target table, including aliased RETURNING columns.
Assert a view reports its base table, including aliased view columns, matching xerial 3.53.4.0.
magnusp
force-pushed
the
fix/37-table-metadata
branch
from
October 21, 2026 22:57
b1a2e90 to
1f3bf6f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #37. Part of #54.
What changed
FROMparser inSqlTableReferencewith a resolver thatreturns an origin table for every result column position. It handles simple
selects, aliases, explicit and comma joins, FROM subqueries, scalar
subqueries, CTEs, the leftmost branch of a compound SELECT,
INSERT/UPDATE/DELETE ... RETURNING, and views.column, including nested views and explicit view column lists.
LibsqlResultSetMetaDatanow keeps a per-column origin table instead of onetable context.
getTableName,isNullable, andisAutoIncrementread thatcolumn's origin and load each distinct table or view once.
pragma_table_infocolumn order so*expansion and view columns keep their declared order.
SqlTableReferenceclass Javadoc.
an aliased RETURNING column), and view. Pinned the unsupported expression and
literal shapes to an empty table name and
columnNullableUnknown.Contract decision
Match xerial 3.53.4.0.
getTableNamereports the origin table that SQLite'ssqlite3_column_table_namewould report, so aliases, joins, subqueries,RETURNING, and views all keep their base table. A view reports its base table,
not the view name. Nullability follows xerial's rule: look up the result label
in the origin table and report
columnNoNulls/columnNullable; an aliaswhose label is not a column of the origin table is
columnNullable.getTableNameno longer requires the output label to be a column of theresolved table. That requirement was why
select a as z from wreturned"".Evidence
Failing before the fix (new tests on unmodified
origin/main):Passing after the fix:
Includes the vendored xerial
RSMetaDataTest(13 tests) against live sqld.I also ran a temporary live-sqld probe (removed before committing) asserting
getTableNameandisNullablefor alias, join, subquery, CTE, UNION,RETURNING, view, aliased view column, and expression shapes. All matched the
expected xerial values.
Deviations
Supported shapes match xerial 3.53.4.0.
For unsupported shapes (expressions and literals) this driver reports
getTableName == ""andisNullable == columnNullableUnknown. xerial reportsthe same empty table name but
columnNullablefor those columns because ittreats missing SQLite column metadata as nullable. The issue explicitly asks
unsupported shapes to return documented empty or unknown values, and an
expression has no table column whose nullability could be known, so this PR
keeps the honest unknown value.