Skip to content

Commit

Permalink
[SPARK-47478][SQL][TESTS] Improve test coverage for mysql bool synonyms
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

We have special conversion rules for mapping MySQL boolean synonyms, this PR added some tests to cover the read and write code path

### Why are the changes needed?

test coverage improvements

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

no

### How was this patch tested?

added tests
### Was this patch authored or co-authored using generative AI tooling?

no

Closes #45604 from yaooqinn/SPARK-47478.

Authored-by: Kent Yao <yao@apache.org>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
  • Loading branch information
yaooqinn authored and HyukjinKwon committed Mar 20, 2024
1 parent df56390 commit a3c04ec
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import java.util.Properties

import org.apache.spark.sql.Row
import org.apache.spark.sql.catalyst.util.DateTimeTestUtils._
import org.apache.spark.sql.types.{BooleanType, MetadataBuilder, StructType}
import org.apache.spark.tags.DockerTest

/**
Expand All @@ -46,6 +47,10 @@ class MySQLIntegrationSuite extends DockerJDBCIntegrationSuite {
conn.prepareStatement("INSERT INTO tbl VALUES (42,'fred')").executeUpdate()
conn.prepareStatement("INSERT INTO tbl VALUES (17,'dave')").executeUpdate()

conn.prepareStatement("CREATE TABLE bools (b1 BOOLEAN, b2 BIT(1), b3 TINYINT(1))")
.executeUpdate()
conn.prepareStatement("INSERT INTO bools VALUES (TRUE, b'1', 1)").executeUpdate()

conn.prepareStatement("CREATE TABLE numbers (onebit BIT(1), tenbits BIT(10), "
+ "small SMALLINT, med MEDIUMINT, nor INT, big BIGINT, deci DECIMAL(40,20), flt FLOAT, "
+ "dbl DOUBLE, tiny TINYINT, u_tiny TINYINT UNSIGNED)").executeUpdate()
Expand Down Expand Up @@ -204,4 +209,19 @@ class MySQLIntegrationSuite extends DockerJDBCIntegrationSuite {
""".stripMargin.replaceAll("\n", " "))
assert(sql("select x, y from queryOption").collect().toSet == expectedResult)
}


test("SPARK-47478: all boolean synonyms read-write roundtrip") {
val df = sqlContext.read.jdbc(jdbcUrl, "bools", new Properties)
checkAnswer(df, Row(true, true, true))
df.write.mode("append").jdbc(jdbcUrl, "bools", new Properties)
checkAnswer(df, Seq(Row(true, true, true), Row(true, true, true)))
val mb = new MetadataBuilder()
.putBoolean("isTimestampNTZ", false)
.putLong("scale", 0)
assert(df.schema === new StructType()
.add("b1", BooleanType, nullable = true, mb.putBoolean("isSigned", true).build())
.add("b2", BooleanType, nullable = true, mb.putBoolean("isSigned", false).build())
.add("b3", BooleanType, nullable = true, mb.putBoolean("isSigned", true).build()))
}
}

0 comments on commit a3c04ec

Please sign in to comment.