-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-26499] [SQL] JdbcUtils.makeGetter does not handle ByteType #23400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
749afc3
c202053
ae34533
1c487b7
a5dedac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,20 @@ class JDBCSuite extends QueryTest | |
| Some(StringType) | ||
| } | ||
|
|
||
| val testH2DialectTinyInt = new JdbcDialect { | ||
| override def canHandle(url: String): Boolean = url.startsWith("jdbc:h2") | ||
| override def getCatalystType( | ||
| sqlType: Int, | ||
| typeName: String, | ||
| size: Int, | ||
| md: MetadataBuilder): Option[DataType] = { | ||
| sqlType match { | ||
| case java.sql.Types.TINYINT => Some(ByteType) | ||
| case _ => None | ||
| } | ||
| } | ||
| } | ||
|
|
||
| before { | ||
| Utils.classForName("org.h2.Driver") | ||
| // Extra properties that will be specified for our database. We need these to test | ||
|
|
@@ -693,6 +707,17 @@ class JDBCSuite extends QueryTest | |
| JdbcDialects.unregisterDialect(testH2Dialect) | ||
| } | ||
|
|
||
| test("Map TINYINT to ByteType via JdbcDialects") { | ||
| JdbcDialects.registerDialect(testH2DialectTinyInt) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, @dongjoon-hyun, actually this test seems fine. The test dialect seems only scoped for this specific case.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. although it's a bit odd given #23400 (comment), at least this test is scoped and won't affect other tests about unsigned
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Originally, I suspected this dialect is valid for Luckily, In this case, I'm okay~
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for verifying this case @dongjoon-hyun |
||
| val df = spark.read.jdbc(urlWithUserAndPass, "test.inttypes", new Properties()) | ||
| val rows = df.collect() | ||
| assert(rows.length === 2) | ||
| assert(rows(0).get(2).isInstanceOf[Byte]) | ||
| assert(rows(0).getByte(2) === 3) | ||
| assert(rows(1).isNullAt(2)) | ||
| JdbcDialects.unregisterDialect(testH2DialectTinyInt) | ||
| } | ||
|
|
||
| test("Default jdbc dialect registration") { | ||
| assert(JdbcDialects.get("jdbc:mysql://127.0.0.1/db") == MySQLDialect) | ||
| assert(JdbcDialects.get("jdbc:postgresql://127.0.0.1/db") == PostgresDialect) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if this is okay in this
H2dialect context.We made
testH2DialectTinyIntlike this, but theoretically,TINYINTis still unsigned and SparkByteTypeis signed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we found similar issue in another PR. @twdsilva can you check and fix it if needed?