This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.
trigger(availableNow = True)
This trigger option processes all data currently available (files visible at start or discovered during the run) as a sequence of micro‑batches, then stops automatically which is perfect for catch‑ups, daily slices, or “drain the backlog” jobs.In Microsoft Fabric, using streaming for batch via availableNow can lower CU consumption compared to always‑on streaming (since compute isn’t permanently running).
Putting it all together in the code sample below .This can be created as a Fabric Notebook and scheduled using Fabric Pipelines
# Define your schema
from pyspark.sql.types import StructField,StructType,StringType,IntegerType,FloatType
file_location = <full file path>
checkpoint_location = <checkpoint path>
data_schema = StructType([
StructField("vendor_id", StringType(), True),
StructField("rate_code", IntegerType(), True),
StructField("passenger_count", IntegerType(), True),
StructField("trip_time_in_secs",IntegerType(),True),
StructField("trip_distance",FloatType(),True),
StructField("payment_type",StringType(),True),
StructField("fare_amount",FloatType(),True)
# Add all your columns here
])
df_stream = (
myspark.readStream
.format("csv")
.option("Header",True)
.schema(data_schema)
.load(f"{file_location}/*.csv")
)
def write_to_table(batch_df,batch_id):
batch_df.write.mode("append").saveAsTable("taxi_data_stream_triggermode")
query=(
df_stream.writeStream
.foreachBatch(write_to_table)
.option("checkpointLocation",f"{checkpoint_location}/")
.trigger(availableNow=True)
.start()
)
print(query.status)
print(query.recentProgress)
Have you used or encountered specific use-case of structured streaming do comment on the post and share the knowledge with the wider community.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.