Skip to content

[CALCITE-6654] NUMERIC/DECIMAL columns without explicit precision should not throw \"DECIMAL precision 0 must be between 1 and 19#4872

Open
mmoradi0101 wants to merge 2 commits intoapache:mainfrom
mmoradi0101:fix/calcite-6654-decimal-precision
Open

[CALCITE-6654] NUMERIC/DECIMAL columns without explicit precision should not throw \"DECIMAL precision 0 must be between 1 and 19#4872
mmoradi0101 wants to merge 2 commits intoapache:mainfrom
mmoradi0101:fix/calcite-6654-decimal-precision

Conversation

@mmoradi0101
Copy link
Copy Markdown

Jira Link

CALCITE-6654

Changes Proposed

JdbcSchema.sqlType() threw an IllegalArgumentException when a column
was declared without explicit precision. Oracle reports precision=0 and
scale=-127 for such columns (e.g. NUMBER), PostgreSQL and MSSQL report
precision=0 and scale=0 (e.g. NUMERIC, DECIMAL).

Treat precision=0 (and Oracle's scale=-127) as "no precision
specified" and fall back to the plain SQL type instead of throwing.

Testing

Added JdbcSchemaDecimalBugTest with 4 integration tests covering Oracle,
PostgreSQL, MSSQL, and a regression test for explicit DECIMAL(10,2).

Comment thread core/build.gradle.kts Outdated
}
}

private static boolean isAffectedTypeForMissingPrecision(SqlTypeName sqlTypeName) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function looks like overkill.
Do you expect it will need to cover other cases too?
I would just inline the function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the condition is now just sqlTypeName == SqlTypeName.DECIMAL directly at the call site.

} else if (precision >= 0 && sqlTypeName.allowsPrecNoScale()) {

// Fix for CALCITE-6654:
// Oracle returns scale=-127 for NUMBER without precision
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment about oracle is informative, but it's not clear how it relates to the code here.

*/
@Tag("integration")
@EnabledIfSystemProperty(named = "calcite.integration.tests", matches = "true")
public class JdbcSchemaDecimalBugTest {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand where the DECIMAL without precision is.
Where is this table test_numbers?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the tests to create the table within each test method using CREATE TABLE ... (val NUMERIC) / (val DECIMAL) / (val NUMBER) without explicit precision, which is exactly the scenario that triggers CALCITE-6654. The table is dropped and recreated at the start of each test run.

@mmoradi0101 mmoradi0101 marked this pull request as draft April 13, 2026 14:31
@sonarqubecloud
Copy link
Copy Markdown

@mihaibudiu
Copy link
Copy Markdown
Contributor

I see this is a draft, please request a new review when this is ready

@mmoradi0101 mmoradi0101 marked this pull request as ready for review April 15, 2026 07:13
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