cloud-fan commented on code in PR #36103:
URL: https://github.com/apache/spark/pull/36103#discussion_r847563776
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/StringExpressionsSuite.scala:
##########
@@ -771,6 +771,77 @@ class StringExpressionsSuite extends SparkFunSuite with
ExpressionEvalHelper {
checkEvaluation(StringRPad(Literal("hi"), Literal(1)), "h")
}
+ test("PadExpressionBuilderBase") {
+ // test if the correct lpad/rpad expression is created given different
parameter types
+ Seq(true, false).foreach { bcEnabled =>
+ SQLConf.get.setConf(SQLConf.LPAD_RPAD_FOR_BINARY_TYPE, bcEnabled)
+
+ val lpadExp1 = LPadExpressionBuilder.build("lpad",
Seq(Literal(Array[Byte]()), Literal(5)))
+ val lpadExp2 = LPadExpressionBuilder.build("lpad", Seq(Literal("hi"),
Literal(5)))
+ val lpadExp3 = LPadExpressionBuilder.build("lpad",
+ Seq(Literal(Array[Byte](1, 2)), Literal(5), Literal(Array[Byte](1))))
+ val lpadExp4 = LPadExpressionBuilder.build("lpad",
+ Seq(Literal(Array[Byte](1, 2)), Literal(5), Literal("somepadding")))
+ val lpadExp5 = LPadExpressionBuilder.build("lpad",
+ Seq(Literal("hi"), Literal(5), Literal("somepadding")))
+
+ val rpadExp1 = RPadExpressionBuilder.build("rpad",
Seq(Literal(Array[Byte]()), Literal(5)))
+ val rpadExp2 = RPadExpressionBuilder.build("rpad", Seq(Literal("hi"),
Literal(5)))
+ val rpadExp3 = RPadExpressionBuilder.build("rpad",
+ Seq(Literal(Array[Byte](1, 2)), Literal(5), Literal(Array[Byte](1))))
+ val rpadExp4 = RPadExpressionBuilder.build("rpad",
+ Seq(Literal(Array[Byte](1, 2)), Literal(5), Literal("somepadding")))
+ val rpadExp5 = RPadExpressionBuilder.build("rpad",
+ Seq(Literal("hi"), Literal(5), Literal("somepadding")))
+
+ if (SQLConf.get.getConf(SQLConf.LPAD_RPAD_FOR_BINARY_TYPE)) {
+ assert(lpadExp1.asInstanceOf[BinaryPad] ==
+ BinaryPad("lpad", Literal(Array[Byte]()), Literal(5),
Literal(Array[Byte](0))))
+ assert(lpadExp2.asInstanceOf[StringLPad] ==
+ StringLPad(Literal("hi"), Literal(5), Literal(" ")))
Review Comment:
can we put the ones that have the same result before the `if-else`? to
highlight what gets changed if we flip the config.
--
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]