dongjoon-hyun commented on code in PR #60487:
URL: https://github.com/apache/spark/pull/60487#discussion_r4574719006
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2PredicateSuite.scala:
##########
@@ -302,6 +303,31 @@ class V2PredicateSuite extends SparkFunSuite {
assert(PredicateUtils.toV1(predicate3).get.toV2 == predicate3)
}
+ test("SPARK-61684: CHAR_READ_SIDE_PADDING compared with literals") {
+ def str(s: String, dt: StringType = StringType): Literal[_] =
+ LiteralValue(UTF8String.fromString(s), dt)
+ def toV1(name: String, length: Int, literals: Literal[_]*): Option[Filter]
= {
+ val pad = new
GeneralScalarExpression(CharVarcharUtils.V2_CHAR_READ_SIDE_PADDING,
+ Array[Expression](ref("c"), LiteralValue(length, IntegerType), str("
")))
+ PredicateUtils.toV1(new Predicate(name, (pad +:
literals).toArray[Expression]))
+ }
+
+ // the stored values that a read pads to 'a '
+ val in = In("c", Array("a", "a ", "a "))
+ assert(toV1("=", 3, str("a ")) === Some(in))
+ assert(toV1("<>", 3, str("a ")) === Some(V1Not(in)))
+ // NULL <=> 'a ' is false, so it must stay false under a NOT
+ assert(toV1("<=>", 3, str("a ")) === Some(V1And(IsNotNull("c"), in)))
+ assert(toV1("IN", 3, str("a "), str("bc ")) ===
+ Some(In("c", Array("a", "a ", "a ", "bc", "bc "))))
+
+ // not converted: a non-binary collation, a literal not padded to the
length, too many values
+ assert(toV1("=", 3, str("a ", StringType("UTF8_LCASE"))).isEmpty)
+ assert(toV1("=", 3, str("a")).isEmpty)
+ assert(toV1("=", 255, str(" " * 255)).get.asInstanceOf[In].values.length
=== 256)
+ assert(toV1("=", 256, str(" " * 256)).isEmpty)
Review Comment:
Thank you. Added the `IN` case whose literals each fit within the bound but
together exceed it.
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2PredicateSuite.scala:
##########
@@ -302,6 +303,31 @@ class V2PredicateSuite extends SparkFunSuite {
assert(PredicateUtils.toV1(predicate3).get.toV2 == predicate3)
}
+ test("SPARK-61684: CHAR_READ_SIDE_PADDING compared with literals") {
+ def str(s: String, dt: StringType = StringType): Literal[_] =
+ LiteralValue(UTF8String.fromString(s), dt)
+ def toV1(name: String, length: Int, literals: Literal[_]*): Option[Filter]
= {
+ val pad = new
GeneralScalarExpression(CharVarcharUtils.V2_CHAR_READ_SIDE_PADDING,
+ Array[Expression](ref("c"), LiteralValue(length, IntegerType), str("
")))
+ PredicateUtils.toV1(new Predicate(name, (pad +:
literals).toArray[Expression]))
+ }
+
+ // the stored values that a read pads to 'a '
+ val in = In("c", Array("a", "a ", "a "))
+ assert(toV1("=", 3, str("a ")) === Some(in))
Review Comment:
Thank you. Added the case with U+1F600. It is built with
`Character.toChars(0x1F600)` because scalastyle reports the `😀` escape as a
non-ASCII character.
--
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]