GitHub user wangyum opened a pull request:
https://github.com/apache/spark/pull/18138
[SPARK-20915][SQL] Make lpad/rpad with empty pad string same as MySQL.
## What changes were proposed in this pull request?
Spark SQL `rpad/lpad` with empty pad string:
```sql
spark-sql> select rpad('hello', -2, ''), rpad('hello', -1, '') ,
rpad('hello', 0, ''), rpad('hello', 1, ''), rpad('hello', 3, ''), rpad('hello',
5, ''), rpad('hello', 6, '');
h hel hello hello
spark-sql> select lpad('hello', -2, ''), lpad('hello', -1, '') ,
lpad('hello', 0, ''), lpad('hello', 1, ''), lpad('hello', 3, ''), lpad('hello',
5, ''), lpad('hello', 6, '');
h hel hello hello
spark-sql>
```
but the MySQL result:
```
mysql> select rpad('hello', -2, ''), rpad('hello', -1, '') , rpad('hello',
0, ''), rpad('hello', 1, ''), rpad('hello', 3, ''), rpad('hello', 5, ''),
rpad('hello', 6, '') from dual;
+-----------------------+-----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+
| rpad('hello', -2, '') | rpad('hello', -1, '') | rpad('hello', 0, '') |
rpad('hello', 1, '') | rpad('hello', 3, '') | rpad('hello', 5, '') |
rpad('hello', 6, '') |
+-----------------------+-----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+
| NULL | NULL | | h
| hel | hello | NULL
|
+-----------------------+-----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+
1 row in set (0.00 sec)
mysql> select lpad('hello', -2, ''), lpad('hello', -1, '') , lpad('hello',
0, ''), lpad('hello', 1, ''), lpad('hello', 3, ''), lpad('hello', 5, ''),
lpad('hello', 6, '') from dual;
+-----------------------+-----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+
| lpad('hello', -2, '') | lpad('hello', -1, '') | lpad('hello', 0, '') |
lpad('hello', 1, '') | lpad('hello', 3, '') | lpad('hello', 5, '') |
lpad('hello', 6, '') |
+-----------------------+-----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+
| NULL | NULL | | h
| hel | hello | NULL
|
+-----------------------+-----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+
1 row in set (0.01 sec)
```
This PR fix this issue, after this PR:
```sql
spark-sql> select rpad('hello', -2, ''), rpad('hello', -1, '') ,
rpad('hello', 0, ''), rpad('hello', 1, ''), rpad('hello', 3, ''), rpad('hello',
5, ''), rpad('hello', 6, '');
NULL NULL h hel hello NULL
spark-sql> select lpad('hello', -2, ''), lpad('hello', -1, '') ,
lpad('hello', 0, ''), lpad('hello', 1, ''), lpad('hello', 3, ''), lpad('hello',
5, ''), lpad('hello', 6, '');
NULL NULL h hel hello NULL
spark-sql>
```
## How was this patch tested?
unit tests
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/wangyum/spark SPARK-20915
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/18138.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #18138
----
commit 3ac9fb07ef2f53315247ad12d391b1bed92319e9
Author: Yuming Wang <[email protected]>
Date: 2017-05-29T16:47:55Z
Make lpad/rpad with empty pad string same as MySQL.
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]