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 compute difference over time of a spark structure streaming?

chanansh
Contributor

I have a table with a timestamp column (t) and a list of columns for which I would like to compute the difference over time (v), by some key(k): v_diff(t) = v(t)-v(t-1) for each k independently.

Normally I would write:

lag_window = Window.partitionBy(COLS_TO_DIFF).orderBy('timestamp')
 
for col in COLS_TO_DIFF:
  df = df.withColumn(
    col + "_diff",
    df[col] - F.lag(df[col]).over(lag_window))

But

AnalysisException: Non-time-based windows are not supported on streaming DataFrames/Datasets;

So, my question is how do I compute what I need?

2 REPLIES 2

chanansh
Contributor

I asked it also in Stack-overflow since I don't get an answer here https://stackoverflow.com/questions/75161849/spark-structure-streaming-differentiate-over-time

chanansh
Contributor

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