05-27-2024 12:04 AM
We are running a streaming job in databricks with custom streaming logic which consumes a CDC stream from mongo and appends to a delta table, at the end of the streaming job we have a internal checkpointing logic which creates an entry into a table with timestamp of query start.
We are seeing diff in the checkpointing logic insertion time and the time where the query actually finishes.
What could be the reason for this?
Can a diff command taken up for execution before the streaming query finishes?
05-28-2024 11:59 AM - edited 05-28-2024 11:59 AM
@Kutbuddin this is true, streaming queries are asynchronous and won't delay your code execution if not awaited for.
You can see in the example below that right after the query starts, the status is 'Initializing sources':
But when using awaitTermination() the next row of code will only be executed after the query finishes:
05-27-2024 12:32 PM
Hello @Kutbuddin,
Can you share more details? Any source code example?
05-27-2024 08:10 PM
Sharing code example:
1. Read stream from mongo
2. Write stream to delta table.
3. Insert into a internal checkpoint table.
05-28-2024 11:20 AM
@Kutbuddin What are you expecting to achieve? which variable is off and why?
05-28-2024 11:28 AM
I was expecting spark.sql(f"insert into table {internal_tab_name} values({dt})") to execute at the end after the streaming query was written to the table.
What I observed:
The spark sql query spark.sql(f"insert into table {internal_tab_name} values({dt})") for inserting to table was happening before the streaming query could complete. I thought awaitTermination wouldn't be required to be explicitly mentioned here.
05-28-2024 11:59 AM - edited 05-28-2024 11:59 AM
@Kutbuddin this is true, streaming queries are asynchronous and won't delay your code execution if not awaited for.
You can see in the example below that right after the query starts, the status is 'Initializing sources':
But when using awaitTermination() the next row of code will only be executed after the query finishes:
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