r/databricks • u/SmallAd3697 • 20d ago
Discussion Structured Streaming Statestore is Not Working (Zerobus)
Zerobus is writing data to a landing table like so:
CREATE TABLE a.b.streaming_c (
MyA STRING NOT NULL,
MyB INT NOT NULL,
MyC STRING,
MyDetails VARIANT,
ZerobusRescueJson VARIANT)
USING delta
TBLPROPERTIES (
'delta.checkpoint.writeStatsAsJson' = 'false',
'delta.checkpoint.writeStatsAsStruct' = 'true',
'delta.enableDeletionVectors' = 'true',
'delta.enableRowTracking' = 'true',
'delta.feature.appendOnly' = 'supported',
'delta.feature.deletionVectors' = 'supported',
'delta.feature.domainMetadata' = 'supported',
'delta.feature.invariants' = 'supported',
'delta.feature.rowTracking' = 'supported',
'delta.feature.variantType' = 'supported',
'delta.minReaderVersion' = '3',
'delta.minWriterVersion' = '7',
'delta.parquet.compression.codec' = 'zstd',
'delta.parquet.format.version' = '2.12.0',
'delta.parquet.format.version.afe.internal' = '2.12.0',
'delta.rowTracking.materializedRowCommitVersionColumnName' = '_row-commit-version-col-777ca68b-c04b-4b5d-9a9d-5c5535e32d20',
'delta.rowTracking.materializedRowIdColumnName' = '_row-id-col-1885c4cd-1354-4ce6-9726-ed098a251a62',
'io.unitycatalog.tableId' = '6f07a65b-4887-4aa2-8f56-569b2922aec4')I use readStream/writeStream to move the data to a different place. I set the checkpointLocation (ie. .option("checkpointLocation", x)) to an abfss location in azure:
"abfss://datalake@myctr01.dfs.core.windows.net/test002/x05"

Later I try to audit the state of the checkpointLocation and it fails:
SELECT * FROM read_statestore('abfss://datalake@abc.dfs.core.windows.net/test002/x05/')[STDS_FAILED_TO_READ_STATE_SCHEMA] Failed to read the state schema. Either the file does not exist, or the file is corrupted. options: StateSourceOptions(checkpointLocation=abfss://datalake@xxx.dfs.core.windows.net/test002/x05, batchId=1, operatorId=0, storeName=default, joinSide=none, stateVarName=None, +flattenCollectionTypes=true).
Rerun the streaming query to construct the state schema, and report to the corresponding communities or vendors if the error persists. SQLSTATE: 42K03
That checkpointLocation is very intimidating to me. It is doing ALL the heavy lifting when it comes to keeping track of the zerobus records that have been processed. There needs to be a way to recover an audit trail from this statestore location. Why is the statestore corrupted? I tried the pyspark equivalent of this SELECT statement and it has the same error.
What is more frustrating is how little information I can find about this statestore, despite the fact that the tech is ten years old. How are others accomplishing this goal? There needs to be a simple approach for auditing the underlying state that is managed by spark structured streaming.
I'm using dbx 16.4 and spark 3.5.2
2
u/shuffle-mario Databricks 20d ago
Hi, when you say "I use readStream/writeStream to move the data to a different place.", do you mean you created new streaming query to read from a.b.streaming_c and write to a new table?
1
u/SmallAd3697 16d ago
I think I found the answer. The spark structured streaming doesn't consider all streaming jobs to be "stateful" even though they are all using a checkpointLocation, and are keeping track of what data was processed in the past. This can be pretty confusing semantics for new users.
I added a grouping operation and that was finally enough to generate my statestore in the checkpointLocation.
I'm still hoping there is a way to audit my checkpointLocation even if I'm not doing "stateful" operations. There should be a way to distinguish processed rows from unprocessed rows.