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
    Constructor
    Description
    LoomSqlResult(@Nullable List<String> columnNames, @Nullable List<List<@Nullable Object>> rows)
    Creates a new SQL result with the given column names and rows.
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the number of columns in the result set.
    Gets the column names from the result set.
    final boolean
    Indicates whether some other object is "equal to" this one.
    fromWireFormat(Map<String, @Nullable Object> wireMap)
    Creates a LoomSqlResult from the portable wire format used by the server (a Map with "columnNames" and "rows" keys), where row cells are stringified values or null.
    int
    getColumnIndex(String columnName)
    Gets the index of a column by its name.
    getColumnName(int columnIndex)
    Gets the name of the column at the specified index.
    List<@Nullable Object>
    getRow(int rowIndex)
    Gets a specific row from the result set.
    @Nullable Object
    getValue(int rowIndex, int columnIndex)
    Gets a specific value from the result set.
    @Nullable Object
    getValue(int rowIndex, String columnName)
    Gets a specific value from the result set by column name.
    final int
    Returns a hash code value for this object.
    boolean
    Checks if the result set is empty (contains no rows).
    int
    Gets the number of rows in the result set.
    List<List<@Nullable Object>>
    Gets the result rows.
    final String
    Returns a string representation of this record class.
    boolean
    Returns the value of the truncated record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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 by client.sql(...), cells are portable wire-format String instances or null. (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 by client.sql(...), cells are portable wire-format String instances or null. (may be null, will use empty list)
      truncated - true when the server safety cap cut the result set short
  • Method Details

    • columnNames

      public List<String> columnNames()
      Gets the column names from the result set.

      The returned list is immutable and will not change.

      Returns:
      an immutable list of column names
    • rows

      public List<List<@Nullable Object>> rows()
      Gets the result rows.

      Each row is represented as an immutable list of values that may include SQL NULL. For results returned by client.sql(...), the portable wire format carries non-null cell values as String instances 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 are String instances
    • 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

      public List<@Nullable Object> getRow(int rowIndex)
      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 are String instances or null
      Throws:
      IndexOutOfBoundsException - if the row index is out of range
    • getValue

      public @Nullable Object getValue(int rowIndex, int columnIndex)
      Gets a specific value from the result set.
      Parameters:
      rowIndex - the zero-based row index
      columnIndex - the zero-based column index
      Returns:
      the value at the specified row and column, or null for SQL NULL; for results returned by client.sql(...), non-null values are String instances
      Throws:
      IndexOutOfBoundsException - if either index is out of range
    • getValue

      public @Nullable Object getValue(int rowIndex, String columnName)
      Gets a specific value from the result set by column name.
      Parameters:
      rowIndex - the zero-based row index
      columnName - the name of the column
      Returns:
      the value at the specified row and column, or null for SQL NULL; for results returned by client.sql(...), non-null values are String instances
      Throws:
      IndexOutOfBoundsException - if the row index is out of range
      IllegalArgumentException - if the column name is not found
    • getColumnName

      public String getColumnName(int columnIndex)
      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

      public int getColumnIndex(String columnName)
      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

      public static LoomSqlResult fromWireFormat(Map<String, @Nullable Object> wireMap)
      Creates a LoomSqlResult from the portable wire format used by the server (a Map with "columnNames" and "rows" keys), where row cells are stringified values or null.
      Parameters:
      wireMap - the deserialized wire-format map (non-null, entries may be null)
      Returns:
      a new LoomSqlResult with the extracted data
      Throws:
      NullPointerException - if wireMap is null
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • truncated

      public boolean truncated()
      Returns the value of the truncated record component.
      Returns:
      the value of the truncated record component