You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/01/01 06:14:46 UTC
[GitHub] asfgit closed pull request #23400: [SPARK-26499] [SQL]
JdbcUtils.makeGetter does not handle ByteType
asfgit closed pull request #23400: [SPARK-26499] [SQL] JdbcUtils.makeGetter does not handle ByteType
URL: https://github.com/apache/spark/pull/23400
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
index edea549748b47..922bef284c98e 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
@@ -438,6 +438,10 @@ object JdbcUtils extends Logging {
(rs: ResultSet, row: InternalRow, pos: Int) =>
row.setShort(pos, rs.getShort(pos + 1))
+ case ByteType =>
+ (rs: ResultSet, row: InternalRow, pos: Int) =>
+ row.update(pos, rs.getByte(pos + 1))
+
case StringType =>
(rs: ResultSet, row: InternalRow, pos: Int) =>
// TODO(davies): use getBytes for better performance, if the encoding is UTF-8
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala
index 71e83767964a0..e4641631e607d 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala
@@ -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)
+ 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)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org