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: 

Maintaining Custom State in Structured Streaming

Starki
New Contributor II

I am consuming an IoT stream with thousands of different signals using Structured Streaming. During processing of the stream, I need to know the previous timestamp and value for each signal in the micro batch. The signal stream is eventually written to a delta table. Every signal is expected to be sent at least once every hour.

Is it possible to make use of the internal State Store as a cache to store this custom state of the previous timestamp and value for each signal?

If not, what would be the canonical approach to maintain such a state?

These are the approaches that I can think of.

Approach 1:

Perform a join on the stream with the target table itself to get the previous signal timestamp and value.

Approach 2:

Maintain a separate ‘state table’ containing the previous timestamp and value for each signal. The ‘state table’ would then be joined with the stream to get the previous signal timestamp and value.

On receiving new signal values, the ‘state table’ would be updated using merge into.

1 REPLY 1

Soma
Valued Contributor

@Suteja Kanuri​ 

Tried the above on streaming DF

But facing the below error

AttributeError: 'DataFrame' object has no attribute 'groupByKey'

Can you please let me know DBR runtime

Join 100K+ Data Experts: Register Now & Grow with Us!

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!