Implementation:Risingwavelabs Risingwave BaseRow
| Property | Value |
|---|---|
| Component | Java Binding |
| Language | Java |
| Source File | java/java-binding/src/main/java/com/risingwave/java/binding/BaseRow.java
|
| Lines | 103 |
| Package | com.risingwave.java.binding
|
| License | Apache 2.0 |
Overview
BaseRow is the base class for row data access in the RisingWave Java binding layer. It provides typed accessor methods for all data types supported by RisingWave, including primitive types (short, int, long, float, double, boolean), string types, temporal types (timestamp, timestamptz, time, date, interval), decimal, jsonb, bytea, and one-dimensional arrays.
The class holds a native pointer to a Rust-side row structure and delegates every typed accessor to the corresponding JNI native method declared in the Binding class. It serves as the foundation for the row access API, extended by KeyedRow (used with HummockIterator) and StreamChunkRow (used with StreamChunkIterator).
Code Reference
Source Location
java/java-binding/src/main/java/com/risingwave/java/binding/BaseRow.java
Signature
public class BaseRow {
protected final long pointer;
protected BaseRow(long pointer);
public boolean isNull(int index);
public short getShort(int index);
public int getInt(int index);
public long getLong(int index);
public float getFloat(int index);
public double getDouble(int index);
public boolean getBoolean(int index);
public String getString(int index);
public java.time.LocalDateTime getTimestamp(int index);
public java.time.OffsetDateTime getTimestamptz(int index);
public java.time.LocalTime getTime(int index);
public java.math.BigDecimal getDecimal(int index);
public java.time.LocalDate getDate(int index);
public String getInterval(int index);
public String getJsonb(int index);
public byte[] getBytea(int index);
public <T> Object[] getArray(int index, Class<T> clazz);
}
Import
import com.risingwave.java.binding.BaseRow;
I/O Contract
Inputs
- pointer (long): A native pointer to a Rust-side row structure, passed at construction time by subclasses. This pointer is used for all subsequent JNI calls.
- index (int): A zero-based column index passed to each accessor method, identifying which column value to retrieve from the row.
- clazz (Class<T>): For
getArray, the element type class used to determine the array element type on the native side.
Outputs
- Each accessor method returns the corresponding Java type for the column value at the given index:
isNullreturnsbooleanindicating whether the column is nullgetShortreturnsshort(INT16)getIntreturnsint(INT32)getLongreturnslong(INT64)getFloatreturnsfloatgetDoublereturnsdoublegetBooleanreturnsbooleangetStringreturnsString(VARCHAR)getTimestampreturnsjava.time.LocalDateTimegetTimestamptzreturnsjava.time.OffsetDateTimegetTimereturnsjava.time.LocalTimegetDecimalreturnsjava.math.BigDecimalgetDatereturnsjava.time.LocalDategetIntervalreturnsString(e.g.,"2 mons 3 days 00:00:00.000004"or ISO 8601 format)getJsonbreturnsString(JSON string representation)getByteareturnsbyte[]getArrayreturnsObject[](one-dimensional array elements)
Side Effects
- All accessor methods make JNI calls to the Rust side via the
Bindingclass. The native pointer must remain valid for the lifetime of the row object.
Usage Examples
Accessing column values from a KeyedRow
// KeyedRow extends BaseRow, obtained from HummockIterator
try (HummockIterator iter = new HummockIterator(readPlan)) {
KeyedRow row;
while ((row = iter.next()) != null) {
if (!row.isNull(0)) {
int id = row.getInt(0);
String name = row.getString(1);
java.math.BigDecimal amount = row.getDecimal(2);
java.time.LocalDateTime createdAt = row.getTimestamp(3);
}
}
}
Accessing column values from a StreamChunkRow
// StreamChunkRow extends BaseRow, obtained from StreamChunkIterator
try (StreamChunkIterator iter = new StreamChunkIterator(chunk)) {
StreamChunkRow row;
while ((row = iter.next()) != null) {
short smallVal = row.getShort(0);
boolean flag = row.getBoolean(1);
byte[] binaryData = row.getBytea(2);
Object[] arrayCol = row.getArray(3, String.class);
}
}
Related Pages
- Binding - Central JNI native method declarations used by all accessor methods
- HummockIterator - Iterator that produces KeyedRow instances (which extend BaseRow)
- StreamChunkIterator - Iterator that produces StreamChunkRow instances (which extend BaseRow)
- StreamChunk - Native StreamChunk wrapper used with StreamChunkIterator