yaooqinn opened a new pull request #26716: [SPARK-30083][SQL] 
visitArithmeticUnary should wrap PLUS case with UnaryPositive for type checking
URL: https://github.com/apache/spark/pull/26716
 
 
   ### What changes were proposed in this pull request?
   
   
   `UnaryPositive` only accepts numeric and interval as we defined, but what we 
do for this in  `AstBuider.visitArithmeticUnary` is just bypassing it.
   
   This should not be omitted for the type checking requirement.
   
   ### Why are the changes needed?
   
   bug fix, you can find a pre-discussion here 
https://github.com/apache/spark/pull/26578#discussion_r347350398
   
   ### Does this PR introduce any user-facing change?
   yes,  +non-numeric-or-interval is now invalid.
   ```
   -- !query 14
   select +date '1900-01-01'
   -- !query 14 schema
   struct<DATE '1900-01-01':date>
   -- !query 14 output
   1900-01-01
   
   
   -- !query 15
   select +timestamp '1900-01-01'
   -- !query 15 schema
   struct<TIMESTAMP '1900-01-01 00:00:00':timestamp>
   -- !query 15 output
   1900-01-01 00:00:00
   
   
   -- !query 16
   select +map(1, 2)
   -- !query 16 schema
   struct<map(1, 2):map<int,int>>
   -- !query 16 output
   {1:2}
   
   
   -- !query 17
   select +array(1,2)
   -- !query 17 schema
   struct<array(1, 2):array<int>>
   -- !query 17 output
   [1,2]
   
   
   -- !query 18
   select -'1'
   -- !query 18 schema
   struct<(- CAST(1 AS DOUBLE)):double>
   -- !query 18 output
   -1.0
   
   
   -- !query 19
   select -X'1'
   -- !query 19 schema
   struct<>
   -- !query 19 output
   org.apache.spark.sql.AnalysisException
   cannot resolve '(- X'01')' due to data type mismatch: argument 1 requires 
(numeric or interval) type, however, 'X'01'' is of binary type.; line 1 pos 7
   
   
   -- !query 20
   select +X'1'
   -- !query 20 schema
   struct<X'01':binary>
   -- !query 20 output
   ```
   
   
   ### 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.
   -->
   add ut check

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