public final class VoltTable extends VoltTableRow implements org.json_voltpatches.JSONString
The primary representation of a result set (of tuples) or a temporary table in VoltDB. VoltTable has arbitrary schema, is serializable, and is used from within Stored Procedures and from the client library.
Given a VoltTable, individual rows can be accessed via the fetchRow(int)
method. This method returns a VoltTableRow
instance with position set to
the specified row. See VoltTableRow for further information on accessing individual
column data within a row.
Like a VoltTableRow
, a VoltTable has a current position within its rows.
This is because VoltTable is a subclass of VoltTableRow. This allows for easy
sequential access of data. Example:
while (table.advanceRow()) {
System.out.println(table.getLong(7));
}
VoltTables can be constructed on the fly. This can help generate cleaner result sets from stored procedures, or more manageable parameters to them. Example:
VoltTable t = new VoltTable(
new VoltTable.ColumnInfo("col1", VoltType.BIGINT),
new VoltTable.ColumnInfo("col2", VoltType.STRING));
t.addRow(15, "sampleString");
t.addRow(-9, "moreData");
Modifier and Type | Class and Description |
---|---|
static class |
VoltTable.ColumnInfo
Object that represents the name and schema for a
VoltTable column. |
Modifier and Type | Field and Description |
---|---|
static int |
MAX_SERIALIZED_TABLE_LENGTH
Size in bytes of the maximum length for a VoltDB tuple.
|
static java.lang.String |
MAX_SERIALIZED_TABLE_LENGTH_STR
String representation of
MAX_SERIALIZED_TABLE_LENGTH . |
MAX_TUPLE_LENGTH, MAX_TUPLE_LENGTH_STR
Constructor and Description |
---|
VoltTable(VoltTable.ColumnInfo[] columns)
Create an empty table from column schema given as an array.
|
VoltTable(VoltTable.ColumnInfo[] columns,
int columnCount)
Create an empty table from column schema.
|
VoltTable(VoltTable.ColumnInfo firstColumn,
VoltTable.ColumnInfo... columns)
Create an empty table from column schema.
|
Modifier and Type | Method and Description |
---|---|
void |
add(VoltTableRow row)
Append a
row from another VoltTable
to this VoltTable instance. |
void |
addRow(java.lang.Object... values)
Append a new row to the table using the supplied column values.
|
long |
asScalarLong()
Tables containing a single row and a single integer column can be read using this convenience
method.
|
byte[] |
buildReusableDependenyResult() |
void |
clearRowData()
Delete all row data.
|
VoltTable |
clone(int extraBytes)
Generates a duplicate of a table including the column schema.
|
VoltTableRow |
cloneRow()
Get a new
VoltTableRow instance with identical position as this table. |
void |
convertToHeapBuffer() |
boolean |
equals(java.lang.Object o)
Deprecated.
Exists for unit testing, but probably shouldn't be called.
|
VoltTableRow |
fetchRow(int index)
Return a
VoltTableRow instance with the specified index. |
void |
flattenToBuffer(java.nio.ByteBuffer buf)
Serialize this table to a given ByteBuffer.
|
static VoltTable |
fromJSONObject(org.json_voltpatches.JSONObject json)
Construct a table from a JSON object.
|
static VoltTable |
fromJSONString(java.lang.String json)
Construct a table from a JSON string.
|
java.nio.ByteBuffer |
getBuffer()
Directly access the table's underlying
ByteBuffer . |
int |
getColumnCount()
Returns the number of columns in the table schema
|
int |
getColumnIndex(java.lang.String name)
Return the index of the column with the specified column name.
|
java.lang.String |
getColumnName(int index)
Return the name of the column with the specified index.
|
VoltType |
getColumnType(int index)
Return the
type of the column with the specified index. |
int |
getRowCount()
Returns the number of rows.
|
protected int |
getRowStart() |
int |
getSerializedSize()
Get the serialized size in bytes of this table.
|
byte |
getStatusCode()
Set the status code associated with this table.
|
VoltTable.ColumnInfo[] |
getTableSchema()
Get the schema of the table.
|
int |
hashCode()
Deprecated.
This only throws. Doesn't do anything.
|
boolean |
hasSameContents(VoltTable other)
Check to see if this table has the same contents as the provided table.
|
void |
setStatusCode(byte code)
Set the status code associated with this table.
|
java.lang.String |
toFormattedString()
Return a "pretty print" representation of this table with column names.
|
java.lang.String |
toFormattedString(boolean includeColumnNames)
Return a "pretty print" representation of this table with or without column names.
|
java.lang.String |
toJSONString()
Get a JSON representation of this table.
|
java.lang.String |
toString()
Returns a
String representation of this table. |
static java.lang.String |
varbinaryToPrintableString(byte[] bin)
Make a printable, short string for a varbinary.
|
advanceRow, advanceToRow, get, get, getActiveRowIndex, getDecimalAsBigDecimal, getDecimalAsBigDecimal, getDouble, getDouble, getGeographyPointValue, getGeographyPointValue, getGeographyValue, getGeographyValue, getLong, getLong, getOffset, getString, getString, getStringAsBytes, getStringAsBytes, getTimestampAsLong, getTimestampAsLong, getTimestampAsSqlTimestamp, getTimestampAsSqlTimestamp, getTimestampAsTimestamp, getTimestampAsTimestamp, getVarbinary, getVarbinary, resetRowPosition, wasNull
public static final int MAX_SERIALIZED_TABLE_LENGTH
public static final java.lang.String MAX_SERIALIZED_TABLE_LENGTH_STR
MAX_SERIALIZED_TABLE_LENGTH
.public VoltTable(VoltTable.ColumnInfo[] columns, int columnCount)
VoltTable(ColumnInfo...)
is the preferred constructor, this version may reduce the need for an array
allocation by allowing the caller to specify only a portion of the given array
should be used.columns
- An array of ColumnInfo objects, one per column
in the desired order.columnCount
- The number of columns in the array to use.public VoltTable(VoltTable.ColumnInfo[] columns)
columns
- An array of ColumnInfo objects, one per column
in the desired order.public VoltTable(VoltTable.ColumnInfo firstColumn, VoltTable.ColumnInfo... columns)
firstColumn
- The first column of the table.columns
- An array of ColumnInfo objects, one per column
in the desired order (can be empty).public final void clearRowData()
public VoltTableRow cloneRow()
VoltTableRow
instance with identical position as this table.
After the cloning, the new instance and this table can be advanced or reset
independently.cloneRow
in class VoltTableRow
VoltTableRow
instance with the same position as this table.public final java.lang.String getColumnName(int index)
index
- Index of the columnpublic final VoltType getColumnType(int index)
VoltTableRow
type
of the column with the specified index.getColumnType
in class VoltTableRow
index
- Index of the columnVoltType
of the columnpublic final int getColumnIndex(java.lang.String name)
VoltTableRow
getColumnIndex
in class VoltTableRow
name
- Name of the columnpublic final VoltTableRow fetchRow(int index)
VoltTableRow
instance with the specified index. This method
is not performant because it has to scan the length prefix of every row preceding
the requested row in order to find the position of the requested row. Use advanceRow
or advanceToRow instead.index
- Index of the rowRow
.java.lang.IndexOutOfBoundsException
- if no row exists at the given index.public final void add(VoltTableRow row)
row
from another VoltTable
to this VoltTable instance. Technically, it could be from the same
table, but this isn't the common usage.row
- Row
to add.public final void addRow(java.lang.Object... values)
values
- Values of each column in the row.VoltTypeException
- when there are casting/type failures
between an input value and the corresponding columnpublic final long asScalarLong()
VoltTableRow.wasNull()
instead.public java.lang.String toString()
String
representation of this table.
Resulting string will contain schema and all data and will be formatted.toString
in class java.lang.Object
String
representation of this table.public static java.lang.String varbinaryToPrintableString(byte[] bin)
bin
- The bytes to print out.public java.lang.String toFormattedString()
public java.lang.String toFormattedString(boolean includeColumnNames)
includeColumnNames
- Flag to control if column names should be included or not.public java.lang.String toJSONString()
toJSONString
in interface org.json_voltpatches.JSONString
public static VoltTable fromJSONString(java.lang.String json) throws org.json_voltpatches.JSONException, java.io.IOException
json
- String containing JSON-formatted table data.VoltTable
instance.org.json_voltpatches.JSONException
- on JSON-related error.java.io.IOException
- if thrown by our JSON library.public static VoltTable fromJSONObject(org.json_voltpatches.JSONObject json) throws org.json_voltpatches.JSONException, java.io.IOException
Construct a table from a JSON object. Only parses VoltDB VoltTable JSON format.
json
- String containing JSON-formatted table data.VoltTable
instance.org.json_voltpatches.JSONException
- on JSON-related error.java.io.IOException
- if thrown by our JSON library.public boolean hasSameContents(VoltTable other)
Object.equals(Object)
because we don't
want to provide all of the additional contractual requirements that go
along with it, such as implementing Object.hashCode()
.other
- Table to compare to.@Deprecated public boolean equals(java.lang.Object o)
Object.equals(Object)
that should not be used. Only
present for unit testing.equals
in class java.lang.Object
@Deprecated public int hashCode()
Object.hashCode()
since we are
overriding Object.equals(Object)
.
Throws an UnsupportedOperationException
.hashCode
in class java.lang.Object
java.lang.UnsupportedOperationException
- if called.public final VoltTable clone(int extraBytes)
Generates a duplicate of a table including the column schema. Only works
on tables that have no rows, have columns defined, and will not have columns added/deleted/modified
later. Useful as way of creating template tables that can be cloned and then populated with
rows
repeatedly.
extraBytes
- The number of extra bytes to leave for to-be-added rows beyond the header.rows
and strings.public final int getRowCount()
VoltTableRow
protected final int getRowStart()
public final int getColumnCount()
VoltTableRow
getColumnCount
in class VoltTableRow
public byte getStatusCode()
public void setStatusCode(byte code)
code
- Status code to setpublic int getSerializedSize()
public void flattenToBuffer(java.nio.ByteBuffer buf)
Serialize this table to a given ByteBuffer. Used mostly internally by VoltDB for moving tables over the network.
buf
- Buffer to serialize table to.public byte[] buildReusableDependenyResult()
public final void convertToHeapBuffer()
public java.nio.ByteBuffer getBuffer()
ByteBuffer
. This should be avoided if
possible by end users, as there is potential to really mess stuff up. VoltDB mostly
uses it to compute various checksums quickly.ByteBuffer
instance.public VoltTable.ColumnInfo[] getTableSchema()
VoltTable.ColumnInfo
instances for each table column.