cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Schema supported by Autoloader

Chris_Konsur
New Contributor III

We do not want to use schema inference with schema evolution in Autoloader. Instead, we want to apply our schema and use the merge option. Our schema is very complex, with multiple nested following levels. 

When I apply this schema to Autoloader, it runs without errors, but it appears that Autoloader cannot parse this multiple-level nested schema. The Autoloader creates columns from the top level, but all the nested levels and values are NULL.  

 stream = spark.readStream.format("cloudFiles")\

     .option("cloudFiles.format", al_in_file_format)\

     .option("multiLine", True) \

     .option('cloudFiles.allowOverwrites',True)\

     .option("cloudFiles.useNotifications", True)\

     .option("cloudFiles.subscriptionId", subscribtion)\

     .option("cloudFiles.tenantId", tenant_id)\

     .option("cloudFiles.clientId", client_id)\

     .option("cloudFiles.clientSecret", client_secret)\

     .option("cloudFiles.resourceGroup", "orcus-eastus")\

     .schema(schema_from_data_catalog)\

     .load(row["al_json_loc"])\

     .withColumn("CurrTime",current_timestamp())\

     .withColumn("filePath",input_file_name())\

     .writeStream.format(al_out_format) \

     .option('checkpointLocation', row["al_checkpoint_path"]) \

     .option('mergeSchema', True)\

     .outputMode("append")\

     .table(databasetable)  

Our schema is this format   

{

  "$schema": "http://json-schema.org/draft-07/schema#",

  "type": "object",

  "title": "LTE Insights",

  "description": "LTE Insights",

  "properties": {

    "id": {

      "type": "string",

      "description": "Unique identifier"

    },

    "name": {

      "type": "string",

      "description": "Name"

    }

  }

}

But Autoloader expect a schema with this format. {

    "fields": [

        {

            "metadata": {},

            "name": "id",

            "nullable": true,

            "type": "string"

        },

        {

            "metadata": {},

            "name": "name",

            "nullable": true,

            "type": "string"

        },

        {

            "metadata": {},

            "name": "_rescued_data",

            "nullable": true,

            "type": "string"

        },

        {

            "metadata": {},

            "name": "CurrTime",

            "nullable": true,

            "type": "timestamp"

        },

        {

            "metadata": {},

            "name": "filePath",

            "nullable": true,

            "type": "string"

        }

    ],

    "type": "struct"

}

Is there a way to convert the schema to schema format that Autoloader expects?

0 REPLIES 0

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group