<?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 DLT: Create Empty Table If Autloader Fails in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/dlt-create-empty-table-if-autloader-fails/m-p/84411#M37190</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am quite new to databricks. Overall I enjoyed the experience so far, but now ran into a problem, I was not able to find an acceptable solution.&lt;/P&gt;&lt;P&gt;Here is my setup: I have a bunch of s3 buckets, and need to put the data into databricks, preferably using a DLT pipeline. Each of the buckets contains a directory with data files, and possibly a directory with error logs, produced by an application. So the structure looks something like this&lt;EM&gt;:&lt;/EM&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;EM&gt;s&lt;/EM&gt;&lt;EM&gt;3://&amp;lt;bucket-name&amp;gt;/data/...&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;s3://&amp;lt;bucket-name&amp;gt;/errors/...&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Creating a DLT-Pipeline to read the data-files was not a problem. Now I wanted to do the same for the errors. The problem is: Some of the buckets do not contain the &lt;EM&gt;/errors&lt;/EM&gt; directory. Therefor the straight forward&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/97035"&gt;@Dlt&lt;/a&gt;.table
def error_table():
    return spark.readStream.options(**options).load("s3://&amp;lt;bucket-name&amp;gt;/errors/")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;does not work, and the complete pipeline will fail on initialization. Thus even the other tables in the pipeline will not update. I want to do the following: If the path does not exist, I instead want to create an empty table (the schema is known).&lt;/P&gt;&lt;P&gt;What I tried so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/97035"&gt;@Dlt&lt;/a&gt;.table
def error_table():
    try:
        return spark.readStream.options(**options).load("s3://&amp;lt;bucket-name&amp;gt;/errors")
    except Exception:
        return spark.createDataframe(data=[], schema=error_schema)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Due to the lazy nature of spark, this does not work (at least for me).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/97035"&gt;@Dlt&lt;/a&gt;.table
def error_table():
    return spark.readStream.options(**options).option("pathGlobFilter", "/errors*").load("s3://&amp;lt;bucket-name&amp;gt;")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This seems to work, &lt;EM&gt;but&lt;/EM&gt; it seems to scan all the data-files. That is quite inefficient, and not acceptable. For me, this took &amp;gt;30min, even when there were no errors.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Aug 2024 14:08:52 GMT</pubDate>
    <dc:creator>DaPo</dc:creator>
    <dc:date>2024-08-27T14:08:52Z</dc:date>
    <item>
      <title>DLT: Create Empty Table If Autloader Fails</title>
      <link>https://community.databricks.com/t5/data-engineering/dlt-create-empty-table-if-autloader-fails/m-p/84411#M37190</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am quite new to databricks. Overall I enjoyed the experience so far, but now ran into a problem, I was not able to find an acceptable solution.&lt;/P&gt;&lt;P&gt;Here is my setup: I have a bunch of s3 buckets, and need to put the data into databricks, preferably using a DLT pipeline. Each of the buckets contains a directory with data files, and possibly a directory with error logs, produced by an application. So the structure looks something like this&lt;EM&gt;:&lt;/EM&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;EM&gt;s&lt;/EM&gt;&lt;EM&gt;3://&amp;lt;bucket-name&amp;gt;/data/...&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;s3://&amp;lt;bucket-name&amp;gt;/errors/...&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Creating a DLT-Pipeline to read the data-files was not a problem. Now I wanted to do the same for the errors. The problem is: Some of the buckets do not contain the &lt;EM&gt;/errors&lt;/EM&gt; directory. Therefor the straight forward&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/97035"&gt;@Dlt&lt;/a&gt;.table
def error_table():
    return spark.readStream.options(**options).load("s3://&amp;lt;bucket-name&amp;gt;/errors/")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;does not work, and the complete pipeline will fail on initialization. Thus even the other tables in the pipeline will not update. I want to do the following: If the path does not exist, I instead want to create an empty table (the schema is known).&lt;/P&gt;&lt;P&gt;What I tried so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/97035"&gt;@Dlt&lt;/a&gt;.table
def error_table():
    try:
        return spark.readStream.options(**options).load("s3://&amp;lt;bucket-name&amp;gt;/errors")
    except Exception:
        return spark.createDataframe(data=[], schema=error_schema)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Due to the lazy nature of spark, this does not work (at least for me).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/97035"&gt;@Dlt&lt;/a&gt;.table
def error_table():
    return spark.readStream.options(**options).option("pathGlobFilter", "/errors*").load("s3://&amp;lt;bucket-name&amp;gt;")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This seems to work, &lt;EM&gt;but&lt;/EM&gt; it seems to scan all the data-files. That is quite inefficient, and not acceptable. For me, this took &amp;gt;30min, even when there were no errors.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 14:08:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/dlt-create-empty-table-if-autloader-fails/m-p/84411#M37190</guid>
      <dc:creator>DaPo</dc:creator>
      <dc:date>2024-08-27T14:08:52Z</dc:date>
    </item>
  </channel>
</rss>

