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: 

Is it possible to join two aggregated streams of data?

osoucy
New Contributor II

Objective

Within the context of a delta live table, I'm trying to merge two streams aggregation, but run into challenges. Is it possible to achieve such a join?

Context

Assume

- table trades stores a list of trades with their associated time stamps

- table trades_1d sums the value of all the trades on a given day

- table stock_price stores a given stock price at some (non-constant) sampling frequency

- table stock_price_1d averages the stock price over a given day

It would translate to something along those lines

import pyspark.sql.functions as sqlf
 
sdf_trades = spark.readStream.format("delta").table(f"stock_price")
sdf_price = spark.readStream.format("delta").table(f"stock_price")
 
 
w = sqlf.window("timetstamp", "24 hours")
 
sdf_trades_1d = (
    sdf_trades
    .groupby(w)
    .agg(sqlf.sum("trade_value"))
    .withColumn("window_end", sqlf.col("window.end"))
    .withColumn("window_start", sqlf.col("window.start"))
)
                
sdf_price_1d = (
    sdf_price
    .groupby(w)
    .agg(sqlf.avg("value"))
    .withColumn("window_end", sqlf.col("window.end"))
    .withColumn("window_start", sqlf.col("window.start"))
).withWatermark("window_end", "48 hours")
 
sdf = sdf_trades_1d.join(sdf_price_1d, "window_end", "left")

Issue

When running the pseudo code above, I get

"Append more error: Multiple streaming aggregations are not supported with stream DataFrames/Datasets"

Any suggestion on how I can make this work?

0 REPLIES 0

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