Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ class PostgresIntegrationSuite extends DockerJDBCIntegrationSuite {
+ "B'1000100101', E'\\\\xDEADBEEF', true, '172.16.0.42', '192.168.0.0/16', "
+ """'{1, 2}', '{"a", null, "b"}', '{0.11, 0.22}', '{0.11, 0.22}', 'd1', 1.01, 1)"""
).executeUpdate()
conn.prepareStatement("INSERT INTO bar VALUES (null, null, null, null, null, "
+ "null, null, null, null, null, "
+ "null, null, null, null, null, null, null)"
).executeUpdate()
}

test("Type mapping for various types") {
val df = sqlContext.read.jdbc(jdbcUrl, "bar", new Properties)
val rows = df.collect()
assert(rows.length == 1)
val rows = df.collect().sortBy(_.toString())
assert(rows.length == 2)
val types = rows(0).toSeq.map(x => x.getClass)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment above this line to indicate the following statements are testing the first row.

assert(types.length == 17)
assert(classOf[String].isAssignableFrom(types(0)))
Expand Down Expand Up @@ -96,6 +100,9 @@ class PostgresIntegrationSuite extends DockerJDBCIntegrationSuite {
assert(rows(0).getString(14) == "d1")
assert(rows(0).getFloat(15) == 1.01f)
assert(rows(0).getShort(16) == 1)

// Test reading null values.
Copy link
Member

@gatorsmile gatorsmile Jan 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Test reading null values using the second row.

assert(0.until(16).forall(rows(1).isNullAt(_)))
}

test("Basic write test") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,9 @@ object JdbcUtils extends Logging {
}

(rs: ResultSet, row: InternalRow, pos: Int) =>
val array = nullSafeConvert[Object](
rs.getArray(pos + 1).getArray,
array => new GenericArrayData(elementConversion.apply(array)))
val array = nullSafeConvert[java.sql.Array](
rs.getArray(pos + 1),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: input = rs.getArray(pos + 1),

array => new GenericArrayData(elementConversion.apply(array.getArray)))
row.update(pos, array)

case _ => throw new IllegalArgumentException(s"Unsupported type ${dt.simpleString}")
Expand Down