<?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: Pyspark Create a ProcessedFiles. Update the flag but I then can't resave OR then view the original P in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4095240#M3562</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="76077" data-lia-user-login="DebbieE" class="lia-mention lia-mention-user"&gt;DebbieE&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was interested in your question and reproduced your error. I am not entirely sure but I assume that the behaviour has something to do with the way spark processes data and keeps track of the schema of each dataframe and where it comes from. In your case I would assume that there is some kind of circular dependency of the schema you are overwritting to the original schema of the file and that is why spark runs into that error - but as I said, pretty unsure about that and actually just an assumption.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nevertheless I was able to at least come up with a solution/ workaround:&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the exact reason of different versions (in terms of schema-versions) of the parquet-file it seems obvious to use delta instead of parquet. So spark can keep track of the originally read schema while creating a newer version of the file since the "older" version is still kept in the lakehouse.&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;dflog_delta = spark.read.format('delta').load("Tables/" + delta_table_name)&lt;BR /&gt;&lt;BR /&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; pyspark.sql.functions &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; lit&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df_Processed_delta = dflog_delta.select(&lt;/SPAN&gt;&lt;SPAN&gt;"filename"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;"processedTime"&lt;/SPAN&gt;&lt;SPAN&gt;).withColumn(&lt;/SPAN&gt;&lt;SPAN&gt;"fullyProcessedFlag"&lt;/SPAN&gt;&lt;SPAN&gt;,lit(&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;df_Processed_delta.write.mode(&lt;/SPAN&gt;&lt;SPAN&gt;"overwrite"&lt;/SPAN&gt;&lt;SPAN&gt;).option(&lt;/SPAN&gt;&lt;SPAN&gt;"overwriteSchema"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"true"&lt;/SPAN&gt;&lt;SPAN&gt;)\&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.format(&lt;/SPAN&gt;&lt;SPAN&gt;'delta'&lt;/SPAN&gt;&lt;SPAN&gt;).saveAsTable(delta_table_name)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"Delta file overwritten successfully."&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this solution works for you. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Martin&lt;/P&gt;</description>
    <pubDate>Mon, 12 Aug 2024 10:56:52 GMT</pubDate>
    <dc:creator>Hofpower</dc:creator>
    <dc:date>2024-08-12T10:56:52Z</dc:date>
    <item>
      <title>Pyspark Create a ProcessedFiles. Update the flag but I then can't resave OR then view the original P</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4091535#M3514</link>
      <description>&lt;P&gt;I have a CurrentProcessed.parquet file containing&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;filename: string (nullable = true)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;processedTime: timestamp (nullable = true)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;fullyProcessedFlag: integer (nullable = true)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And throughout the process the flag is 0. At the end I create a dataframe of the three rows in the parquet file and then set the flag to 1. Processed.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from pyspark.sql.functions import lit
# Update the fullyProcessedFlag column to 1 for all rows
df_Processed = dflog.select("filename","processedTime").withColumn("fullyProcessedFlag",lit(1))

display(df_Processed)&lt;/LI-CODE&gt;&lt;P&gt;there is a slight change to the schema&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;fullyProcessedFlag: integer (nullable = false)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I then overwrite the parquet file with the new data. All processed&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;workspace_id = "########-####-####-####-############"
lakehouse_id = "########-####-####-####-############"

df_Processed.write.mode("overwrite").option("overwriteSchema", "true")\
.parquet(f"abfss://{workspace_id}@onelake.dfs.fabric.microsoft.com/{lakehouse_id}/Files/Data/Silver/Log/ProcessedFiles.parquet")

# Print a success message
print("Parquet file overwritten successfully.")&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;And it errors. It removes the files from the parquet folder and leaves the folder empty.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;With the error&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Caused by: org.apache.spark.SparkFileNotFoundException: Operation failed: "Not Found", 404, HEAD, It is possible the underlying files have been updated. You can explicitly invalidate the cache in Spark by running 'REFRESH TABLE tableName' command in SQL or by recreating the Dataset/DataFrame involved.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am at a complete loss with this and its now a blocker. I can't get past it so cant close my run off by resetting the flag in the parquet file.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can anyone see what I am doing wrong in the code? could the slight schema change to nullable = false be causing the issue (I can't sort this out either and change it to true)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2024 11:12:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4091535#M3514</guid>
      <dc:creator>DebbieE</dc:creator>
      <dc:date>2024-08-09T11:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: Pyspark Create a ProcessedFiles. Update the flag but I then can't resave OR then view the original P</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4095058#M3561</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="76077" data-lia-user-login="DebbieE" class="lia-mention lia-mention-user"&gt;DebbieE&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I reproduced the same error when trying to update a parquet file with your method. However I haven't figured out a solution yet. Still need some time to&amp;nbsp;work on this, as I'm new to Spark and not very experienced by now.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Jing&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2024 09:45:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4095058#M3561</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-12T09:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Pyspark Create a ProcessedFiles. Update the flag but I then can't resave OR then view the original P</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4095240#M3562</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="76077" data-lia-user-login="DebbieE" class="lia-mention lia-mention-user"&gt;DebbieE&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was interested in your question and reproduced your error. I am not entirely sure but I assume that the behaviour has something to do with the way spark processes data and keeps track of the schema of each dataframe and where it comes from. In your case I would assume that there is some kind of circular dependency of the schema you are overwritting to the original schema of the file and that is why spark runs into that error - but as I said, pretty unsure about that and actually just an assumption.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nevertheless I was able to at least come up with a solution/ workaround:&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the exact reason of different versions (in terms of schema-versions) of the parquet-file it seems obvious to use delta instead of parquet. So spark can keep track of the originally read schema while creating a newer version of the file since the "older" version is still kept in the lakehouse.&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;dflog_delta = spark.read.format('delta').load("Tables/" + delta_table_name)&lt;BR /&gt;&lt;BR /&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; pyspark.sql.functions &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; lit&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df_Processed_delta = dflog_delta.select(&lt;/SPAN&gt;&lt;SPAN&gt;"filename"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;"processedTime"&lt;/SPAN&gt;&lt;SPAN&gt;).withColumn(&lt;/SPAN&gt;&lt;SPAN&gt;"fullyProcessedFlag"&lt;/SPAN&gt;&lt;SPAN&gt;,lit(&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;df_Processed_delta.write.mode(&lt;/SPAN&gt;&lt;SPAN&gt;"overwrite"&lt;/SPAN&gt;&lt;SPAN&gt;).option(&lt;/SPAN&gt;&lt;SPAN&gt;"overwriteSchema"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"true"&lt;/SPAN&gt;&lt;SPAN&gt;)\&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.format(&lt;/SPAN&gt;&lt;SPAN&gt;'delta'&lt;/SPAN&gt;&lt;SPAN&gt;).saveAsTable(delta_table_name)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"Delta file overwritten successfully."&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this solution works for you. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Martin&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2024 10:56:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4095240#M3562</guid>
      <dc:creator>Hofpower</dc:creator>
      <dc:date>2024-08-12T10:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: Pyspark Create a ProcessedFiles. Update the flag but I then can't resave OR then view the original P</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4115511#M3745</link>
      <description>&lt;P&gt;I dont want to do that. I want to have everything in the one file. Because otherwise it will get really confusing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I still want to see the old data in the latest file with 0 as processed in the latest.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2024 11:19:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4115511#M3745</guid>
      <dc:creator>DebbieE</dc:creator>
      <dc:date>2024-08-23T11:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: Pyspark Create a ProcessedFiles. Update the flag but I then can't resave OR then view the original P</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4116710#M3756</link>
      <description>&lt;P&gt;I think you could still use a delta table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don't want to overwrite the information in the table, perhaps you could update or upsert instead?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.delta.io/latest/delta-update.html#update-a-table" target="_blank"&gt;https://docs.delta.io/latest/delta-update.html#update-a-table&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure I fully understand the functionality you are wanting to achieve.&lt;SPAN&gt;&amp;nbsp;Could you show some pictures of what you're wanting to achieve?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please remember don't show any sensitive or internal information.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Aug 2024 07:16:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4116710#M3756</guid>
      <dc:creator>frithjof_v</dc:creator>
      <dc:date>2024-08-24T07:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Pyspark Create a ProcessedFiles. Update the flag but I then can't resave OR then view the original P</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4118255#M3775</link>
      <description>&lt;P&gt;Here is a Reddit thread which discusses a similar topic:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.reddit.com/r/MicrosoftFabric/s/zm1hF16CPz" target="_blank"&gt;https://www.reddit.com/r/MicrosoftFabric/s/zm1hF16CPz&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2024 08:55:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Pyspark-Create-a-ProcessedFiles-Update-the-flag-but-I-then-can-t/m-p/4118255#M3775</guid>
      <dc:creator>frithjof_v</dc:creator>
      <dc:date>2024-08-26T08:55:54Z</dc:date>
    </item>
  </channel>
</rss>

