Skip to content

Commit

Permalink
changing to require instead of if
Browse files Browse the repository at this point in the history
  • Loading branch information
ayudovin committed Jan 6, 2019
1 parent 34fe718 commit e8fd2b6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ object JDBCRDD extends Logging {
val table = options.tableOrQuery
val dialect = JdbcDialects.get(url)
val conn: Connection = JdbcUtils.createConnectionFactory(options)()

try {
val statement = conn.prepareStatement(dialect.getSchemaQuery(table))
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ object JdbcUtils extends Logging {
s"Did not find registered driver with class $driverClass")
}
val connection: Connection = driver.connect(options.url, options.asConnectionProperties)

if (connection == null) {
throw new IllegalArgumentException("Wrong url in JDBC options.")
}
require(connection != null,
s"The driver could not open a JDBC connection. Check the URL: ${options.url}")

connection
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ class JDBCSuite extends QueryTest
Row("fred", 1) :: Nil)
}

test("SPARK-26383 throw IllegalArgumentException if url is wrong") {
test("SPARK-26383 throw IllegalArgumentException if wrong kind of driver to the given url") {
val e = intercept[IllegalArgumentException] {
val opts = Map(
"url" -> "jdbc:mysql://localhost/db",
Expand All @@ -1518,6 +1518,7 @@ class JDBCSuite extends QueryTest
)
spark.read.format("jdbc").options(opts).load
}.getMessage
assert(e.contains("Wrong url in JDBC options."))
assert(e.contains("The driver could not open a JDBC connection. " +
"Check the URL: jdbc:mysql://localhost/db"))
}
}

0 comments on commit e8fd2b6

Please sign in to comment.