Delta tables: Cannot set default column mapping mode to "name" in Python for delta tables

AsfandQ
New Contributor III

Hello,

I am trying to write Delta files for some CSV data. When I do

csv_dataframe.write.format("delta").save("/path/to/table.delta")

I get: AnalysisException:

Found invalid character(s) among " ,;{}()\n\t=" in the column names of your

schema.

Having looked up some docs, I expected the following to set the column mapping mode to "name" for all tables which would not cause this error:

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

Running this before invoking `write(...)` does not work and I get the same error.

I have managed to do it in SQL using TBLPROPERTIES with the CREATE TABLE statement like so:

CREATE TABLE table_bronze_csv
  USING CSV
  OPTIONS (path '/path/to/data.csv', 'header' 'true', 'mode' 'FAILFAST');
 
CREATE TABLE table_bronze
  USING DELTA
  TBLPROPERTIES ("delta.columnMapping.mode" = "name")
  AS SELECT * FROM table_bronze;

but am looking for the Python way of doing it.

Thanks