Add Short and BigDecimal type mappings to SqlTypeUtils#763
Open
gknz wants to merge 2 commits into
Open
Conversation
Short and java.math.BigDecimal had no entry in the JDBC type map, so columns of those Java types were created as VARCHAR(255) by the JDBC table sink in overwrite mode. Map Short (and short) to SMALLINT and BigDecimal to NUMERIC; the PostgreSQL dialect map inherits both from the default map. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
SqlTypeUtils now maps Short->SMALLINT and BigDecimal->NUMERIC for the generated DDL, but the sinks still bound those values via the String fallback. Complete the write path: - JavaTableSink: bind via setShort / setBigDecimal - SparkTableSink: map Short->ShortType and BigDecimal->DecimalType(38,18) so the Spark DataFrame writes SMALLINT / NUMERIC columns instead of text
Contributor
|
Hi thanks for the contribution, if possible it would also be nice to have a unit test for this |
Contributor
|
@mspruc what unit test do you have in mind? This PR seems to simply add two more data types |
Contributor
|
@zkaoudi well something that tests the sinks ideally, e.g. for https://github.com/gknz/wayang/blob/efb35979111a6bb84192acd2ade8424bcd1ee463/wayang-platforms/wayang-spark/src/main/java/org/apache/wayang/spark/operators/SparkTableSink.java#L156 we have two magic numbers, I'd like to make sure this conversion is stable. |
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.
Summary
Adds proper SQL type handling for
Shortandjava.math.BigDecimalacross thetable-sink write path. Previously these had no entry in the JDBC type map, so the
sink created such columns as
VARCHAR(255)in overwrite mode and bound the valuesas strings.
Changes
Short/short→SMALLINTandBigDecimal→NUMERIC(the PostgreSQL dialect inherits both from the default map).
setShort/setBigDecimalinstead of thesetStringfallback.Short→ShortTypeandBigDecimal→DecimalType(38, 18)(Spark's default precision/scale) so the DataFrame writesSMALLINT/NUMERICcolumns instead of text.Testing
Verified end-to-end against PostgreSQL on both the Java and Spark platforms: a
record of
(Integer, Short, BigDecimal)now producesinteger/smallint/numericcolumns with the exact values on both write paths.