Repository navigation
Conversation
…8 spellings ColDataTypeCorpusTest reads type-corpus.tsv and checks the values ColDataType exposes for each spelling: name, arguments, precision, scale, modifiers, array, character set, interval qualifier, national type, column specs and toString. The MySQL and PostgreSQL rows hold the type spellings of MySQL 8.4 and PostgreSQL 18 in a column definition, and the spelling each server reports for that column (COLUMN_TYPE, format_type) as a type fragment. A few rows cover other dialects. The table records the current behaviour, so a change in how a type is read shows up as changed rows. Signed-off-by: minleejae <mmj9808@gmail.com>
ColDataType gave the spelling of its character set clause twice: getCharacterSetSyntax() names every spelling (CHARACTER SET, CHARSET, ASCII, UNICODE), and isUseCharsetKeyword()/setUseCharsetKeyword() repeated the CHARSET case as a boolean. The boolean pair was added after 5.4 and is not released, so it is removed; the parser and the tests use the enum. Signed-off-by: minleejae <mmj9808@gmail.com>
MySQL takes BYTE where it takes ASCII and UNICODE (opt_charset_with_opt_binary in sql_yacc.yy): CHAR BYTE is CHAR CHARACTER SET binary, which the server stores as binary(1). With the MySQL dialect the parser now reads it as the shorthand CharacterSetSyntax.BYTE, whose character set is binary, as it already does for ASCII and UNICODE. CHAR BYTE was the only spelling of the MySQL 8.4 corpus that did not parse. Signed-off-by: minleejae <mmj9808@gmail.com>
ColDataType gave VARCHAR(10) as the name "VARCHAR (10)" without arguments, but MEDIUMINT(9), YEAR(4), DEC(5), INTERVAL(3) and other names that are not DATA_TYPE tokens as the name "mediumint" with the arguments [9]. Since 5.0 the DataType() production, written for implicit casts, folded the arguments of a DATA_TYPE name into the name; 4.9 read every type as a name and arguments. A caller had to know which path a type took, and CastExpression.isOf() gave UNKNOWN for CAST(x AS VARCHAR(10)) because it compares the name. One production, TypeArguments(), now reads the arguments of every type, and getDataType() is the name alone: - VARCHAR(10) is VARCHAR with [10]. TIMESTAMP(3) WITH TIME ZONE is TIMESTAMP WITH TIME ZONE with [3], and toString() writes the precision after the first word as before. - getPrecision() and getScale() read the arguments, so they agree with them and with toString(). MAX is an argument, not Integer.MAX_VALUE. - The length unit of CHAR(10 BYTE) is kept instead of being dropped. - Arguments are separated by commas, as DataType() required, and * stands only in VECTOR or as the precision of NUMBER. - MySQL's CAST(x AS UNSIGNED ARRAY) keeps ARRAY as the array spelling of the type, as PostgreSQL's INT ARRAY does, instead of a word of the name. Removed, as they read or wrote the folded name or set a precision toString() did not show: getBaseTypeName(), getNumericPrecision(), setNumericPrecision(), isMaxPrecision(), fromNumericParameters(), fromTypeParameters() (added after 5.4), setPrecision(), withPrecision(), setScale(), withScale() (5.4) and ColDataType(String, int, int) (5.0). A type is built with new ColDataType(name).addArgumentsStringList(...). In type-corpus.tsv only getDataType() and the arguments change, except for VARCHAR(MAX) (no precision, MAX as written), CHAR(10 BYTE) (BYTE kept) and VARCHAR2(10 CHAR) (precision 10). Signed-off-by: minleejae <mmj9808@gmail.com>
ColDataType kept MySQL's numeric modifiers twice: getTypeModifiers() in the order written, and signedness and ZEROFILL fields beside it. setSignedness() and setZerofill() changed the fields but not the list, and toString() writes the list, so INT(11) UNSIGNED with setSignedness(SIGNED) answered SIGNED and printed UNSIGNED. getSignedness() and isZerofill() now read the list: the last of SIGNED and UNSIGNED, and whether ZEROFILL is in it. setSignedness(), withSignedness(), setZerofill() and withZerofill() are removed, along with isNational(), which repeated getNationalCharacterType() != null. All five came with 5.4 and have no caller in the parser or the tests. Signed-off-by: minleejae <mmj9808@gmail.com>
Three constructors took the type as a string and stored it whole as the name of a ColDataType, so new CastExpression(a, "VARCHAR(10)") had the name "VARCHAR(10)" with no arguments, unlike a parsed CAST. CastExpression(String keyword, Expression, String) and CastExpression(Expression, String) now take a ColDataType, and CastExpression(String dataType, String value) is removed in favour of CastExpression(ColDataType, String). None of them had a caller in the parser or the tests. Signed-off-by: minleejae <mmj9808@gmail.com>
usage.rst gets a "Column data types" section: the accessor for each part of a ColDataType, an example, and a table from the API this branch removes or changes to its replacement. The paragraph on negative scales builds the type with its arguments instead of the removed factory and constructor. Signed-off-by: minleejae <mmj9808@gmail.com>
This branch has not been deployed
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.
ColDataTyperead some types as a name with arguments and folded the arguments of others into the name.MEDIUMINT(9)had the namemediumintand the arguments[9], whileVARCHAR(10)had the nameVARCHAR (10)and no arguments. The difference comes from 5.0, when theDataType()production for implicit casts started to read column types as well; 4.9 read both as a name and arguments. A caller had to strip the name itself, andCastExpression.isOf()returnedUNKNOWNforCAST(x AS VARCHAR(10)). Some accessors also gave the same information twice, and some setters changed a value thattoString()did not show.This PR reads the arguments of every type in one production and keeps one accessor for each part of a type. The duplicate API is removed rather than deprecated.
What changes
getDataType()returns only the name, andgetArgumentsStringList()returns the arguments as written.VARCHAR(10)isVARCHARwith[10], andTIMESTAMP(3) WITH TIME ZONEisTIMESTAMP WITH TIME ZONEwith[3].toString()output is unchanged.getPrecision()andgetScale()are read from the arguments.MAX,*and numbers outside theintrange returnnulland stay in the argument list.getSignedness()andisZerofill()are read fromgetTypeModifiers().CHAR(10 BYTE)keepsBYTE, MySQL'sCHAR BYTEis read as thebinarycharacter set, and MySQL'sCAST(x AS UNSIGNED ARRAY)is an array ofUNSIGNEDinstead of a type namedUNSIGNED ARRAY.CastExpressionconstructors take the type as aColDataTypeinstead of a string.API changes
getBaseTypeName(),getNumericPrecision(),setNumericPrecision(),isMaxPrecision(),fromNumericParameters(),fromTypeParameters(),isUseCharsetKeyword(),setUseCharsetKeyword()(added after 5.4)getDataType(),getArgumentsStringList(),getPrecision(),getCharacterSetSyntax()setPrecision(),withPrecision(),setScale(),withScale()(5.4)setArgumentsStringList()setSignedness(),withSignedness(),setZerofill(),withZerofill(),isNational()(5.4)setTypeModifiers(),addTypeModifier(),getNationalCharacterType()ColDataType(String, int, int)(5.0)new ColDataType(name).addArgumentsStringList(...)CastExpressionconstructors with a type stringColDataTypeCode written against 5.0–5.4 that expects
getDataType()to returnVARCHAR (10)will need to change.usage.rsthas a migration table. If these changes should wait for a major release, the first three commits don't change any released API and can be merged on their own.Validation
type-corpus.tsvrecords whatColDataTypereturns for MySQL 8.4 and PostgreSQL 18 type spellings, the spellings the servers return for the same columns (COLUMN_TYPEandformat_type), and a few spellings from other dialects. In the name and argument commit, only the name and arguments change, except forMAXarguments,CHAR(10 BYTE)andVARCHAR2(10 CHAR). All 343 rows now parse; before this PR,CHAR BYTEwas the only failure.gradle checkandcheckGrammarAmbiguity. The last commit ran 19,130 tests with 0 failures and no grammar choice conflicts.spotlessJavaCheckandspotlessMiscCheckreportCCJSqlParserTest.javaandCHANGELOG.md, which fail the same way onmaster.Prepared with Claude Code.