Package org.voltdb

Class VoltTableRow

java.lang.Object
org.voltdb.VoltTableRow
Direct Known Subclasses:
VoltTable

public abstract class VoltTableRow extends Object

Represents the interface to a row in a VoltTable result set.

Accessing Row Fields

Row fields are acessed via methods of the form get<Type>(col_index|col_name). Note: it is more performant to access rows by column index than by column name.

Advancing and Iterating through a Table

VoltTableRow represents both a row in a table and an iterator for all the rows in the table. For a given table, each VoltTableRow instance has a position value which represents the index represented in the table. To increment the position, call advanceRow(). To reset the position, call resetRowPosition(), which moves the position before the first row. Note that before you can access fields after a call to resetRowPosition, advanceRow must be called to move to the first row.

Example

VoltTableRow row = table.fetchRow(5);
System.out.println(row.getString("foo");
row.resetRowPosition();
while (row.advanceRow()) {
    System.out.println(row.getLong(7));
}
  • Field Details

    • MAX_TUPLE_LENGTH

      public static final int MAX_TUPLE_LENGTH
      Size in bytes of the maximum length for a VoltDB tuple. This is inclusive of the 4-byte row length prefix. 2 megs to allow a max size string/varbinary + length prefix + some other stuff
      See Also:
    • MAX_TUPLE_LENGTH_STR

      public static final String MAX_TUPLE_LENGTH_STR
      String representation of MAX_TUPLE_LENGTH.
  • Method Details

    • getColumnType

      public abstract VoltType getColumnType(int columnIndex)
      Return the type of the column with the specified index.
      Parameters:
      columnIndex - Index of the column
      Returns:
      VoltType of the column
    • getColumnIndex

      public abstract int getColumnIndex(String columnName)
      Return the index of the column with the specified column name.
      Parameters:
      columnName - Name of the column
      Returns:
      Index of the column
    • getColumnCount

      public abstract int getColumnCount()
      Returns the number of columns in the table schema
      Returns:
      Number of columns in the table schema
    • cloneRow

      public abstract VoltTableRow cloneRow()
      Clone a row. The new instance returned will have an independent position from the original instance.
      Returns:
      A deep copy of the current VoltTableRow instance.
    • getOffset

      public final int getOffset(int index)
    • resetRowPosition

      public void resetRowPosition()
      Sets the active position indicator so that the next call to advanceRow() will make the first record active. This never needs to be called if the table is only going to be scanned once. After this call getActiveRowIndex() will return -1 until advanceRow() is called.
    • getActiveRowIndex

      public int getActiveRowIndex()
      Get the position in the table of this row instance, starting at zero for the first row.
      Returns:
      The index of the active row or -1 if none.
    • advanceRow

      public boolean advanceRow()
      Makes the next row active so calls to getXXX() will return values from the current record. At initialization time, the active row index is -1, which is invalid. If advanced past the end of the resultset, resetRowPosition() must be called to re-iterate through the rows.
      Returns:
      True if a valid row became active. False otherwise.
    • advanceToRow

      public boolean advanceToRow(int rowIndex)
      Advance to a specific row so calls to getXXX() will return values from the current record. At initialization time, the active row index is -1, which is invalid. If advanced past the end of the resultset, resetRowPosition() must be called to re-iterate through the rows.
      Parameters:
      rowIndex - The row to jump to.
      Returns:
      True if a valid row became active. False otherwise.
    • get

      public final Object get(int columnIndex, VoltType type)
      Retrieve a value from the row by specifying the column index and the type. This method is slower then linking directly against the type specific getter. Prefer the type specific getter methods where viable. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnIndex - Index of the column
      type - VoltType of the value
      Returns:
      The value or null if the value is not set.
      See Also:
    • get

      public final Object get(String columnName, VoltType type)
      Retrieve a value from the row by specifying the column name and the type. This method is slower then linking directly against the type specific getter. Prefer the type specific getter methods where viable. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnName - Name of the column
      type - VoltType of the value
      Returns:
      The value or null if the value is not set.
      See Also:
    • getRowObjects

      public final Object[] getRowObjects()
      Retrieve the current row as an array of Objects. When this method is used wasNull() will not return a valid result since more than one value is being accessed.
      Returns:
      The current row as an array of objects
      Throws:
      RuntimeException - if the current row is not valid
    • get

      public final Object get(int columnIndex)
      Retrieve the column of the current row at columnIndex. If the value is null then null will be returned and wasNull() will return true
      Parameters:
      columnIndex - Index of the column
      Returns:
      The value or null if the value is not set.
      Throws:
      RuntimeException - if the current row is not valid
    • getLong

      public final long getLong(int columnIndex)
      Retrieve the long value stored in the column specified by index. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnIndex - Index of the column
      Returns:
      long value stored in the specified column
      See Also:
    • getLong

      public final long getLong(String columnName)
      Retrieve the long value stored in the column specified by name. Avoid retrieving via this method as it is slower than specifying the column by index. Use getLong(int) instead. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnName - Name of the column
      Returns:
      long value stored in the specified column
      See Also:
    • wasNull

      public final boolean wasNull()
      Returns whether last retrieved value was null. Some special values that are NOT Java's NULL represents null the SQL notion of null in our system.
      Returns:
      true if the value was null, false otherwise.
    • getRawRow

      public final ByteBuffer getRawRow()
      Returns:
      A slice of the underlying buffer containing the raw data of a row in a format that can be blindly copied into a VoltDB with sufficient space and the exact same schema.
    • getDouble

      public final double getDouble(int columnIndex)
      Retrieve the double value stored in the column specified by index. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnIndex - Index of the column
      Returns:
      double value stored in the specified column
      See Also:
    • getDouble

      public final double getDouble(String columnName)
      Retrieve the double value stored in the column specified by name. Avoid retrieving via this method as it is slower than specifying the column by index. Use getDouble(int) instead. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnName - Name of the column
      Returns:
      double value stored in the specified column
      See Also:
    • getString

      public final String getString(int columnIndex)
      Retrieve the String value stored in the column specified by index. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead. If at all possible you should use getStringAsBytes(int) instead and avoid the overhead of constructing the String object.
      Parameters:
      columnIndex - Index of the column
      Returns:
      String value stored in the specified column
      See Also:
    • getString

      public final String getString(String columnName)
      Retrieve the String value stored in the column specified by name. Avoid retrieving via this method as it is slower than specifying the column by index. Use getString(int) instead. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead. If at all possible you should use getStringAsBytes(int) instead and avoid the overhead of constructing the String object.
      Parameters:
      columnName - Name of the column
      Returns:
      String value stored in the specified column
      See Also:
    • getStringAsBytes

      public final byte[] getStringAsBytes(int columnIndex)
      Retrieve the string value stored in the column specified by index as an array of bytes. Assume UTF-8 encoding for all string values in VoltDB. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnIndex - Index of the column
      Returns:
      string value stored in the specified column as a byte[]
      See Also:
    • getStringAsBytes

      public final byte[] getStringAsBytes(String columnName)
      Retrieve the string value stored in the column specified by name as an array of bytes. Assume UTF-8 encoding for all string values in VoltDB.Avoid retrieving via this method as it is slower than specifying the column by index. Use getStringAsBytes(int) instead. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnName - Name of the column
      Returns:
      string value stored in the specified column as a byte[]
      See Also:
    • getVarbinary

      public final byte[] getVarbinary(int columnIndex)
      Retrieve the varbinary value stored in the column specified by index. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnIndex - Index of the column
      Returns:
      Varbinary value stored in the specified column
      See Also:
    • getVarbinaryLen

      public final int getVarbinaryLen(int columnIndex)
      Retrieve the length of the varbinary value stored in the column specified by index.
      Parameters:
      columnIndex - Index of the column
      Returns:
      Length of the varbinary value stored in the specified column or -1 if the value is null
    • getVarbinary

      public final byte[] getVarbinary(String columnName)
      Retrieve the varbinary value stored in the column specified by name. Avoid retrieving via this method as it is slower than specifying the column by index. Use getVarbinary(int) instead. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnName - Name of the column
      Returns:
      Varbinary value stored in the specified column
      See Also:
    • getGeographyPointValue

      public final GeographyPointValue getGeographyPointValue(int columnIndex)
      Retrieve the GeographyPointValue value stored in the column specified by index. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnIndex - Index of the column
      Returns:
      GeographyPointValue value stored in the specified column
      See Also:
    • getGeographyPointValue

      public final GeographyPointValue getGeographyPointValue(String columnName)
      Retrieve the GeographyPointValue value stored in the column specified by name. Avoid retrieving via this method as it is slower than specifying the column by index. Use getGeographyPointValue(int) instead. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnName - Name of the column
      Returns:
      GeographyPointValue value stored in the specified column
      See Also:
    • getGeographyValue

      public final GeographyValue getGeographyValue(int columnIndex)
      Retrieve the GeographyValue value stored in the column specified by index. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnIndex - Index of the column
      Returns:
      GeographyValue value stored in the specified column
      See Also:
    • getGeographyValue

      public final GeographyValue getGeographyValue(String columnName)
      Retrieve the GeographyValue value stored in the column specified by name. Avoid retrieving via this method as it is slower than specifying the column by index. Use getGeographyValue(int) instead. Looking at the return value is not a reliable way to check if the value is null. Use wasNull() instead.
      Parameters:
      columnName - Name of the column
      Returns:
      GeographyValue value stored in the specified column
      See Also:
    • getTimestampAsLong

      public final long getTimestampAsLong(int columnIndex)
      Retrieve the long timestamp stored in the column specified by index. Note that VoltDB uses GMT universally within its process space. Date objects sent over the wire from clients may seem to be different times because of this, but it is just a time zone offset. Timestamps represent microseconds from epoch.
      Parameters:
      columnIndex - Index of the column
      Returns:
      long timestamp value stored in the specified column
      See Also:
    • getTimestampAsLong

      public final long getTimestampAsLong(String columnName)
      Retrieve the long timestamp value stored in the column specified by name. Note that VoltDB uses GMT universally within its process space. Date objects sent over the wire from clients may seem to be different times because of this, but it is just a time zone offset. Avoid retrieving via this method as it is slower than specifying the column by index. Use getTimestampAsLong(int) instead.
      Parameters:
      columnName - Name of the column
      Returns:
      long timestamp value stored in the specified column
      See Also:
    • getTimestampAsTimestamp

      public final TimestampType getTimestampAsTimestamp(int columnIndex)
      Retrieve the TimestampType value stored in the column specified by index. Note that VoltDB uses GMT universally within its process space. Date objects sent over the wire from clients may seem to be different times because of this, but it is just a time zone offset.
      Parameters:
      columnIndex - Index of the column
      Returns:
      TimestampType value stored in the specified column
      See Also:
    • getTimestampAsTimestamp

      public final TimestampType getTimestampAsTimestamp(String columnName)
      Retrieve the TimestampType value stored in the column specified by name. Note that VoltDB uses GMT universally within its process space. Date objects sent over the wire from clients may seem to be different times because of this, but it is just a time zone offset. Avoid retrieving via this method as it is slower than specifying the column by index. Use getTimestampAsTimestamp(int) instead.
      Parameters:
      columnName - Name of the column
      Returns:
      TimestampType value stored in the specified column
      See Also:
    • getTimestampAsSqlTimestamp

      public final Timestamp getTimestampAsSqlTimestamp(int columnIndex)
      Retrieve the java.sql.Timestamp equivalent to the value stored in the column specified by index. Note that VoltDB uses GMT universally within its process space. Date objects sent over the wire from clients may seem to be different times because of this, but it is just a time zone offset. VoltDB Timestamps are stored as long integer microseconds from epoch. The resulting value is accurate to no finer than microsecond granularity.
      Parameters:
      columnIndex - Index of the column
      Returns:
      the java.sql.Timestamp equivalent to the value stored in the specified column
    • getTimestampAsSqlTimestamp

      public Timestamp getTimestampAsSqlTimestamp(String columnName)
      Retrieve the java.sql.Timestamp equivalent to the value stored in the column specified by name. Note that VoltDB uses GMT universally within its process space. Date objects sent over the wire from clients may seem to be different times because of this, but it is just a time zone offset. VoltDB Timestamps are stored as long integer microseconds from epoch. The resulting value is accurate to no finer than microsecond granularity. Avoid retrieving via this method as it is slower than specifying the column by index. Use getTimestampAsSqlTimestamp(int) instead.
      Parameters:
      columnName - name of the column
      Returns:
      the java.sql.Timestamp equivalent to the value stored in the specified column
    • getDecimalAsBigDecimal

      public final BigDecimal getDecimalAsBigDecimal(int columnIndex)

      Retrieve the BigDecimal value stored in the column specified by the index. All DECIMAL types have a fixed scale when represented as BigDecimals.

      Parameters:
      columnIndex - Index of the column
      Returns:
      BigDecimal representation.
      See Also:
    • getDecimalAsBigDecimal

      public BigDecimal getDecimalAsBigDecimal(String columnName)
      Retrieve the BigDecimal value stored in the column specified by columnName. All DECIMAL types have a fixed scale when represented as BigDecimals.
      Parameters:
      columnName - Name of the column
      Returns:
      BigDecimal representation.
      See Also:
    • getRow

      public String getRow()