Skip to content

Commit

Permalink
[SPARK-32576][SQL][TEST][FOLLOWUP] Add tests for all the character ar…
Browse files Browse the repository at this point in the history
…ray types in PostgresIntegrationSuite

### What changes were proposed in this pull request?

This is a follow-up PR of #29192 that adds integration tests for character arrays in `PostgresIntegrationSuite`.

### Why are the changes needed?

For better test coverage.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Add tests.

Closes #29397 from maropu/SPARK-32576-FOLLOWUP.

Authored-by: Takeshi Yamamuro <yamamuro@apache.org>
Signed-off-by: Takeshi Yamamuro <yamamuro@apache.org>
  • Loading branch information
maropu committed Aug 10, 2020
1 parent fc62d72 commit 7990ea1
Showing 1 changed file with 19 additions and 0 deletions.
Expand Up @@ -83,6 +83,13 @@ class PostgresIntegrationSuite extends DockerJDBCIntegrationSuite {
).executeUpdate()
conn.prepareStatement("INSERT INTO char_types VALUES " +
"('abcd', 'efgh', 'ijkl', 'mnop', 'q')").executeUpdate()

conn.prepareStatement("CREATE TABLE char_array_types (" +
"c0 char(4)[], c1 character(4)[], c2 character varying(4)[], c3 varchar(4)[], c4 bpchar[])"
).executeUpdate()
conn.prepareStatement("INSERT INTO char_array_types VALUES " +
"""('{"a", "bcd"}', '{"ef", "gh"}', '{"i", "j", "kl"}', '{"mnop"}', '{"q", "r"}')"""
).executeUpdate()
}

test("Type mapping for various types") {
Expand Down Expand Up @@ -235,4 +242,16 @@ class PostgresIntegrationSuite extends DockerJDBCIntegrationSuite {
assert(row(0).getString(3) === "mnop")
assert(row(0).getString(4) === "q")
}

test("SPARK-32576: character array type tests") {
val df = sqlContext.read.jdbc(jdbcUrl, "char_array_types", new Properties)
val row = df.collect()
assert(row.length == 1)
assert(row(0).length === 5)
assert(row(0).getSeq[String](0) === Seq("a ", "bcd "))
assert(row(0).getSeq[String](1) === Seq("ef ", "gh "))
assert(row(0).getSeq[String](2) === Seq("i", "j", "kl"))
assert(row(0).getSeq[String](3) === Seq("mnop"))
assert(row(0).getSeq[String](4) === Seq("q", "r"))
}
}

0 comments on commit 7990ea1

Please sign in to comment.