cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to limit number of files in each batch in streaming batch processing

sanjay
Valued Contributor II

Hi,

I am running batch job which processes incoming files. I am trying to limit number of files in each batch process so added maxFilesPerTrigger option. But its not working. It processes all incoming files at once.

(spark.readStream.format("delta").load(silver_path)

.writeStream

.option("checkpointLocation", gold_checkpoint_path)

.option("maxFilesPerTrigger", 200)

.trigger(once=True)

.foreachBatch(foreachBatchFunction)

.start()

.awaitTermination()

)

Please suggest.

Regards,

Sanjay

20 REPLIES 20

Sandeep
Contributor III

@Sanjay Jain​ , inside your gold_checkpoint_path, there are a few subfolders.

Go to "commits" and check which is the latest file inside (You can see files named 1,2,3,4,.....50,51 so on. File named with the highest number is the latest one. Assume it is 60 for example. This means micro batch 60 is committed. If no batch is committed yet, you will see no files).

And then check for files inside "offsets" folder. see the latest one in that folder too. That will in almost all cases you will see a file with name = latest batchID found in commits + 1 (61 as per this example. If there were no files at all inside commits, then you will see a file named "0" inside this folder.). And If you see this behavior, take a backup of this latest file and then delete it. Then restart the job. This should help!

sanjay
Valued Contributor II

This seems to be manual step, Is there any way I can this automatically like reprocess the file if any updates are made on that particular file.

-werners-
Esteemed Contributor III

that sounds more like the change data feed functionality of delta lake.

https://learn.microsoft.com/en-us/azure/databricks/delta/delta-change-data-feed

Anonymous
Not applicable

Hi @Sanjay Jain​ 

Hope everything is going great.

Just wanted to check in if you were able to resolve your issue. If yes, would you be happy to mark an answer as best so that other members can find the solution more quickly? If not, please tell us so we can help you. 

Cheers!

sanjay
Valued Contributor II

Hi Vidula,

Above solutions are not working. Please suggest any other solution.

Regards,

Sanjay

Sandeep
Contributor III

@Sanjay Jain​ sorry missed one thing. .trigger(once=True)​ doesn't support rate limiters. You can use .trigger(availableNow=True)​ instead.

ref: https://docs.databricks.com/structured-streaming/triggers.html#configuring-incremental-batch-process...

spark.readStream.format("delta")

.option("maxFilesPerTrigger", 200)

.load(silver_path)

.writeStream

.option("checkpointLocation", gold_checkpoint_path)

.trigger(availableNow=True)

.foreachBatch(foreachBatchFunction)

.start()

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group