Skip to content

Split SqlTableReference.Parser into focused units #206

Closed

Description

@magnusp

Goal

Split SqlTableReference.Parser into focused units. One 789-line inner class currently mixes token navigation, SQL grammar, schema binding, and I/O, and parseSource alone is 144 lines.

Depends on

#195. The parser warms the metadata cache during parsing, so pin the attached-schema path first.

Pin

SqlTableReferenceTest has 34 cases covering star expansion, USING and NATURAL, joins, aliases, quoted and non-ASCII names, CTEs, views, RETURNING, and rejected input. LibsqlResultSetMetaDataTest covers the integration path.

Scope

  • Add SqlCursor over the token list and depth, replacing the repeated bounds guards.
  • Extract FromClauseParser (sources, joins, INDEXED, USING, star list).
  • Extract SelectItemParser (items, aliases, star expansion, expression labels).
  • Extract TableBinding (CTE, view, and definition to Source construction).
  • Replace the parallel labels and tables lists with one result builder that enforces the pairing.

Preserve

  • Schema.definition is called during parsing, once per source occurrence, in source order, and its SQLException propagates.
  • The view cycle guard stays add before recurse and remove in finally, keyed by schema plus lower-cased table.
  • CREATE VIEW is tokenized twice today. That fixes the explicit column list.
  • The token depth convention stays as is. ( carries pre-increment depth and ) post-decrement.
  • The column-count width guard stays where it is relative to caching.
  • targetTable remains AS-only and lenient about a third dotted part.

Acceptance

  • All four new units exist, and SqlTableReference.java is under 450 lines.
  • ./mvnw -pl libsql-jdbc -am test green with no assertion edited.
  • ./mvnw -pl libsql-conformance -am verify green.
  • ./mvnw spotless:check green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal priority: edge case, feature gap, or test/process improvement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions