-
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 1 commit
749afc3
c202053
ae34533
1c487b7
a5dedac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
… test that uses custom JdbcDialect that maps TINYINT to ByteType
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,6 @@ import java.util.{Calendar, GregorianCalendar, Properties} | |
|
|
||
| import org.h2.jdbc.JdbcSQLException | ||
| import org.scalatest.{BeforeAndAfter, PrivateMethodTester} | ||
|
|
||
| import org.apache.spark.SparkException | ||
| import org.apache.spark.sql.{AnalysisException, DataFrame, QueryTest, Row} | ||
| import org.apache.spark.sql.catalyst.parser.CatalystSqlParser | ||
|
|
@@ -56,6 +55,17 @@ 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) | ||
|
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. I'm wondering if this is okay in this
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. Yeah, I think we found similar issue in another PR. @twdsilva can you check and fix it if needed? |
||
| case _ => None | ||
| } | ||
| } | ||
| } | ||
|
|
||
| before { | ||
| Utils.classForName("org.h2.Driver") | ||
| // Extra properties that will be specified for our database. We need these to test | ||
|
|
@@ -572,7 +582,7 @@ class JDBCSuite extends QueryTest | |
| assert(rows.length === 1) | ||
| assert(rows(0).getInt(0) === 1) | ||
| assert(rows(0).getBoolean(1) === false) | ||
| assert(rows(0).getByte(2) === 3) | ||
| assert(rows(0).getInt(2) === 3) | ||
| assert(rows(0).getInt(3) === 4) | ||
| assert(rows(0).getLong(4) === 1234567890123L) | ||
| } | ||
|
|
@@ -693,6 +703,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) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.