yaooqinn opened a new pull request #26599: [SPARK-29961][SQL] Implement builtin 
function - typeof
URL: https://github.com/apache/spark/pull/26599
 
 
   ### What changes were proposed in this pull request?
   Add typeof function for Spark to get the underlying type of value.
   ```sql
   -- !query 0
   select typeof(1)
   -- !query 0 schema
   struct<typeof(1):string>
   -- !query 0 output
   int
   
   
   -- !query 1
   select typeof(1.2)
   -- !query 1 schema
   struct<typeof(1.2):string>
   -- !query 1 output
   decimal(2,1)
   
   
   -- !query 2
   select typeof(array(1, 2))
   -- !query 2 schema
   struct<typeof(array(1, 2)):string>
   -- !query 2 output
   array<int>
   
   
   -- !query 3
   select typeof(a) from (values (1), (2), (3.1)) t(a)
   -- !query 3 schema
   struct<typeof(a):string>
   -- !query 3 output
   decimal(11,1)
   decimal(11,1)
   decimal(11,1)
   
   ```
   
   ##### presto
   
   ```sql
   presto> select typeof(array[1]);
        _col0
   ----------------
    array(integer)
   (1 row)
   ```
   ##### PostgreSQL
   
   ```sql
   postgres=# select pg_typeof(a) from (values (1), (2), (3.0)) t(a);
    pg_typeof
   -----------
    numeric
    numeric
    numeric
   (3 rows)
   ```
   ##### impala 
   https://issues.apache.org/jira/browse/IMPALA-1597
   
   ### Why are the changes needed?
   a function which is better we have to help us debug, test, develop ...
   
   
   ### Does this PR introduce any user-facing change?
   <!--
   If yes, please clarify the previous behavior and the change this PR proposes 
- provide the console output, description and/or an example to show the 
behavior difference if possible.
   If no, write 'No'.
   -->
   
   add a new function
   ### 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 and example

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