yaooqinn opened a new pull request #26618: [SPARK-29980][SQL] Whitespaces 
handling for Cast and BinaryOperation between StringType and NumericTypes
URL: https://github.com/apache/spark/pull/26618
 
 
   
   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: 
https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: 
https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., 
'[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a 
faster review.
   -->
   
   ### What changes were proposed in this pull request?
   Here is a case, let see how it goes in different SQL engines.
   
   ```sql
   select cast('1 ' as int) as v1, '1 ' = 1 as v2
   ```
   
   #### spark 1.6
   `NULL        true`
   #### spark 2.1
   `NULL        true`
   #### spark 2.2
   `NULL        NULL`
   #### spark 2.3
   `NULL        NULL`
   #### spark 2.4
   `NULL        NULL`
   #### hive
   `NULL        true`
   #### PostgreSQL
   
   ```sql
   postgres=# select cast('1 ' as int) as v1, '1 ' = 1 as v2;
    v1 | v2
   ----+----
     1 | t
   (1 row)
   ```
   #### presto
   ```sql
   presto> select cast('1 ' as int) as v1, '1 ' = 1 as v2;
   Query 20191120_060530_00002_f5kcs failed: line 1:38: '=' cannot be applied 
to varchar(2), integer
   select cast('1 ' as int) as v1, '1 ' = 1 as v2
   
   presto> select cast('1 ' as int) as v1, '1 ' = '1 ' as v2;
   Query 20191120_060545_00003_f5kcs failed: Cannot cast '1 ' to INT
   ```
   Our behavior is unstable because type coercion changed since 2.2.
   Personally, I think what PostgreSQL and Presto does here is more reasonable 
and consistent
   
   Currently, this pull request obeys PostgreSQL, might need further discussion 
against this behavior change.
   
   ### Why are the changes needed?
   
   For better dirty data auto handling, keep consistency with older version 
sparks
   
   
   ### Does this PR introduce any user-facing change?
   <!--
   Yes, string will be trim at both ends before casting and compared to numerics
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some 
test cases that check the changes thoroughly including negative and positive 
cases if possible.
   If it was tested in a way different from regular unit tests, please clarify 
how you tested step by step, ideally copy and paste-able, so that other 
reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why 
it was difficult to add.
   -->
   ad ut

----------------------------------------------------------------
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]

Reply via email to