3 weeks ago
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?
3 weeks ago - last edited 3 weeks ago
@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:
3 weeks ago
Hello @Kutbuddin,
Can you share more details? Any source code example?
3 weeks ago
Sharing code example:
1. Read stream from mongo
2. Write stream to delta table.
3. Insert into a internal checkpoint table.
3 weeks ago
@Kutbuddin What are you expecting to achieve? which variable is off and why?
3 weeks ago
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.
3 weeks ago - last edited 3 weeks ago
@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:
Excited to expand your horizons with us? Click here to Register and begin your journey to success!
Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!