[#9816] fix(catalogs): Fix alter JDBC catalogs column default value problem(cherry-pick)#9873
Merged
jerryshao merged 1 commit intoapache:branch-1.1from Feb 4, 2026
Conversation
…alue problem (apache#9821) This pull request enhances the handling of default values for string-type columns in JDBC catalog implementations for MySQL, PostgreSQL, Doris, OceanBase, and StarRocks. It ensures that string default values are always properly quoted in generated SQL, addressing cases where default values may be empty or unquoted. Comprehensive unit tests have been added for each implementation to verify this behavior. it's a bug. Fix: apache#9816 N/A UTs --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in JDBC catalog implementations where setting empty string default values for columns could cause SQL syntax errors. The fix introduces a check in JdbcColumnDefaultValueConverter to properly quote empty/blank string values for numeric types, and refactors default value handling across MySQL, PostgreSQL, Doris, OceanBase, and StarRocks catalogs.
Changes:
- Added handling for empty/blank default values in
JdbcColumnDefaultValueConverterby wrapping them in quotes for numeric types - Refactored default value SQL generation into a shared
appendDefaultValuemethod inJdbcTableOperations - Updated all five JDBC catalog implementations to use the new shared method
- Added unit tests for each catalog to verify empty string and non-empty string default value handling
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/converter/JdbcColumnDefaultValueConverter.java | Added check to wrap empty/blank values in quotes for numeric types to prevent SQL syntax errors |
| catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java | Extracted common default value append logic into new protected method |
| catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/operation/MysqlTableOperations.java | Refactored to use shared appendDefaultValue method |
| catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.java | Refactored to use shared appendDefaultValue method, removed unused import |
| catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java | Refactored to use shared appendDefaultValue method, made appendNecessaryProperties visible for testing |
| catalogs/catalog-jdbc-oceanbase/src/main/java/org/apache/gravitino/catalog/oceanbase/operation/OceanBaseTableOperations.java | Refactored to use shared appendDefaultValue method |
| catalogs/catalog-jdbc-starrocks/src/main/java/org/apache/gravitino/catalog/starrocks/operations/StarRocksTableOperations.java | Refactored to use shared appendDefaultValue method |
| catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperationsSqlGeneration.java | Added tests for empty and non-empty string default values |
| catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/operation/TestPostgreSqlTableOperationsSqlGeneration.java | Added tests for empty and non-empty string default values |
| catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisTableOperationsSqlGeneration.java | Added tests for empty and non-empty string default values |
| catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/operation/TestOceanBaseTableOperationsSqlGeneration.java | Added tests for empty and non-empty string default values |
| catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperationsSqlGeneration.java | Added tests for empty, non-empty, and whitespace string default values |
| catalogs/catalog-jdbc-doris/build.gradle.kts | Added mockito-core test dependency for mocking in tests |
...java/org/apache/gravitino/catalog/doris/operation/TestDorisTableOperationsSqlGeneration.java
Show resolved
Hide resolved
.../apache/gravitino/catalog/oceanbase/operation/TestOceanBaseTableOperationsSqlGeneration.java
Show resolved
Hide resolved
.../apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperationsSqlGeneration.java
Show resolved
Hide resolved
...c/main/java/org/apache/gravitino/catalog/jdbc/converter/JdbcColumnDefaultValueConverter.java
Show resolved
Hide resolved
...java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperationsSqlGeneration.java
Show resolved
Hide resolved
...pache/gravitino/catalog/postgresql/operation/TestPostgreSqlTableOperationsSqlGeneration.java
Show resolved
Hide resolved
Contributor
|
Can this be merged? @yuqi1129 |
Contributor
Author
Yeah, this is just a cherry-pick PR, and it has been merged into main. |
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.
What changes were proposed in this pull request?
This pull request enhances the handling of default values for string-type columns in JDBC catalog implementations for MySQL, PostgreSQL, Doris, OceanBase, and StarRocks. It ensures that string default values are always properly quoted in generated SQL, addressing cases where default values may be empty or unquoted. Comprehensive unit tests have been added for each implementation to verify this behavior.
Why are the changes needed?
It's a bug.
Fix: #9816
Does this PR introduce any user-facing change?
N/A
How was this patch tested?
UTs.