<?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: GeneratedAlwaysAs' along with dataframe.write in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10883#M5937</link>
    <description>&lt;P&gt;Maybe try something like &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df.createOrReplaceTempView("my_table")
&amp;nbsp;
spark.sql("CREATE TABLE rectangles(
  a INT,
  b INT,
  area INT GENERATED ALWAYS AS (a * b)
);
INSERT INTO rectangles (a, b)
select
  a,
  b
FROM
  my_table)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Jan 2023 13:43:05 GMT</pubDate>
    <dc:creator>Hubert-Dudek</dc:creator>
    <dc:date>2023-01-23T13:43:05Z</dc:date>
    <item>
      <title>GeneratedAlwaysAs' along with dataframe.write</title>
      <link>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10879#M5933</link>
      <description>&lt;P&gt;Is it possible to use a calculated column (as like in the delta table using generatedAlwaysAs) definition while writing the data frame as a delta file like df.write.format("delta").&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any options are there with the dataframe.write method to achieve this ?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 08:41:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10879#M5933</guid>
      <dc:creator>thushar</dc:creator>
      <dc:date>2023-01-23T08:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: GeneratedAlwaysAs' along with dataframe.write</title>
      <link>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10880#M5934</link>
      <description>&lt;P&gt;Hi @Thushar R​ in my knowledge&amp;nbsp;currently we don't have any option in databricks.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 11:05:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10880#M5934</guid>
      <dc:creator>Ajay-Pandey</dc:creator>
      <dc:date>2023-01-23T11:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: GeneratedAlwaysAs' along with dataframe.write</title>
      <link>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10881#M5935</link>
      <description>&lt;P&gt;Yes, you can as GeneratedAlwaysAs is in delta schema, for example, write to the table (which is registered delta as the table).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;df.write.format("delta").mode('append').saveAsTable('TableName')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;some more examples are there &lt;A href="https://docs.delta.io/latest/delta-batch.html" target="test_blank"&gt;https://docs.delta.io/latest/delta-batch.html&lt;/A&gt; there are a lot of ways to achieve that&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DeltaTable.create(spark) \
  .tableName("default.events") \
  .addColumn("eventId", "BIGINT") \
  .addColumn("data", "STRING") \
  .addColumn("eventType", "STRING") \
  .addColumn("eventTime", "TIMESTAMP") \
  .addColumn("year", "INT", generatedAlwaysAs="YEAR(eventTime)") \
  .addColumn("month", "INT", generatedAlwaysAs="MONTH(eventTime)") \
  .addColumn("day", "INT", generatedAlwaysAs="DAY(eventTime)") \
  .partitionedBy("eventType", "year", "month", "day") \
  .execute()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 13:17:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10881#M5935</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2023-01-23T13:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: GeneratedAlwaysAs' along with dataframe.write</title>
      <link>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10882#M5936</link>
      <description>&lt;P&gt;Thanks,  but my ask is whether we have the option to mention the clause 'generatedAlwaysAs' with dataframe.write method?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 13:29:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10882#M5936</guid>
      <dc:creator>thushar</dc:creator>
      <dc:date>2023-01-23T13:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: GeneratedAlwaysAs' along with dataframe.write</title>
      <link>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10883#M5937</link>
      <description>&lt;P&gt;Maybe try something like &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df.createOrReplaceTempView("my_table")
&amp;nbsp;
spark.sql("CREATE TABLE rectangles(
  a INT,
  b INT,
  area INT GENERATED ALWAYS AS (a * b)
);
INSERT INTO rectangles (a, b)
select
  a,
  b
FROM
  my_table)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 13:43:05 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10883#M5937</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2023-01-23T13:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: GeneratedAlwaysAs' along with dataframe.write</title>
      <link>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10884#M5938</link>
      <description>&lt;P&gt;Hi @Thushar R​,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just a friendly follow-up. Did any of the responses help you to resolve your question? if it did, please mark it as best. Otherwise, please let us know if you still need help.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 23:43:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10884#M5938</guid>
      <dc:creator>jose_gonzalez</dc:creator>
      <dc:date>2023-02-24T23:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: GeneratedAlwaysAs' along with dataframe.write</title>
      <link>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10885#M5939</link>
      <description>&lt;P&gt;Hi @Thushar R​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This option is not a part of Dataframe write API as GeneratedAlwaysAs feature is only applicable to Delta format and df.write is a common API to handle writes for all formats. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you to achieve this programmatically, you can still use DeltaTable API to create the table first as below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DeltaTable.create(spark) \&lt;/P&gt;&lt;P&gt;  .tableName("default.events") \&lt;/P&gt;&lt;P&gt;  .addColumn("eventId", "BIGINT") \&lt;/P&gt;&lt;P&gt;  .addColumn("data", "STRING") \&lt;/P&gt;&lt;P&gt;  .addColumn("eventType", "STRING") \&lt;/P&gt;&lt;P&gt;  .addColumn("eventTime", "TIMESTAMP") \&lt;/P&gt;&lt;P&gt;  .addColumn("year", "INT", generatedAlwaysAs="YEAR(eventTime)") \&lt;/P&gt;&lt;P&gt;  .addColumn("month", "INT", generatedAlwaysAs="MONTH(eventTime)") \&lt;/P&gt;&lt;P&gt;  .addColumn("day", "INT", generatedAlwaysAs="DAY(eventTime)") \&lt;/P&gt;&lt;P&gt;  .partitionedBy("eventType", "year", "month", "day") \&lt;/P&gt;&lt;P&gt;  .execute()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 14:27:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/generatedalwaysas-along-with-dataframe-write/m-p/10885#M5939</guid>
      <dc:creator>pvignesh92</dc:creator>
      <dc:date>2023-03-09T14:27:58Z</dc:date>
    </item>
  </channel>
</rss>

