<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Invalid Characters in Column Names &amp;quot; ,;{}()\n\t=&amp;quot; in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/104019#M41639</link>
    <description>&lt;P&gt;You can use column mapping to bypass this issue:&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When column mapping is enabled for a Delta table, you can include spaces and any of these characters in the table’s column names:&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="docutils literal notranslate"&gt;&lt;SPAN class="pre"&gt;,;{}()\n\t=&lt;/SPAN&gt;&lt;/CODE&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://docs.databricks.com/en/delta/column-mapping.html#supported-characters-in-column-names" target="_blank"&gt;https://docs.databricks.com/en/delta/column-mapping.html#supported-characters-in-column-names&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jan 2025 03:21:57 GMT</pubDate>
    <dc:creator>Walter_C</dc:creator>
    <dc:date>2025-01-03T03:21:57Z</dc:date>
    <item>
      <title>Invalid Characters in Column Names " ,;{}()\n\t="</title>
      <link>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/22960#M15812</link>
      <description>&lt;P&gt;I'm reading data into a dataframe with&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df = spark.read.json("s3://somepath/")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've tried first creating a delta table using the DeltaTable API with:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DeltaTable.createIfNotExists(spark)\
            .location(target_path)\
            .addColumns(df.schema)\
            .execute()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;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:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;spark.conf.set("spark.databricks.delta.defaults.columnMapping.mode", "name")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This hasn't worked. I've tried to use the DataFrame API instead:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df.write.format("delta").option("delta.columnMapping.mode", "name").save("s3://anotherpath")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But the same error message is coming up. The erroneous column names are deeply nested in structs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there some other way for me to accomplish this delta table write (without flattening and fixing col names)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT: I ended up traversing through the schema and changing the problematic column names.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 16:45:05 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/22960#M15812</guid>
      <dc:creator>maxutil</dc:creator>
      <dc:date>2022-11-09T16:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Characters in Column Names " ,;{}()\n\t="</title>
      <link>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/104018#M41638</link>
      <description>&lt;P&gt;Hi Databricks, it would be great to get a better answer to this 2022 issue, rather than changing column names. Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2025 02:27:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/104018#M41638</guid>
      <dc:creator>jb1z</dc:creator>
      <dc:date>2025-01-03T02:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Characters in Column Names " ,;{}()\n\t="</title>
      <link>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/104019#M41639</link>
      <description>&lt;P&gt;You can use column mapping to bypass this issue:&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When column mapping is enabled for a Delta table, you can include spaces and any of these characters in the table’s column names:&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="docutils literal notranslate"&gt;&lt;SPAN class="pre"&gt;,;{}()\n\t=&lt;/SPAN&gt;&lt;/CODE&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://docs.databricks.com/en/delta/column-mapping.html#supported-characters-in-column-names" target="_blank"&gt;https://docs.databricks.com/en/delta/column-mapping.html#supported-characters-in-column-names&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2025 03:21:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/104019#M41639</guid>
      <dc:creator>Walter_C</dc:creator>
      <dc:date>2025-01-03T03:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Characters in Column Names " ,;{}()\n\t="</title>
      <link>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/104021#M41640</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/88823"&gt;@Walter_C&lt;/a&gt;&amp;nbsp;thanks for the fast response. I tried using 'delta.columnMapping.mode', 'name' as suggested by&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/55742"&gt;@maxutil&lt;/a&gt;&amp;nbsp;but this failed with the same error. The documentation you provided only had SQL examples and the DLT pipeline i am running only allows python, so i am trying to set the option correctly. This is the code I have, and the example schema below that, that i also tried which failed with an error about columns not matching, even though the columns exactly match my json data.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import dlt
@dlt.table(table_properties={'quality': 'bronze'})
def netsuite_items_inventory_price():
  return (
     spark.readStream.format('cloudFiles')
     .option('cloudFiles.format', 'json')
     .option('delta.columnMapping.mode', 'name')
     .load('s3://data-lake-raw-injestion/Netsuite/Item/testLoad')
    )

# param for @dlt.tables(
schema="""
    ID STRING,
    RecordType STRING,
    Name STRING,
    DisplayName STRING,
    BasePrice STRING,
    IsItemUpdated STRING,
    OnHand STRING,
    TotalQuantityOnHand STRING,
    TotalValue STRING,
    AverageCost STRING,
    LastPurchasePrice STRING,
    Location STRING,
    Available STRING,
    UPCCode STRING,
    VendorName STRING,
    VendorCode STRING,
    EachHeight STRING,
    EachLength STRING,
    EachWidth STRING,
    Weight STRING
  """&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2025 04:17:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/104021#M41640</guid>
      <dc:creator>jb1z</dc:creator>
      <dc:date>2025-01-03T04:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Characters in Column Names " ,;{}()\n\t="</title>
      <link>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/104042#M41647</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/139986"&gt;@jb1z&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/55742"&gt;@maxutil&lt;/a&gt;&amp;nbsp;Have you tried it like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;import dlt

@dlt.table(table_properties={'quality': 'bronze', 'delta.columnMapping.mode': 'name'})
def netsuite_items_inventory_price():
    return (
        spark.readStream.format('cloudFiles')
        .option('cloudFiles.format', 'json')
        .load('s3://data-lake-raw-injestion/Netsuite/Item/testLoad')
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking at&amp;nbsp;&lt;A href="https://docs.databricks.com/en/delta-live-tables/properties.html#delta-live-tables-table-properties," target="_blank" rel="noopener"&gt;https://docs.databricks.com/en/delta-live-tables/properties.html#delta-live-tables-table-properties,&lt;/A&gt;&amp;nbsp;it says "&lt;SPAN&gt;In addition to the table properties supported by&amp;nbsp;&lt;/SPAN&gt;&lt;A class="reference internal" href="https://docs.databricks.com/en/delta/table-properties.html" target="_blank" rel="noopener"&gt;&lt;SPAN class="doc"&gt;Delta Lake&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;, you can set the following table properties.", so ideally we should be able to provide a key-value pair, columnMapping is listed in&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://docs.databricks.com/en/delta/table-properties.html#delta-table-properties:" target="_blank" rel="noopener"&gt;https://docs.databricks.com/en/delta/table-properties.html#delta-table-properties:&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;delta.columnMapping.mode

Whether column mapping is enabled for Delta table columns and the corresponding Parquet columns that use different names.

See Rename and drop columns with Delta Lake column mapping.

Note: Enabling delta.columnMapping.mode automatically enables delta.randomizeFilePrefixes.

Data type: DeltaColumnMappingMode

Default: none&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2025 09:40:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/104042#M41647</guid>
      <dc:creator>VZLA</dc:creator>
      <dc:date>2025-01-03T09:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Characters in Column Names " ,;{}()\n\t="</title>
      <link>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/105659#M42229</link>
      <description>&lt;P&gt;This code worked for me with all the additional table properties for versions. Thanks for your help&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/34618"&gt;@VZLA&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import dlt
@dlt.table(table_properties={'quality': 'bronze', 'delta.columnMapping.mode': 'name', 'delta.minReaderVersion': '2', 'delta.minWriterVersion': '5'})
def netsuite_items_inventory_price():
  return (
     spark.readStream.format('cloudFiles')
     .option('cloudFiles.format', 'json')
     .option('delta.columnMapping.mode', 'name')
     .load('s3://data-lake-raw-injestion/Netsuite/Item/testLoad')
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2025 05:16:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/105659#M42229</guid>
      <dc:creator>jb1z</dc:creator>
      <dc:date>2025-01-15T05:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Characters in Column Names " ,;{}()\n\t="</title>
      <link>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/105686#M42239</link>
      <description>&lt;P&gt;Glad it helped&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/139986"&gt;@jb1z&lt;/a&gt;&amp;nbsp;, happy to help.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2025 10:07:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/invalid-characters-in-column-names-quot-n-t-quot/m-p/105686#M42239</guid>
      <dc:creator>VZLA</dc:creator>
      <dc:date>2025-01-15T10:07:25Z</dc:date>
    </item>
  </channel>
</rss>

