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: 

Auto Loader fails when reading json element containing space

Magnus
Contributor

I'm using Auto Loader as part of a Delta Live Tables pipeline to ingest json files, and today it failed with this error message:

om.databricks.sql.transaction.tahoe.DeltaAnalysisException: Found invalid character(s) among ' ,;{}()\n\t=' in the column names of your schema. 
org.apache.spark.sql.AnalysisException:  Column name "NotificationSettings.element.Microsoft Teams" contains invalid character(s). Please use alias to rename it.

The failing json file contains an element named "Microsoft Teams" which causes the pipeline to fail. How can I handle such elements? The error message mentions the use of an alias, but I can't find any info on how to implement this.

		"NotificationSettings": [
			{
				"NotificationType": "MissedActivityReminder",
				"Microsoft Teams": true
			},
...

 

3 REPLIES 3

Lakshay
Databricks Employee
Databricks Employee

I could not get the DeltaTable solution to work in combination with Auto Loader/DLT/Unity Catalog, since it expects a table location and I want the framework to handle that.

I also tried withColumnRenamed, but I can't get it to work either. I still get the error message shown in my original question.

withColumnRenamed("NotificationSettings.Microsoft Teams", "MicrosoftTeams")

 

Tharun-Kumar
Databricks Employee
Databricks Employee

@Magnus 

  • You can read the input file using Pandas or Koalas (https://koalas.readthedocs.io/en/latest/index.html)
  • then rename the columns
  • then convert the Pandas/Koalas dataframe to Spark dataframe. You can write it back with the correct column name, so the next time you use it, the error will not happen.

 

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