[WIP] [SPARK-29644][SQL] Fixed ByteType JDBCUtils to map to TinyInt at write read and ShortType on read #27172
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?
Fixed ByteType JDBCUtils to map to TinyInt at write read and ShortType on read path.
Fixed Unit test cases where applicable and added new E2E test cases in to test table read/write ByteType.
Refer #26301 for details. The fix was reverted as it mapped even the read path to a ByteType and that would have resulted in truncations for some database that support 0 to 255 for tinyint while spark byteType range is -127 to +127 only.
Problems
case java.sql.Types.TINYINT => IntegerType
Why are the changes needed?
With the current mapping of ByteType as "Byte" when writting a table from JDBC connector fails.
Does this PR introduce any user-facing change?
Yes
(Write path) Uses would now be able to create tables when data frame has ByteType.
(Read path) Spark dataframe that reads a table with a TINYINT will get mapped to ShortType rather than Integer
How was this patch tested?
Corrected Unit test cases where applicable.
Added a test case in MsSqlServerIntegrationSuite.scala. Validated by manual as follows.