Record Class LoomSqlResult
java.lang.Object
java.lang.Record
com.loomcache.client.LoomSqlResult
public record LoomSqlResult(List<String> columnNames, List<List<@Nullable Object>> rows, boolean truncated)
extends Record
Client-side SQL query result.
Wraps the response from a SQL query executed on the cluster, providing access to column metadata and result rows. All operations are thread-safe.
Result Structure
A SQL result consists of:
- Column names — the names of columns in the result set
- Rows — a list of rows, where each row is a list of values
- Truncation — whether the server safety cap cut the result set short
Thread Safety
This class is thread-safe. Multiple threads may safely iterate over rows and access column metadata concurrently.Usage Example
LoomClient client = LoomClient.builder()
.addSeed("127.0.0.1:5701")
.build();
client.connect();
LoomSqlResult result = client.sql("SELECT * FROM users WHERE age > 18");
// Get column names
List<String> columns = result.columnNames();
// [user_id, name, age, email]
// Values returned by client.sql(...) are portable wire-format values.
// Numeric and temporal SQL values are stringified; SQL NULL is preserved as null.
for (List<@Nullable Object> row : result.rows()) {
@Nullable String userId = (String) row.get(0);
@Nullable String name = (String) row.get(1);
@Nullable String ageText = (String) row.get(2);
if (ageText != null) {
long age = Long.parseLong(ageText);
// Process row
}
}
- Since:
- 1.4
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintGets the number of columns in the result set.Gets the column names from the result set.final booleanIndicates whether some other object is "equal to" this one.static LoomSqlResultfromWireFormat(Map<String, @Nullable Object> wireMap) Creates aLoomSqlResultfrom the portable wire format used by the server (aMapwith "columnNames" and "rows" keys), where row cells are stringified values ornull.intgetColumnIndex(String columnName) Gets the index of a column by its name.getColumnName(int columnIndex) Gets the name of the column at the specified index.getRow(int rowIndex) Gets a specific row from the result set.@Nullable ObjectgetValue(int rowIndex, int columnIndex) Gets a specific value from the result set.@Nullable ObjectGets a specific value from the result set by column name.final inthashCode()Returns a hash code value for this object.booleanisEmpty()Checks if the result set is empty (contains no rows).introwCount()Gets the number of rows in the result set.rows()Gets the result rows.final StringtoString()Returns a string representation of this record class.booleanReturns the value of thetruncatedrecord component.
-
Constructor Details
-
LoomSqlResult
public LoomSqlResult(@Nullable List<String> columnNames, @Nullable List<List<@Nullable Object>> rows) Creates a new SQL result with the given column names and rows.- Parameters:
columnNames- the names of columns in the result set (may be null, will use empty list)rows- the result rows, where each row is a list of values that may include SQL NULLs. For results returned byclient.sql(...), cells are portable wire-formatStringinstances ornull. (may be null, will use empty list)
-
LoomSqlResult
public LoomSqlResult(@Nullable List<String> columnNames, @Nullable List<List<@Nullable Object>> rows, boolean truncated) Creates a new SQL result with the given column names, rows, and truncation flag.- Parameters:
columnNames- the names of columns in the result set (may be null, will use empty list)rows- the result rows, where each row is a list of values that may include SQL NULLs. For results returned byclient.sql(...), cells are portable wire-formatStringinstances ornull. (may be null, will use empty list)truncated- true when the server safety cap cut the result set short
-
-
Method Details
-
columnNames
-
rows
Gets the result rows.Each row is represented as an immutable list of values that may include SQL
NULL. For results returned byclient.sql(...), the portable wire format carries non-null cell values asStringinstances rather than preserving their original server-side SQL types.- Returns:
- an immutable list of rows, where each row is a list of values that may include SQL NULLs;
for results returned by
client.sql(...), non-null cells areStringinstances
-
columnCount
public int columnCount()Gets the number of columns in the result set.- Returns:
- the number of columns
-
rowCount
public int rowCount()Gets the number of rows in the result set.- Returns:
- the number of rows
-
isEmpty
public boolean isEmpty()Checks if the result set is empty (contains no rows).- Returns:
- true if there are no rows; false otherwise
-
getRow
Gets a specific row from the result set.- Parameters:
rowIndex- the zero-based row index- Returns:
- the row as an immutable list of values, which may include SQL NULLs;
for results returned by
client.sql(...), cells areStringinstances ornull - Throws:
IndexOutOfBoundsException- if the row index is out of range
-
getValue
Gets a specific value from the result set.- Parameters:
rowIndex- the zero-based row indexcolumnIndex- the zero-based column index- Returns:
- the value at the specified row and column, or
nullfor SQL NULL; for results returned byclient.sql(...), non-null values areStringinstances - Throws:
IndexOutOfBoundsException- if either index is out of range
-
getValue
Gets a specific value from the result set by column name.- Parameters:
rowIndex- the zero-based row indexcolumnName- the name of the column- Returns:
- the value at the specified row and column, or
nullfor SQL NULL; for results returned byclient.sql(...), non-null values areStringinstances - Throws:
IndexOutOfBoundsException- if the row index is out of rangeIllegalArgumentException- if the column name is not found
-
getColumnName
Gets the name of the column at the specified index.- Parameters:
columnIndex- the zero-based column index- Returns:
- the column name
- Throws:
IndexOutOfBoundsException- if the column index is out of range
-
getColumnIndex
Gets the index of a column by its name.- Parameters:
columnName- the name of the column- Returns:
- the zero-based column index; -1 if not found
-
fromWireFormat
Creates aLoomSqlResultfrom the portable wire format used by the server (aMapwith "columnNames" and "rows" keys), where row cells are stringified values ornull.- Parameters:
wireMap- the deserialized wire-format map (non-null, entries may be null)- Returns:
- a new
LoomSqlResultwith the extracted data - Throws:
NullPointerException- if wireMap is null
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
truncated
public boolean truncated()Returns the value of thetruncatedrecord component.- Returns:
- the value of the
truncatedrecord component
-