You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "ShuMing Li (JIRA)" <ji...@apache.org> on 2019/07/28 14:29:00 UTC
[jira] [Comment Edited] (SPARK-28036) Built-in udf left/right has
inconsistent behavior
[ https://issues.apache.org/jira/browse/SPARK-28036?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16877765#comment-16877765 ]
ShuMing Li edited comment on SPARK-28036 at 7/28/19 2:28 PM:
-------------------------------------------------------------
[~shivusondur@gmail.com] It's not the same with `Postgres`:
* In Postgres:
** left({{str}} {{text}}, {{n}} {{int}}): Return first {{n}} characters in the string. When {{n is negative, return all but last |n}}| characters;
** right({{str}} {{text}}, {{n}} {{int}}): Return last {{n}} characters in the string. When {{n}} is negative, return all but first |{{n}}| characters;
* In Spark:
** left(str, len) - Returns the leftmost `len`(`len` can be string type) characters from the string `str`,if `len` is less or equal than 0 the result is an empty string;
** right(str, len) - Returns the rightmost `len`(`len` can be string type) characters from the string `str`,if `len` is less or equal than 0 the result is an empty string.
They are different when `n`/`len` is negative. So maybe need to change Spark to adapt to Postgres's meaning.
was (Author: lishuming):
[~shivusondur@gmail.com] It's not the same with `Postgres`:
* In Postgres:
** left({{str}} {{text}}, {{n}} {{int}}): Return first {{n}} characters in the string. When {{n }}is negative, return all but last |{{n}}| characters;
** right({{str}} {{text}}, {{n}} {{int}}): Return last {{n}} characters in the string. When {{n}} is negative, return all but first |{{n}}| characters;
* In Spark:
** left(str, len) - Returns the leftmost `len`(`len` can be string type) characters from the string `str`,if `len` is less or equal than 0 the result is an empty string;
** right(str, len) - Returns the rightmost `len`(`len` can be string type) characters from the string `str`,if `len` is less or equal than 0 the result is an empty string.
They are different when `n`/`len` is negative. So maybe need to change Spark to adapt to Postgres's meaning.
> Built-in udf left/right has inconsistent behavior
> -------------------------------------------------
>
> Key: SPARK-28036
> URL: https://issues.apache.org/jira/browse/SPARK-28036
> Project: Spark
> Issue Type: Sub-task
> Components: SQL
> Affects Versions: 3.0.0
> Reporter: Yuming Wang
> Priority: Major
>
> PostgreSQL:
> {code:sql}
> postgres=# select left('ahoj', -2), right('ahoj', -2);
> left | right
> ------+-------
> ah | oj
> (1 row)
> {code}
> Spark SQL:
> {code:sql}
> spark-sql> select left('ahoj', -2), right('ahoj', -2);
> spark-sql>
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org