Skip to content

Commit 85a8718

Browse files
maropuyhuai
authored andcommitted
[SPARK-11394][SQL] Throw IllegalArgumentException for unsupported types in postgresql
If DataFrame has BYTE types, throws an exception: org.postgresql.util.PSQLException: ERROR: type "byte" does not exist Author: Takeshi YAMAMURO <linguin.m.s@gmail.com> Closes apache#9350 from maropu/FixBugInPostgreJdbc. (cherry picked from commit 73862a1) Signed-off-by: Yin Huai <yhuai@databricks.com>
1 parent fd20248 commit 85a8718

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ private object PostgresDialect extends JdbcDialect {
6464
getJDBCType(et).map(_.databaseTypeDefinition)
6565
.orElse(JdbcUtils.getCommonJDBCType(et).map(_.databaseTypeDefinition))
6666
.map(typeName => JdbcType(s"$typeName[]", java.sql.Types.ARRAY))
67+
case ByteType => throw new IllegalArgumentException(s"Unsupported type in postgresql: $dt");
6768
case _ => None
6869
}
6970

sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ class JDBCSuite extends SparkFunSuite with BeforeAndAfter with SharedSQLContext
460460
val Postgres = JdbcDialects.get("jdbc:postgresql://127.0.0.1/db")
461461
assert(Postgres.getCatalystType(java.sql.Types.OTHER, "json", 1, null) === Some(StringType))
462462
assert(Postgres.getCatalystType(java.sql.Types.OTHER, "jsonb", 1, null) === Some(StringType))
463+
val errMsg = intercept[IllegalArgumentException] {
464+
Postgres.getJDBCType(ByteType)
465+
}
466+
assert(errMsg.getMessage contains "Unsupported type in postgresql: ByteType")
463467
}
464468

465469
test("DerbyDialect jdbc type mapping") {

0 commit comments

Comments
 (0)