Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-50792][SQL] Format binary data as a binary literal in JDBC. #49452

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Support binary literal for Oracle and add a test
Signed-off-by: Xiaoguang Sun <[email protected]>
  • Loading branch information
sunxiaoguang committed Jan 11, 2025
commit ce6bc59bf848f1c79202d8a2c32a021d39d6686d
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private case class MsSqlServerDialect() extends JdbcDialect with NoLegacyJDBCErr
// scalastyle:on line.size.limit
override def compileValue(value: Any): Any = value match {
case booleanValue: Boolean => if (booleanValue) 1 else 0
case binaryValue: Array[Byte] => binaryValue.map("%02X".format(_)).mkString("0x", "", "")
case other => super.compileValue(other)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3097,4 +3097,19 @@ class JDBCV2Suite extends QueryTest with SharedSparkSession with ExplainSuiteHel
assert(rows.contains(Row(null)))
assert(rows.contains(Row("a a a")))
}

test("SPARK-50792 Format binary data as a binary literal in JDBC.") {
withTable(s"h2.test.binary_literal") {
// Create a table with binary column
val binary = "X'123456'"
val tableName = "h2.test.binary_literal"

sql(s"CREATE TABLE $tableName (binary_col BLOB)")
sql(s"INSERT INTO $tableName VALUES ($binary)")

val select = s"SELECT * FROM $tableName WHERE binary_col = $binary"
assert(spark.sql(select).collect().length === 1, s"Binary literal test failed: $select")
}
}

}
Loading