Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Risingwavelabs Risingwave StreamChunkIterator

From Leeroopedia
Revision as of 16:32, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Risingwavelabs_Risingwave_StreamChunkIterator.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Property Value
Component Java Binding
Language Java
Source File java/java-binding/src/main/java/com/risingwave/java/binding/StreamChunkIterator.java
Lines 43
Package com.risingwave.java.binding
License Apache 2.0

Overview

StreamChunkIterator is a Java iterator wrapper for traversing rows within a StreamChunk via JNI calls to the native Rust iterator. It enables row-by-row iteration over StreamChunk data in Java sink connectors and integration tests.

The class creates a native stream chunk iterator from a StreamChunk pointer via Binding.iteratorNewStreamChunk. On each call to next(), it advances the native iterator and returns a StreamChunkRow instance (which extends BaseRow) representing the current row, or null when all rows have been consumed. The class implements AutoCloseable to ensure the native iterator is released via Binding.iteratorClose.

Code Reference

Source Location

java/java-binding/src/main/java/com/risingwave/java/binding/StreamChunkIterator.java

Signature

public class StreamChunkIterator implements AutoCloseable {
    private final long pointer;
    private boolean isClosed;

    public StreamChunkIterator(StreamChunk chunk);
    public StreamChunkRow next();

    @Override
    public void close();
}

Import

import com.risingwave.java.binding.StreamChunkIterator;
// Required for construction:
import com.risingwave.java.binding.StreamChunk;

I/O Contract

Inputs

  • chunk (StreamChunk): A StreamChunk instance whose native pointer is used to create the underlying native iterator via Binding.iteratorNewStreamChunk(chunk.getPointer()).

Outputs

  • next() returns StreamChunkRow: The next row in the stream chunk, or null when no more rows remain. StreamChunkRow extends BaseRow and additionally provides access to the operation type (insert, delete, update_insert, update_delete) via its getOp() method.

Side Effects

  • Native resource allocation: The constructor calls Binding.iteratorNewStreamChunk to create a native Rust iterator over the stream chunk data.
  • Native resource release: close() calls Binding.iteratorClose(pointer) to free the native iterator. The isClosed flag prevents double-close.
  • Iterator advancement: Each call to next() advances the native iterator's cursor position via Binding.iteratorNext.

Usage Examples

Iterating over a StreamChunk

try (StreamChunk chunk = StreamChunk.fromPayload(payload);
     StreamChunkIterator iter = new StreamChunkIterator(chunk)) {

    StreamChunkRow row;
    while ((row = iter.next()) != null) {
        int op = row.getOp();       // Operation type
        int id = row.getInt(0);     // Column 0 as int
        String name = row.getString(1); // Column 1 as string
        // Process the row based on operation type...
    }
}

Using with a pretty-printed test chunk

// Create a test chunk: two integer columns, two rows (one insert, one delete)
try (StreamChunk chunk = StreamChunk.fromPretty("I I\n + 1 10\n - 2 20");
     StreamChunkIterator iter = new StreamChunkIterator(chunk)) {

    StreamChunkRow insertRow = iter.next();
    assert insertRow != null;
    assert insertRow.getInt(0) == 1;
    assert insertRow.getInt(1) == 10;

    StreamChunkRow deleteRow = iter.next();
    assert deleteRow != null;
    assert deleteRow.getInt(0) == 2;
    assert deleteRow.getInt(1) == 20;

    assert iter.next() == null; // No more rows
}

Related Pages

  • StreamChunk - The stream chunk data structure that this iterator traverses
  • BaseRow - Base class for row data access; StreamChunkRow extends BaseRow
  • Binding - Declares iteratorNewStreamChunk, iteratorNext, and iteratorClose native methods
  • HummockIterator - Analogous iterator for Hummock storage data (produces KeyedRow instead of StreamChunkRow)

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment