shivadarshan-devadiga commented on code in PR #60750:
URL: https://github.com/apache/spark/pull/60750#discussion_r4651095162
##########
sql/core/src/test/scala/org/apache/spark/sql/CharVarcharTestSuite.scala:
##########
@@ -660,6 +660,59 @@ trait CharVarcharTestSuite extends QueryTest {
}
}
+ test("SPARK-61970: char type comparison: struct field and string literal") {
+ withTable("t") {
+ sql(s"CREATE TABLE t(s STRUCT<c: CHAR(3)>, n STRUCT<s: STRUCT<c:
CHAR(3)>>) USING $format")
+ sql("INSERT INTO t VALUES (struct('a'), struct(struct('a')))")
+ testConditions(spark.table("t"), Seq(
+ ("s.c = 'a'", true),
+ ("'a' = s.c", true),
+ ("s.c = 'a '", true),
+ ("s.c > 'a'", false),
+ ("s.c IN ('a', 'b')", true),
+ ("s.c = 'abcd'", false),
+ ("n.s.c = 'a'", true),
+ ("n.s.c IN ('b', 'a')", true),
+ ("s.c <=> null", false)))
+ }
+ }
+
+ test("SPARK-61970: a reordered struct field keeps its own raw type") {
+ withTable("t") {
+ sql(s"CREATE TABLE t(s STRUCT<c: CHAR(3), v: STRING>) USING $format")
+ sql("INSERT INTO t VALUES (named_struct('c', 'x', 'v', 'a'))")
+ // Dataset.to reorders the fields of the struct and keeps the column's
metadata.
+ val df = spark.table("t").to(StructType.fromDDL("s STRUCT<v: STRING, c:
STRING>"))
+ checkAnswer(df.selectExpr("s.v = 'a'", "s.c = 'x'"), Row(true, true))
+ // It matches field names case-insensitively, and takes the target's
spelling.
+ val renamed = spark.table("t").to(StructType.fromDDL("s STRUCT<C:
STRING, V: STRING>"))
+ checkAnswer(renamed.selectExpr("s.C = 'x'", "s.V = 'a'"), Row(true,
true))
+ }
+ withTable("t") {
+ sql(s"CREATE TABLE t(n STRUCT<s: STRUCT<c: CHAR(3), v: STRING>>) USING
$format")
+ sql("INSERT INTO t VALUES (named_struct('s', named_struct('c', 'x', 'v',
'a')))")
+ // The fields of a nested struct are reordered too.
+ val df = spark.table("t").to(StructType.fromDDL("n STRUCT<s: STRUCT<v:
STRING, c: STRING>>"))
+ checkAnswer(df.selectExpr("n.s.c = 'x'", "n.s.v = 'a'"), Row(true, true))
+ }
+ }
+
+ test("SPARK-61970: comparisons with a struct field keep constants that
fail") {
Review Comment:
Updated. The description now names the suites the tests run in, says that
the type check on the value applies to top-level columns too (and how it treats
CHAR), and lists the user-facing change for top-level columns compared with a
constant that fails.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]