Skip to content

Commit 2fca41c

Browse files
belieferLuciferYang
authored andcommitted
[SPARK-50792][SQL][TESTS][FOLLOWUP] Test case should reuse the exists table
### What changes were proposed in this pull request? This PR proposes update the test case by reuse the exists table. ### Why are the changes needed? #49452 created a new table for binary test. But there are already exists a table with binary schema. This PR also rename the test table with binary schema to a better name. ### Does this PR introduce _any_ user-facing change? 'No'. Just update test case. ### How was this patch tested? GA. ### Was this patch authored or co-authored using generative AI tooling? 'No'. Closes #50087 from beliefer/SPARK-50792_f2. Authored-by: beliefer <beliefer@163.com> Signed-off-by: yangjie01 <yangjie01@baidu.com>
1 parent 727167a commit 2fca41c

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCV2Suite.scala

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import java.util.Properties
2222

2323
import scala.util.control.NonFatal
2424

25+
import org.apache.commons.codec.binary.Hex
2526
import test.org.apache.spark.sql.connector.catalog.functions.JavaStrLen.JavaStrLenStaticMagic
2627

2728
import org.apache.spark.{SparkConf, SparkException, SparkIllegalArgumentException}
@@ -222,9 +223,9 @@ class JDBCV2Suite extends QueryTest with SharedSparkSession with ExplainSuiteHel
222223
conn.prepareStatement("INSERT INTO \"test\".\"address\" VALUES " +
223224
"('abc_''%def@gmail.com')").executeUpdate()
224225

225-
conn.prepareStatement("CREATE TABLE \"test\".\"binary1\" (name TEXT(32),b BINARY(20))")
226+
conn.prepareStatement("CREATE TABLE \"test\".\"binary_tab\" (name TEXT(32),b BINARY(20))")
226227
.executeUpdate()
227-
val stmt = conn.prepareStatement("INSERT INTO \"test\".\"binary1\" VALUES (?, ?)")
228+
val stmt = conn.prepareStatement("INSERT INTO \"test\".\"binary_tab\" VALUES (?, ?)")
228229
stmt.setString(1, "jen")
229230
stmt.setBytes(2, testBytes)
230231
stmt.executeUpdate()
@@ -1602,23 +1603,23 @@ class JDBCV2Suite extends QueryTest with SharedSparkSession with ExplainSuiteHel
16021603
}
16031604

16041605
test("scan with filter push-down with misc functions") {
1605-
val df1 = sql("SELECT name FROM h2.test.binary1 WHERE " +
1606+
val df1 = sql("SELECT name FROM h2.test.binary_tab WHERE " +
16061607
"md5(b) = '4371fe0aa613bcb081543a37d241adcb'")
16071608
checkFiltersRemoved(df1)
16081609
val expectedPlanFragment1 = "PushedFilters: [B IS NOT NULL, " +
16091610
"MD5(B) = '4371fe0aa613bcb081543a37d241adcb']"
16101611
checkPushedInfo(df1, expectedPlanFragment1)
16111612
checkAnswer(df1, Seq(Row("jen")))
16121613

1613-
val df2 = sql("SELECT name FROM h2.test.binary1 WHERE " +
1614+
val df2 = sql("SELECT name FROM h2.test.binary_tab WHERE " +
16141615
"sha1(b) = 'cf355e86e8666f9300ef12e996acd5c629e0b0a1'")
16151616
checkFiltersRemoved(df2)
16161617
val expectedPlanFragment2 = "PushedFilters: [B IS NOT NULL, " +
16171618
"SHA1(B) = 'cf355e86e8666f9300ef12e996acd5c629e0b0a1'],"
16181619
checkPushedInfo(df2, expectedPlanFragment2)
16191620
checkAnswer(df2, Seq(Row("jen")))
16201621

1621-
val df3 = sql("SELECT name FROM h2.test.binary1 WHERE " +
1622+
val df3 = sql("SELECT name FROM h2.test.binary_tab WHERE " +
16221623
"sha2(b, 256) = '911732d10153f859dec04627df38b19290ec707ff9f83910d061421fdc476109'")
16231624
checkFiltersRemoved(df3)
16241625
val expectedPlanFragment3 = "PushedFilters: [B IS NOT NULL, (SHA2(B, 256)) = " +
@@ -1777,7 +1778,7 @@ class JDBCV2Suite extends QueryTest with SharedSparkSession with ExplainSuiteHel
17771778
Row("test", "empty_table", false), Row("test", "employee", false),
17781779
Row("test", "item", false), Row("test", "dept", false),
17791780
Row("test", "person", false), Row("test", "view1", false), Row("test", "view2", false),
1780-
Row("test", "datetime", false), Row("test", "binary1", false),
1781+
Row("test", "datetime", false), Row("test", "binary_tab", false),
17811782
Row("test", "employee_bonus", false),
17821783
Row("test", "strings_with_nulls", false)))
17831784
}
@@ -3109,19 +3110,13 @@ class JDBCV2Suite extends QueryTest with SharedSparkSession with ExplainSuiteHel
31093110
}
31103111

31113112
test("SPARK-50792: Format binary data as a binary literal in JDBC.") {
3112-
val tableName = "h2.test.binary_literal"
3113-
withTable(tableName) {
3114-
// Create a table with binary column
3115-
val binary = "X'123456'"
3116-
3117-
sql(s"CREATE TABLE $tableName (binary_col BINARY)")
3118-
sql(s"INSERT INTO $tableName VALUES ($binary)")
3119-
3120-
val df = sql(s"SELECT * FROM $tableName WHERE binary_col = $binary")
3121-
checkFiltersRemoved(df)
3122-
checkPushedInfo(df, "PushedFilters: [binary_col IS NOT NULL, binary_col = 0x123456]")
3123-
checkAnswer(df, Row(Array(18, 52, 86)))
3124-
}
3113+
val hexBinary = Hex.encodeHexString(testBytes, false)
3114+
val binary = "X'" + hexBinary + "'"
3115+
val df = sql(s"SELECT * FROM h2.test.binary_tab WHERE b = $binary")
3116+
checkFiltersRemoved(df)
3117+
checkPushedInfo(df, s"PushedFilters: [B IS NOT NULL, B = 0x$hexBinary]")
3118+
checkAnswer(df,
3119+
Row("jen", Array(99, -122, -121, -56, -51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)))
31253120
}
31263121

31273122
}

0 commit comments

Comments
 (0)