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.