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

Inferring schema from JSON string literal

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.1
    • Fix Version/s: 2.4.0
    • Component/s: SQL
    • Labels:
      None

      Description

      Need to add new function - schema_of_json(). The function should infer schema of JSON string literal. The result of the function is a schema in DDL format.

      One of the use cases is passing output of schema_of_json() to from_json(). Currently, the from_json() function requires a schema as a mandatory argument. An user has to pass a schema as string literal in SQL. The new function should allow schema inferring from an example. Let's say json_col is a column containing JSON string with the same schema. It should be possible to pass a JSON string with the same schema to schema_of_json() which infers schema for the particular example.

      select from_json(json_col, schema_of_json('{"f1": 0, "f2": [0], "f2": "a"}'))
      from json_table;
      

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: