Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-29961

Implement typeof builtin function

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.0.0
    • 3.0.0
    • SQL
    • None

    Description

      Add typeof function in Spark to illastrate the underlying type of a value.

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

      resto> select typeof(array[1]);
           _col0
      ----------------
       array(integer)
      (1 row)
      

      PostgreSQL

      postgres=# select pg_typeof(a) from (values (1), (2), (3.0)) t(a);
       pg_typeof
      -----------
       numeric
       numeric
       numeric
      (3 rows)
      

      Attachments

        Issue Links

          Activity

            People

              Qin Yao Kent Yao 2
              Qin Yao Kent Yao 2
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: