Skip to content

Commit

Permalink
[SPARK-6967] [SQL] fix date type convertion in jdbcrdd
Browse files Browse the repository at this point in the history
This pr convert java.sql.Date type into Int for JDBCRDD.

Author: Daoyuan Wang <[email protected]>

Closes #5590 from adrian-wang/datebug and squashes the following commits:

f897b81 [Daoyuan Wang] add a test case
3c9184c [Daoyuan Wang] fix date type convertion in jdbcrdd
  • Loading branch information
adrian-wang authored and rxin committed Apr 23, 2015
1 parent f4f3998 commit 04525c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ private[sql] class JDBCRDD(
val pos = i + 1
conversions(i) match {
case BooleanConversion => mutableRow.setBoolean(i, rs.getBoolean(pos))
// TODO(davies): convert Date into Int
case DateConversion => mutableRow.update(i, rs.getDate(pos))
case DateConversion =>
mutableRow.update(i, DateUtils.fromJavaDate(rs.getDate(pos)))
case DecimalConversion => mutableRow.update(i, rs.getBigDecimal(pos))
case DoubleConversion => mutableRow.setDouble(i, rs.getDouble(pos))
case FloatConversion => mutableRow.setFloat(i, rs.getFloat(pos))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ class JDBCSuite extends FunSuite with BeforeAndAfter {
assert(rows(0).getAs[java.sql.Timestamp](2).getNanos === 543543543)
}

test("test DATE types") {
val rows = TestSQLContext.jdbc(urlWithUserAndPass, "TEST.TIMETYPES").collect()
val cachedRows = TestSQLContext.jdbc(urlWithUserAndPass, "TEST.TIMETYPES").cache().collect()
assert(rows(0).getAs[java.sql.Date](1) === java.sql.Date.valueOf("1996-01-01"))
assert(cachedRows(0).getAs[java.sql.Date](1) === java.sql.Date.valueOf("1996-01-01"))
}

test("H2 floating-point types") {
val rows = sql("SELECT * FROM flttypes").collect()
assert(rows(0).getDouble(0) === 1.00000000000000022) // Yes, I meant ==.
Expand Down

0 comments on commit 04525c0

Please sign in to comment.