vitaliili-db commented on code in PR #37483:
URL: https://github.com/apache/spark/pull/37483#discussion_r951968563
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/StringExpressionsSuite.scala:
##########
@@ -452,6 +452,90 @@ class StringExpressionsSuite extends SparkFunSuite with
ExpressionEvalHelper {
// scalastyle:on
}
+ test("to_binary") {
+ // Base64 - Positive cases
+ val base64Literal = Literal("base64")
+ Seq(
+ ("", ""),
+ (" \r\n \t", ""),
+ ("ag", "ag=="),
+ ("abc", "abc="),
+ ("abcd", "abcd"),
+ ("ab\r\n\t cd", "abcd"),
+ ("ab cd ef", "abcdeQ=="),
+ ("+ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/",
+ "+ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/"),
+
("b25lIHR3byB0aHJlZSBmb3VyIGZpdmUgc2l4IHNldmVuIGVpZ2h0IG5pbmUgdGVuIGVsZXZlbiB0\r\n"
+
+
"d2VsdmUgdGhpcnRlZW4gZm91cnRlZW4gZml2dGVlbiBzaXh0ZWVuIHNldmVudGVlbiBlaWdodGVl\r\n"
+
+ "biBuaW5ldGVlbiB0d2VudHkgdHdlbnR5LW9uZQ==",
+
"b25lIHR3byB0aHJlZSBmb3VyIGZpdmUgc2l4IHNldmVuIGVpZ2h0IG5pbmUgdGVuIGVsZXZlbiB0\r\n"
+
+
"d2VsdmUgdGhpcnRlZW4gZm91cnRlZW4gZml2dGVlbiBzaXh0ZWVuIHNldmVudGVlbiBlaWdodGVl\r\n"
+
+ "biBuaW5ldGVlbiB0d2VudHkgdHdlbnR5LW9uZQ==")
+ ).foreach {
+ case (input: String, expected: String) =>
+ checkEvaluation(Base64(ToBinary(Literal(input), base64Literal)),
expected)
+ }
+ checkEvaluation(ToBinary(Literal.create(null, StringType), base64Literal),
null)
+
+ // Base64 - Negative cases
+ Seq(
+ "a", // Too short
+ "abc==", // Invalid padding
+ "abcdef==a", // String should end with padding
+ "[email protected]" // Invalid character
+ ).foreach { input =>
+ val errMsg = "[CONVERSION_INVALID_INPUT]"
+ checkExceptionInExpression[Exception](ToBinary(Literal(input),
base64Literal), errMsg)
+ }
Review Comment:
I think it is a bit out of scope of this PR. Right now
`checkExceptionInExpression` covers more scenarios than `checkError` so I would
take switching as separate task, wdyt?
--
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]