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

from_json should accept an aggregate function as schema

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 2.3.1
    • Fix Version/s: None
    • Component/s: SQL
    • Labels:
      None

      Description

      Currently, the from_json() function accepts only string literals as schema:

      JsonToStructs should be modified to accept results of aggregate functions like infer_schema (see SPARK-24642). It should be possible to write SQL like:

      select from_json(json_col, infer_schema(json_col)) from json_table
      

      Here is a test case with existing aggregate function - first():

      create temporary view schemas(schema) as select * from values
        ('struct<a:int>'),
        ('map<string,int>');
      
      select from_json('{"a":1}', first(schema)) from schemas;
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                maxgekk Maxim Gekk
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: