cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Invalid Characters in Column Names " ,;{}()\n\t="

maxutil
New Contributor II

I'm reading data into a dataframe with

df = spark.read.json("s3://somepath/")

I've tried first creating a delta table using the DeltaTable API with:

DeltaTable.createIfNotExists(spark)\
            .location(target_path)\
            .addColumns(df.schema)\
            .execute()

This is giving me an AnalysisException and says I have invalid characters. I should set the table property 'delta.columnMapping.mode' to 'name'. I've tried:

spark.conf.set("spark.databricks.delta.defaults.columnMapping.mode", "name")

This hasn't worked. I've tried to use the DataFrame API instead:

df.write.format("delta").option("delta.columnMapping.mode", "name").save("s3://anotherpath")

But the same error message is coming up. The erroneous column names are deeply nested in structs.

Is there some other way for me to accomplish this delta table write (without flattening and fixing col names)?

EDIT: I ended up traversing through the schema and changing the problematic column names.

1 REPLY 1

Kaniz
Community Manager
Community Manager

Hi @Chris Chung​, Can you re-check by trying the below code?

df.write.format("delta").option("delta.columnMapping.mode", "name").save("s3://anotherpath")

Now you can load it into a Spark dataframe:

SELECT * FROM new_table;

delta_df = spark.read.format("delta").load("table_path")

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.