AbhishekNew commented on a change in pull request #26477: [SPARK-29776][SQL]
rpad and lpad should return NULL when padstring parameter is empty
URL: https://github.com/apache/spark/pull/26477#discussion_r361597143
##########
File path:
common/unsafe/src/test/java/org/apache/spark/unsafe/types/UTF8StringSuite.java
##########
@@ -362,15 +362,15 @@ public void pad() {
assertEquals(EMPTY_UTF8, fromString("数据砖头").lpad(-10, fromString("孙行者")));
assertEquals(EMPTY_UTF8, fromString("数据砖头").lpad(-10, EMPTY_UTF8));
- assertEquals(fromString("数据砖头"), fromString("数据砖头").lpad(5, EMPTY_UTF8));
- assertEquals(fromString("数据砖"), fromString("数据砖头").lpad(3, EMPTY_UTF8));
- assertEquals(EMPTY_UTF8, EMPTY_UTF8.lpad(3, EMPTY_UTF8));
+ assertEquals(fromString(null), fromString("数据砖头").lpad(5, EMPTY_UTF8));
+ assertEquals(fromString(null), fromString("数据砖头").lpad(3, EMPTY_UTF8));
+ assertEquals(fromString(null), EMPTY_UTF8.lpad(3, EMPTY_UTF8));
assertEquals(EMPTY_UTF8, fromString("数据砖头").rpad(-10, fromString("孙行者")));
assertEquals(EMPTY_UTF8, fromString("数据砖头").rpad(-10, EMPTY_UTF8));
- assertEquals(fromString("数据砖头"), fromString("数据砖头").rpad(5, EMPTY_UTF8));
- assertEquals(fromString("数据砖"), fromString("数据砖头").rpad(3, EMPTY_UTF8));
- assertEquals(EMPTY_UTF8, EMPTY_UTF8.rpad(3, EMPTY_UTF8));
+ assertEquals(fromString(null), fromString("数据砖头").rpad(5, EMPTY_UTF8));
Review comment:
I think NULL is the better choice, that way we don't return unpadded data.
NULL makes sense with invalid input.
Please refer the JIRA how Hive handled
https://issues.apache.org/jira/browse/HIVE-15792
So as per me we should follow this as per Hive.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]