Skip to content

Read a numeric column's length as its total digits, fixes #8216Read a numeric column's length as its total digits, fixes #8216 - #8242

Open
fskorgen wants to merge 1 commit into
apache:mainfrom
fskorgen:fix/decimal-length-ddl
Open

Read a numeric column's length as its total digits, fixes #8216Read a numeric column's length as its total digits, fixes #8216#8242
fskorgen wants to merge 1 commit into
apache:mainfrom
fskorgen:fix/decimal-length-ddl

Conversation

@fskorgen

@fskorgen fskorgen commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

numericLength() took the scale off the precision the database reports, so decimal(5,2) arrived as Hop length 3. Every getFieldDefinition writes a scaled column as DECIMAL(length, precision), and a length typed into a transform dialog means the same total — so the length read off a column matched neither. A table re-created from a read stopped round-tripping: decimal(24,15) becomes DECIMAL(9,15), which SQL Server refuses, and decimal(5,2) becomes DECIMAL(3,2), which is valid DDL that then rejects valid data.

The subtraction is kept as integerDigits() for the two rules that test whether a declaration is possible at all, so no dialect rule changes behaviour. Oracle's two require scale <= 0, where it never applied.

JdbcTypeMappingCharacterizationTest: 63 diverging lines become 16, and the live path now agrees with the legacy mapper on every numeric case. New MsSqlServerNumericRoundTripTest fails without this change with expected: <DECIMAL(5,2)> but was: <DECIMAL(3,2)>.

Fixes #8216


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Run mvn clean install apache-rat:check to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If you have a group of commits related to the same change, please squash your commits into one and force push your branch using git rebase -i.
  • Mention the appropriate issue in your description (for example: addresses #123), if applicable.

To make clear that you license your contribution under the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@mattcasters

Copy link
Copy Markdown
Contributor

Thanks for the investigation — the round-trip failure is real (#8216).

This PR cannot land as written against current main. numericLength() is documented as digits before the decimal and dialect rules already depend on that (MySQL overscaled DOUBLE, PostgreSQL DOUBLE/NUMERIC, Oracle NUMBER(38)). Redefining it to JDBC precision would change those conditions.

#8216 is fixed in mattcasters/hop#issue-8218 / the follow-up PR on apache/hop by:

  • keeping numericLength() as integer digits for rule conditions
  • storing JDBC precision as Hop Number length (totalDigits())
  • changing PostgreSQL write from NUMERIC(length + scale, scale) to NUMERIC(length, scale) so it does not inflate once length is total digits again

Please close this PR in favour of that one once it is up.

@mattcasters

Copy link
Copy Markdown
Contributor

The replacement is #8244

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DECIMAL read metadata is incompatible with DDL generation in 2.19 (regression)

2 participants