Package dev.frostlake.metastore.model
Class Stream
java.lang.Object
dev.frostlake.metastore.model.Stream
Represents a Snowflake Stream - Change Data Capture (CDC) mechanism
Streams record DML changes (INSERT, UPDATE, DELETE) made to a table
-
Constructor Summary
ConstructorsConstructorDescriptionStream(String name, String sourceTableName, StreamSourceType sourceType, StreamType streamType, boolean showInitialRows) Stream(String name, String sourceTableName, StreamType streamType) Stream(String name, String sourceTableName, StreamType streamType, boolean showInitialRows) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRecord(StreamRecord record) voidconsume()voidconsumeSeen(long committedCut, List<StreamRecord> seenTransient) Consume exactly what a reader SAW, not everything present at commit: advance past the committed prefix visible at read time (committedCutrecords) and remove the records this transaction's commit re-emitted for changes that were already buffered when the read happened (seenTransient— matched by change kind, values and capture tag, at or after the cut).First base table, or null if none — kept for callers and persistence that assume a single table.All base tables backing a VIEW-sourced stream (one per UNION ALL branch); empty for table streams.longgetName()getOwner()getUnconsumedAppendsWith(List<StreamRecord> extraRaw) The unconsumed records that APPENDED a row, in the order the appends happened, with the values each row was appended WITH — the append-only view of the change window.intThe unconsumed change records consolidated to the NET delta per logical row, which is what a SELECT from a stream returns in Snowflake: a row inserted then updated inside the window is a single INSERT of its final image (ISUPDATE false); inserted then deleted cancels out entirely; a pre-existing row updated repeatedly nets to one DELETE(original)+INSERT(final) pair (ISUPDATE true); updated then deleted nets to a plain DELETE of the original image.getUnconsumedNetRecordsWith(List<StreamRecord> extraRaw) The net unconsumed records asgetUnconsumedNetRecords(), but withextraRawtransient change records (e.g. the current transaction's not-yet-committed base-table changes) folded in AFTER the committed unconsumed ones, so a stream read inside a transaction reflects that transaction's own uncommitted DML — the deferred-apply equivalent of read-your-writes for streams.static booleanisAppend(StreamRecord record) Whether a change record APPENDED a row: an INSERT that no UPDATE produced.booleanbooleanisStale()longTotal records ever captured (consumed + unconsumed) — the read-time cut for scoped consumption.voidreset()voidsetBaseTableName(String baseTableName) voidsetBaseTableNames(List<String> names) voidsetComment(String comment) voidvoidsetStale(boolean stale)
-
Constructor Details
-
Stream
-
Stream
-
Stream
public Stream(String name, String sourceTableName, StreamSourceType sourceType, StreamType streamType, boolean showInitialRows)
-
-
Method Details
-
isAppend
Whether a change record APPENDED a row: an INSERT that no UPDATE produced. The insert half of an update pair carries the same change type and is deliberately not an append — live-verified, a row that already existed contributes nothing to an append-only view however often it is rewritten. -
addRecord
-
getUnconsumedRecords
-
getUnconsumedNetRecords
The unconsumed change records consolidated to the NET delta per logical row, which is what a SELECT from a stream returns in Snowflake: a row inserted then updated inside the window is a single INSERT of its final image (ISUPDATE false); inserted then deleted cancels out entirely; a pre-existing row updated repeatedly nets to one DELETE(original)+INSERT(final) pair (ISUPDATE true); updated then deleted nets to a plain DELETE of the original image. Logical rows are chained by value image (an update pair's DELETE half matches the entry whose current image it removes), since change records carry per-operation — not per-row — ids. APPEND_ONLY streams record only true INSERTs, so they are returned as-is. -
getUnconsumedNetRecordsWith
The net unconsumed records asgetUnconsumedNetRecords(), but withextraRawtransient change records (e.g. the current transaction's not-yet-committed base-table changes) folded in AFTER the committed unconsumed ones, so a stream read inside a transaction reflects that transaction's own uncommitted DML — the deferred-apply equivalent of read-your-writes for streams. The extras are never added to the stream, so a rollback (which just discards the write set) needs no undo here. Extras that anaddRecord(dev.frostlake.metastore.model.StreamRecord)would drop (an APPEND_ONLY stream keeps only true INSERTs) are filtered the same way before consolidation. -
getUnconsumedAppendsWith
The unconsumed records that APPENDED a row, in the order the appends happened, with the values each row was appended WITH — the append-only view of the change window.This is not the net delta filtered to its inserts, and the difference is visible three ways, all live-verified: a row inserted and then updated inside the window reports the value it was inserted with rather than its current one; a row inserted and then deleted inside the window is still reported, because a later delete does not un-append it; and a row that already existed reports nothing however it is rewritten, because rewriting is not appending.
extraRawfolds in transient records the same waygetUnconsumedNetRecordsWith(java.util.List<dev.frostlake.metastore.model.StreamRecord>)does. -
consume
public void consume() -
recordCount
public long recordCount()Total records ever captured (consumed + unconsumed) — the read-time cut for scoped consumption. -
consumeSeen
Consume exactly what a reader SAW, not everything present at commit: advance past the committed prefix visible at read time (committedCutrecords) and remove the records this transaction's commit re-emitted for changes that were already buffered when the read happened (seenTransient— matched by change kind, values and capture tag, at or after the cut). Records appended after the read — by another transaction, or by this transaction's own LATER DML — stay unconsumed. This mirrors Snowflake, where the common flush-then-load procedure pattern runs each statement in its own autocommit transaction: a mid-procedure stream flush must not consume rows the procedure inserts after it. -
reset
public void reset() -
getBaseTableName
First base table, or null if none — kept for callers and persistence that assume a single table. -
setBaseTableName
-
getBaseTableNames
All base tables backing a VIEW-sourced stream (one per UNION ALL branch); empty for table streams. -
setBaseTableNames
-
getName
-
getOwner
-
setOwner
-
getSourceTableName
-
getSourceType
-
getStreamType
-
isShowInitialRows
public boolean isShowInitialRows() -
getRecords
-
getCreatedAt
-
getCurrentOffset
public long getCurrentOffset() -
isStale
public boolean isStale() -
setStale
public void setStale(boolean stale) -
getUnconsumedCount
public int getUnconsumedCount() -
getComment
-
setComment
-