<?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 Genrated partition column not being used by optimizer in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/genrated-partition-column-not-being-used-by-optimizer/m-p/16249#M10455</link>
    <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt; We have created a table using the new generated column feature (https://docs.microsoft.com/en-us/azure/databricks/delta/delta-batch#deltausegeneratedcolumns)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;CREATE TABLE ingest.MyEvent(
 data  binary,
 topic string,
 timestamp timestamp,
 date date GENERATED ALWAYS AS (CAST(timestamp AS DATE))
)
USING DELTA
PARTITIONED BY (topic,date)
LOCATION '/mnt/data/myevent'
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When running&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT * FROM WHERE timestamp &amp;gt; '2021-06-01T12:34'
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;
We were expecting it to push down a filter "date &amp;gt;= '2021-06-01'" so that it can make use of the partitioned column without having to explicit query it. However it does not push down a filter on date, so doesn't benefit from partition filtering&lt;/P&gt;&lt;P&gt;
Is it expected that generated columns would be used to optimize queries? Is it possible to make generated columns work the way i'm expecting or am I expecting too much?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Aug 2021 16:16:57 GMT</pubDate>
    <dc:creator>AlexDavies</dc:creator>
    <dc:date>2021-08-19T16:16:57Z</dc:date>
    <item>
      <title>Genrated partition column not being used by optimizer</title>
      <link>https://community.databricks.com/t5/data-engineering/genrated-partition-column-not-being-used-by-optimizer/m-p/16249#M10455</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt; We have created a table using the new generated column feature (https://docs.microsoft.com/en-us/azure/databricks/delta/delta-batch#deltausegeneratedcolumns)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;CREATE TABLE ingest.MyEvent(
 data  binary,
 topic string,
 timestamp timestamp,
 date date GENERATED ALWAYS AS (CAST(timestamp AS DATE))
)
USING DELTA
PARTITIONED BY (topic,date)
LOCATION '/mnt/data/myevent'
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When running&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT * FROM WHERE timestamp &amp;gt; '2021-06-01T12:34'
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;
We were expecting it to push down a filter "date &amp;gt;= '2021-06-01'" so that it can make use of the partitioned column without having to explicit query it. However it does not push down a filter on date, so doesn't benefit from partition filtering&lt;/P&gt;&lt;P&gt;
Is it expected that generated columns would be used to optimize queries? Is it possible to make generated columns work the way i'm expecting or am I expecting too much?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 16:16:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/genrated-partition-column-not-being-used-by-optimizer/m-p/16249#M10455</guid>
      <dc:creator>AlexDavies</dc:creator>
      <dc:date>2021-08-19T16:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: Genrated partition column not being used by optimizer</title>
      <link>https://community.databricks.com/t5/data-engineering/genrated-partition-column-not-being-used-by-optimizer/m-p/16250#M10456</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I think you have to pass a date in your select query instead of a timestamp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;The generated column will indeed derive a data from the timestamp and partition by it.
&lt;P&gt;But the docs state:&lt;/P&gt;
&lt;P&gt;&lt;I&gt;When you &lt;B&gt;write&lt;/B&gt; to a table with generated columns and you do not explicitly provide values for them, Delta Lake automatically computes the values.&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;So the date column will be filled while writing. But afaik it is not the case with reading.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;So "Select timestamp" will not be translated to "Select date".&lt;P&gt;&lt;/P&gt;When you query on the timestamp column, spark will read the timestamp column, and the table is not partitioned on this.&lt;P&gt;&lt;/P&gt;try this f.e.:
&lt;PRE&gt;&lt;CODE&gt;SELECT * FROM WHERE date  = '2021-06-01'&lt;/CODE&gt;&lt;/PRE&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 09:30:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/genrated-partition-column-not-being-used-by-optimizer/m-p/16250#M10456</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2021-08-23T09:30:44Z</dc:date>
    </item>
  </channel>
</rss>

