<?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: How to set properties for a delta table when I want to write a DataFrame? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-set-properties-for-a-delta-table-when-i-want-to-write-a/m-p/7626#M3433</link>
    <description>&lt;P&gt;Hi @Mohammad Saber​&amp;nbsp;, According to my understanding, the issue is complaining about some of the columns in the delta table(where you are writing to) having ';{}()\n\t=' in the column names. You need to change the reader and writer versions of the delta table to be able to 2 and 5 respectively using below command&lt;/P&gt;&lt;P&gt;ALTER TABLE  SET TBLPROPERTIES (&lt;/P&gt;&lt;P&gt;'delta.columnMapping.mode' = 'name',&lt;/P&gt;&lt;P&gt;'delta.minReaderVersion' = '2',&lt;/P&gt;&lt;P&gt;'delta.minWriterVersion' = '5')&lt;/P&gt;</description>
    <pubDate>Fri, 17 Mar 2023 14:31:49 GMT</pubDate>
    <dc:creator>Lakshay</dc:creator>
    <dc:date>2023-03-17T14:31:49Z</dc:date>
    <item>
      <title>How to set properties for a delta table when I want to write a DataFrame?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-set-properties-for-a-delta-table-when-i-want-to-write-a/m-p/7623#M3430</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a PySpark DataFrame with 11 million records. I created the DataFrame on a cluster. It is not saved on DBFS or storage account. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import pyspark.sql.functions as F
from pyspark.sql.functions import col, when, floor, expr, hour, minute, to_timestamp, explode, sequence  
&amp;nbsp;
&amp;nbsp;
# Define start and end datetime for intervals
start_datetime = "1990-01-01 00:00:00"
end_datetime = "2099-12-31 23:55:00"
interval_minutes = 5   # minutes
&amp;nbsp;
&amp;nbsp;
# Create a DataFrame with sequence of intervals
df = spark.range(0, 1).select(
    expr(f"sequence(to_timestamp('{start_datetime}'), to_timestamp('{end_datetime}'), interval {interval_minutes} minutes)").alias("time")
)
&amp;nbsp;
&amp;nbsp;
# Explode the sequence column to create individual intervals
df = df.select(explode(col("time")).alias("time"))
&amp;nbsp;
&amp;nbsp;
# Create a DataFrame with sequence of intervals
df = spark.range(0, 1).select(
    expr(f"sequence(to_timestamp('{start_datetime}'), to_timestamp('{end_datetime}'), interval {interval_minutes} minutes)").alias("time")
)
&amp;nbsp;
&amp;nbsp;
# Explode the sequence column to create individual intervals
df = df.select(explode(col("time")).alias("time"))
&amp;nbsp;
&amp;nbsp;
# add a new column with interval_period
df = df.withColumn('Interval_Period', interval_period)
df = df.withColumn('Interval_Date', F.to_date(F.col("time")))
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;When I want to write in on Storage Account as a Delta table by:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df.write \
&amp;nbsp;
 .format("delta") \
&amp;nbsp;
 .mode("overwrite") \
&amp;nbsp;
 .option("path", "table_path") \
&amp;nbsp;
 .saveAsTable("my_table")  # External table&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I get the error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;AnalysisException: Found invalid character(s) among ' ,;{}()\n\t=' in the column names of your schema. 
Please upgrade your Delta table to reader version 2 and writer version 5
and change the column mapping mode to 'name' mapping. You can use the following command:
&amp;nbsp;
ALTER TABLE  SET TBLPROPERTIES (
   'delta.columnMapping.mode' = 'name',
   'delta.minReaderVersion' = '2',
   'delta.minWriterVersion' = '5')
Refer to table versioning at &lt;A href="https://docs.microsoft.com/azure/databricks/delta/versioning" target="test_blank"&gt;https://docs.microsoft.com/azure/databricks/delta/versioning&lt;/A&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is how I can set those properties. Not that I don't have a delta table. What I have is a DataFrame created on a cluster. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get the error when I want t write files to the table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 12:02:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-set-properties-for-a-delta-table-when-i-want-to-write-a/m-p/7623#M3430</guid>
      <dc:creator>Mado</dc:creator>
      <dc:date>2023-03-16T12:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to set properties for a delta table when I want to write a DataFrame?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-set-properties-for-a-delta-table-when-i-want-to-write-a/m-p/7624#M3431</link>
      <description>&lt;P&gt;Hi @Mohammad Saber​&amp;nbsp;, Are you getting the error while writing the file to the table? Or before that?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 12:57:04 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-set-properties-for-a-delta-table-when-i-want-to-write-a/m-p/7624#M3431</guid>
      <dc:creator>Lakshay</dc:creator>
      <dc:date>2023-03-16T12:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to set properties for a delta table when I want to write a DataFrame?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-set-properties-for-a-delta-table-when-i-want-to-write-a/m-p/7625#M3432</link>
      <description>&lt;P&gt;Hi @Lakshay Goel​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get the error when I want to write files to the table. &lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 21:38:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-set-properties-for-a-delta-table-when-i-want-to-write-a/m-p/7625#M3432</guid>
      <dc:creator>Mado</dc:creator>
      <dc:date>2023-03-16T21:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to set properties for a delta table when I want to write a DataFrame?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-set-properties-for-a-delta-table-when-i-want-to-write-a/m-p/7626#M3433</link>
      <description>&lt;P&gt;Hi @Mohammad Saber​&amp;nbsp;, According to my understanding, the issue is complaining about some of the columns in the delta table(where you are writing to) having ';{}()\n\t=' in the column names. You need to change the reader and writer versions of the delta table to be able to 2 and 5 respectively using below command&lt;/P&gt;&lt;P&gt;ALTER TABLE  SET TBLPROPERTIES (&lt;/P&gt;&lt;P&gt;'delta.columnMapping.mode' = 'name',&lt;/P&gt;&lt;P&gt;'delta.minReaderVersion' = '2',&lt;/P&gt;&lt;P&gt;'delta.minWriterVersion' = '5')&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 14:31:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-set-properties-for-a-delta-table-when-i-want-to-write-a/m-p/7626#M3433</guid>
      <dc:creator>Lakshay</dc:creator>
      <dc:date>2023-03-17T14:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to set properties for a delta table when I want to write a DataFrame?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-set-properties-for-a-delta-table-when-i-want-to-write-a/m-p/7627#M3434</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found that I should create a table first using the above properties, and then I write Dataframe to the table. &lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 23:19:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-set-properties-for-a-delta-table-when-i-want-to-write-a/m-p/7627#M3434</guid>
      <dc:creator>Mado</dc:creator>
      <dc:date>2023-03-17T23:19:10Z</dc:date>
    </item>
  </channel>
</rss>

