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
Esteemed Contributor
Esteemed Contributor

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
Honored Contributor II
Honored Contributor II

@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.

 

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!