Skip to content

feat(parser): model ColDataType precision and scale as structured properties - #2539

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/coldatatype-structured-precision-scale
Sep 4, 2026
Merged

feat(parser): model ColDataType precision and scale as structured properties#2539
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/coldatatype-structured-precision-scale

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

Summary

  • add structured precision and scale state to ColDataType, populated on every grammar path
  • keep getDataType(), toString(), equals() and hashCode() unchanged, so deparsing and existing consumers are unaffected

ColDataType currently exposes type parameters in three different shapes depending on which grammar path produced it:

SQL getDataType() getArgumentsStringList()
VARCHAR(255) "VARCHAR (255)" null
MEDIUMINT(9) "MEDIUMINT" ["9"]
TIMESTAMP(3) WITH TIME ZONE "TIMESTAMP(3) WITH TIME ZONE" null

Keyword types fold the parameters into the type string (inserting a space), identifier types keep them in the arguments list, and zoned types embed them in the lexer token image. A consumer that needs the precision has to regex the string, with a different pattern per shape. The new accessors return the parameters uniformly:

VARCHAR(255)                -> precision=255  scale=null
DECIMAL(10, 2)              -> precision=10   scale=2
mediumint(9)                -> precision=9    scale=null
TIMESTAMP(3) WITH TIME ZONE -> precision=3    scale=null
ENUM('x', 'y')              -> precision=null scale=null   (non-numeric arguments)
VARCHAR(MAX)                -> precision=Integer.MAX_VALUE

The string-based behavior stays untouched for compatibility. The hand-built expected object trees in DeclareStatementTest were extended with the new state, since assertEqualsObjectTree compares all fields reflectively.

Testing

  • ./gradlew check passes (checkstyle, PMD, spotless, spotbugs, JaCoCo)
  • Full test suite: 5059 tests, 0 failures, 0 errors
  • JavaCC reports 0 errors and 11 warnings, identical to master — no new choice conflicts
  • New tests in ColDataTypeTest pin getPrecision() / getScale() for the three shapes above, plus the no-parameter, DECIMAL(10, 2), VARCHAR(MAX) and ENUM(...) cases

AI assistance

AI tooling assisted with the implementation and test coverage. The changes were manually reviewed and verified against MySQL and PostgreSQL syntax.

…perties

ColDataType exposed type parameters in three different shapes depending on
the grammar path: keyword types fold them into the dataType string
("VARCHAR (255)"), identifier types keep them in argumentsStringList
(mediumint(9) -> ["9"]), and zoned types embed them in the lexer token
image ("TIMESTAMP(3) WITH TIME ZONE"). A consumer that needs the precision
has to re-parse the string, with a different pattern per shape.

Populate structured precision and scale on all three paths. The rendered
dataType string, toString(), equals() and hashCode() are unchanged; the
hand-built object trees in DeclareStatementTest gain the new state.
@manticore-projects
manticore-projects merged commit c919a0c into JSQLParser:master Sep 4, 2026
7 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants