Repository navigation
refactor(jdbc): share one SqlTokenizer across metadata parsers - #154
Merged
Merged
Conversation
Move the two copies of tokenize, skipQuoted, unescape, and isWordChar into SqlTokenizer, whose Token carries type, depth, and literal kind. Both SqlTableReference and the LibsqlResultSetMetaData CREATE TABLE scanner now use it, and the duplicated matchingParen, identifiers, and indexOfWord helpers are gone. Tokenizer semantics are unchanged, so parser output and auto-increment detection are unaffected.
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.
Fixes #111
Contract. Hrana 3 is the source of truth for transport, values, metadata, batching, transactions, and error reporting; the parser here only decides JDBC origin and nullability, which the protocol does not supply.
java.sqlis the source of truth for the JDBC surface. xerial/sqlite-jdbc is the behavioral reference for which columns are auto-increment, and this PR preserves that behavior rather than changing it.Change
One
SqlTokenizernow owns tokenization for both local SQL scanners:Tokencarries a type (WORD,IDENT,LITERAL,SYMBOL), the enclosing parenthesis depth, and aLiteralKind(NONE,STRING,BLOB), as the plan requires.tokenize,matchingParen,identifiers,indexOfWord,indexOfAnyWord,indexOfSymbol,isWordAt,isSymbolAt,wordAt,identifierAt, andupper.SqlTableReferenceuses it from the table-reference parser and view resolution. The duplicatematchingParen/matchingParenIn,identifiers/identifiersIn, andindexOfWord/indexOfWordInpairs are deleted, and so are itstokenize,scanQuoted,unescape,isWordChar,Type,Token, andUNQUOTED_IDENTIFIER.LibsqlResultSetMetaDatauses it from the CREATE TABLE scanner. ItsTokenType,Token,tokenize,skipQuoted,unescape,isWordChar,isWord,isSymbol, andidentifiercopies are deleted.SqlTableReference.javagoes from 1284 to 998 lines.Red and green
The plan's Build box says behavior-preserving with no parser semantics change, and its Verify, unit box says no new behavior tests. So there is no meaningful red case: a refactor keeps every existing assertion green on both sides.
Trunk
fdf3a0cand headfc663a0both report the same parser and metadata suites:Green is the equality gate: the full-module surefire case list is identical at both SHAs (307 cases, lane 9 diff empty).
Lanes (all at head
fc663a0, basefdf3a0c)./mvnw -pl libsql-jdbc test -Dtest='SqlTableReferenceTest,LibsqlResultSetMetaDataTest'at trunk and head/tmp/xerial-parity-i111/lane-1-regression.logtokenize|skipQuoted|isWordCharunderlibsql-jdbc/src/main/tmp/xerial-parity-i111/lane-2-specific.log./mvnw -pl libsql-jdbc test/tmp/xerial-parity-i111/lane-3-specific.log./mvnw -pl libsql-jdbc test/tmp/xerial-parity-i111/lane-4-module-suite.log./mvnw -pl libsql-conformance -am verify/tmp/xerial-parity-i111/lane-5-conformance.log./mvnw -pl libsql-conformance -am -Pxerial-control verify/tmp/xerial-parity-i111/lane-6-control.log./mvnw spotless:check/tmp/xerial-parity-i111/lane-7-spotless.log./mvnw test/tmp/xerial-parity-i111/lane-8-reactor.log/tmp/xerial-parity-i111/lane-9-specific.log./mvnw -pl libsql-jdbc -am package -DskipTests/tmp/xerial-parity-i111/lane-10-package.loglibsql-itestswas not run. This PR touches no transport, connection, or container behavior.Perf
Metric: wall clock of
./mvnw -q -pl libsql-jdbc test, three runs per side, interleaved head/trunk.fdf3a0cfc663a0Head median is +0.97% against the trunk baseline, inside the 10% rule. The one 4064 ms head run is the first run of the sequence and a warm-up outlier; trunk is always second in each pair, so the median is the comparable number. Log:
/tmp/xerial-parity-i111/perf-times.txt.Divergences
LibsqlStatement.javakeeps a thirdskipQuotedfor statement splitting, andLibsqlPreparedStatement.javakeeps atokenize/skipQuotedpair for result-set detection. Both files are outside the plan's Files block, and neither scanner is the near-identical copy Share one SQL tokenizer between SqlTableReference and LibsqlResultSetMetaData #111 names: one splits statements, the other only reads top-level keywords. Migrating them needs a separate PR and a plan change.LITERALtokens where its private tokenizer dropped them, andX'..'is oneBLOBliteral where it used to beWORD xplus a dropped string. The CREATE TABLE scanner only inspectsWORDandSYMBOLtokens at identifier and separator positions, and the full suite is unchanged.UNQUOTED_IDENTIFIERrule. The private copy accepted anyWORD. The only rejected shapes are unquoted tokens that are not valid SQLite identifiers (leading digit,$, and similar), which the CREATE TABLE scanner never receives as a column name.SqlTableReference.javais 998 lines, down 286 from trunk.