Class VoltTable
- All Implemented Interfaces:
- 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.
Accessing Rows by Index
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.
A VoltTable is also a VoltTableRow
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));
 }
 
 Building a Table Dynamically
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");
 - 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classObject that represents the name and schema for aVoltTablecolumn.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intSize in bytes of the maximum length for a VoltDB tuple.static final StringString representation ofMAX_SERIALIZED_TABLE_LENGTH.Fields inherited from class org.voltdb.VoltTableRowMAX_TUPLE_LENGTH, MAX_TUPLE_LENGTH_STR
- 
Constructor SummaryConstructorsConstructorDescriptionVoltTable(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.
- 
Method SummaryModifier and TypeMethodDescriptionfinal voidadd(VoltTableRow row) Append arowfrom anotherVoltTableto this VoltTable instance.final voidAppend a new row to the table using the supplied column values.voidAdd all rows fromotherinto this VoltTable.voidaddTables(Collection<VoltTable> tables) Add all rows fromtablesinto this VoltTable.voidAdds a table with extra columns, based on another provided table.voidaddTableWithLessColumns(VoltTable other) Adds a table with fewer columns, based on another provided table.final longTables containing a single row and a single integer column can be read using this convenience method.byte[]Builds a dependency response that can be reused.final voidDelete all row data.final VoltTableclone(int extraBytes) Generates a duplicate of a table including the column schema.cloneRow()Get a newVoltTableRowinstance with identical position as this table.final voidConverts the allocated direct buffer to a heap buffer, if necessary,booleanDeprecated.Exists for unit testing, but probably shouldn't be called.final VoltTableRowfetchRow(int index) Return aVoltTableRowinstance with the specified index.voidSerialize this table to a given ByteBuffer.static VoltTablefromJSONObject(org.json_voltpatches.JSONObject json) Construct a table from a JSON object.static VoltTablefromJSONString(String json) Construct a table from a JSON string.Directly access the table's underlyingByteBuffer.final intReturns the number of columns in the table schemafinal intgetColumnIndex(String name) Return the index of the column with the specified column name.final StringgetColumnName(int index) Return the name of the column with the specified index.final VoltTypegetColumnType(int index) Return thetypeof the column with the specified index.static VoltTableget a not fully constructed and validated VoltTable.final intintGet the serialized size in bytes of this table.byteSet the status code associated with this table.longgetTableCheckSum(boolean includeHeader) Calculate a rudimentary checksum of the table.Get the schema of the table.inthashCode()Deprecated.This only throws.booleanhasSameContents(VoltTable other) Check to see if this table has the same contents as the provided table.booleanhasSameContents(VoltTable other, boolean ignoreOrder) Check to see if this table has the same contents as the provided table, optionally ignoring the order of rows.voidsetStatusCode(byte code) Set the status code associated with this table.Return a "pretty print" representation of this table with column names.toFormattedString(boolean includeColumnNames) Return a "pretty print" representation of this table with or without column names.Get a JSON representation of this table.org.json_voltpatches.JSONStringertoJSONStringerV2(org.json_voltpatches.JSONStringer js) Get a JSON /api/2.0/ representation of this table.toString()Returns aStringrepresentation of this table.static StringvarbinaryToPrintableString(byte[] bin) Make a printable, short string for a varbinary.Methods inherited from class org.voltdb.VoltTableRowadvanceRow, advanceToRow, get, get, get, getActiveRowIndex, getDateAsDate, getDateAsDate, getDateAsLocalDate, getDateAsLocalDate, getDateAsSqlDate, getDateAsSqlDate, getDateAsUtilDate, getDateAsUtilDate, getDecimalAsBigDecimal, getDecimalAsBigDecimal, getDouble, getDouble, getGeographyPointValue, getGeographyPointValue, getGeographyValue, getGeographyValue, getLong, getLong, getOffset, getRawRow, getRow, getRowObjects, getString, getString, getStringAsBytes, getStringAsBytes, getTimestampAsLong, getTimestampAsLong, getTimestampAsSqlTimestamp, getTimestampAsSqlTimestamp, getTimestampAsTimestamp, getTimestampAsTimestamp, getVarbinary, getVarbinary, getVarbinaryLen, resetRowPosition, wasNull
- 
Field Details- 
MAX_SERIALIZED_TABLE_LENGTHpublic static final int MAX_SERIALIZED_TABLE_LENGTHSize in bytes of the maximum length for a VoltDB tuple. This value is counted from byte 0 of the header size to the end of row data.- See Also:
 
- 
MAX_SERIALIZED_TABLE_LENGTH_STRString representation ofMAX_SERIALIZED_TABLE_LENGTH.
 
- 
- 
Constructor Details- 
VoltTableCreate an empty table from column schema. WhileVoltTable(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.- Parameters:
- columns- An array of ColumnInfo objects, one per column in the desired order.
- columnCount- The number of columns in the array to use.
 
- 
VoltTableCreate an empty table from column schema given as an array.- Parameters:
- columns- An array of ColumnInfo objects, one per column in the desired order.
 
- 
VoltTableCreate an empty table from column schema. Note that while this accepts a varargs set of columns, it requires at least one column to prevent user errors.- Parameters:
- firstColumn- The first column of the table.
- columns- An array of ColumnInfo objects, one per column in the desired order (can be empty).
 
 
- 
- 
Method Details- 
getInstanceForTestget a not fully constructed and validated VoltTable. DO NOT use it for production- Parameters:
- buf- The buffer containing VoltTable buffer.
- Returns:
- VoltTable instance
 
- 
clearRowDatapublic final void clearRowData()Delete all row data. Column data is preserved. Useful for reusing anVoltTable.
- 
cloneRowGet a newVoltTableRowinstance with identical position as this table. After the cloning, the new instance and this table can be advanced or reset independently.- Specified by:
- cloneRowin class- VoltTableRow
- Returns:
- A new VoltTableRowinstance with the same position as this table.
 
- 
getColumnNameReturn the name of the column with the specified index.- Parameters:
- index- Index of the column
- Returns:
- Name of the column with the specified index.
 
- 
getColumnTypeDescription copied from class:VoltTableRowReturn thetypeof the column with the specified index.- Specified by:
- getColumnTypein class- VoltTableRow
- Parameters:
- index- Index of the column
- Returns:
- VoltTypeof the column
 
- 
getColumnIndexDescription copied from class:VoltTableRowReturn the index of the column with the specified column name.- Specified by:
- getColumnIndexin class- VoltTableRow
- Parameters:
- name- Name of the column
- Returns:
- Index of the column
 
- 
fetchRowReturn aVoltTableRowinstance 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.- Parameters:
- index- Index of the row
- Returns:
- The requested Row.
- Throws:
- IndexOutOfBoundsException- if no row exists at the given index.
 
- 
addAppend arowfrom anotherVoltTableto this VoltTable instance. Technically, it could be from the same table, but this isn't the common usage.- Parameters:
- row-- Rowto add.
 
- 
addRowAppend a new row to the table using the supplied column values.- Parameters:
- values- Values of each column in the row.
- Throws:
- org.voltdb.VoltTypeException- when there are casting/type failures between an input value and the corresponding column
 
- 
asScalarLongpublic final long asScalarLong()Tables containing a single row and a single integer column can be read using this convenience method. Looking at the return value is not a reliable way to check if the value isnull. UseVoltTableRow.wasNull()instead.- Returns:
- The integer row value.
 
- 
addTableAdd all rows fromotherinto this VoltTable. Both tables must have the exact same schema including column names.- Parameters:
- other-- VoltTableto add to this table
- Throws:
- IllegalArgumentException- if- otheris not compatible with this table
 
- 
addTableWithExtraColumnsAdds a table with extra columns, based on another provided table.If the othertable has extra columns they will be skipped.Columns that match must have the same types. If no columns were copied this will throw an IllegalStateException. Be careful using this as it may copy column A into column B if their ordinals and type match. - Parameters:
- other- the- VoltTableto copy columns from.
 
- 
addTableWithLessColumnsAdds a table with fewer columns, based on another provided table.If the othertable has fewer columns, null values will be used.Columns that match must have the same types. If no columns were copied this will throw an IllegalStateException. - Parameters:
- other- the- VoltTableto copy columns from.
 
- 
addTablesAdd all rows fromtablesinto this VoltTable. All tables must have the exact same schema including column names.- Parameters:
- tables-- Collectionof- VoltTables to add to this table
- Throws:
- IllegalArgumentException- if any table in- tablesis not compatible with this table
 
- 
toStringReturns aStringrepresentation of this table. Resulting string will contain schema and all data and will be formatted.
- 
varbinaryToPrintableStringMake a printable, short string for a varbinary. String includes a CRC and the contents of the varbinary in hex. Contents longer than 13 chars are truncated and elipsized. Yes, "elipsized" is totally a word. Example: "bin[crc:1298399436,value:0xABCDEF12345...]"- Parameters:
- bin- The bytes to print out.
- Returns:
- A string representation that is printable and short.
 
- 
toFormattedStringReturn a "pretty print" representation of this table with column names. Output will be formatted in a tabular textual format suitable for display.- Returns:
- A string containing a pretty-print formatted representation of this table.
 
- 
toFormattedStringReturn a "pretty print" representation of this table with or without column names. Output will be formatted in a tabular textual format suitable for display.- Parameters:
- includeColumnNames- Flag to control if column names should be included or not.
- Returns:
- A string containing a pretty-print formatted representation of this table.
 
- 
toJSONStringGet a JSON representation of this table.- Specified by:
- toJSONStringin interface- org.json_voltpatches.JSONString
- Returns:
- A string containing a JSON representation of this table.
 
- 
toJSONStringerV2public org.json_voltpatches.JSONStringer toJSONStringerV2(org.json_voltpatches.JSONStringer js) throws org.json_voltpatches.JSONException Get a JSON /api/2.0/ representation of this table.- Parameters:
- js-- JSONStringerinstance to add this table to
- Returns:
- A JSONStringer containing representation of this table.
- Throws:
- org.json_voltpatches.JSONException- If there was an error generating the JSON
 
- 
fromJSONStringpublic static VoltTable fromJSONString(String json) throws org.json_voltpatches.JSONException, IOException Construct a table from a JSON string. Only parses VoltDB VoltTable JSON format.- Parameters:
- json- String containing JSON-formatted table data.
- Returns:
- Constructed VoltTableinstance.
- Throws:
- org.json_voltpatches.JSONException- on JSON-related error.
- IOException- if thrown by our JSON library.
 
- 
fromJSONObjectpublic static VoltTable fromJSONObject(org.json_voltpatches.JSONObject json) throws org.json_voltpatches.JSONException, IOException Construct a table from a JSON object. Only parses VoltDB VoltTable JSON format. - Parameters:
- json- String containing JSON-formatted table data.
- Returns:
- Constructed VoltTableinstance.
- Throws:
- org.json_voltpatches.JSONException- on JSON-related error.
- IOException- if thrown by our JSON library.
 
- 
hasSameContentsCheck to see if this table has the same contents as the provided table. This is notObject.equals(Object)because we don't want to provide all of the additional contractual requirements that go along with it, such as implementingObject.hashCode().- Parameters:
- other- Table to compare to.
- Returns:
- Whether the tables have the same contents.
 
- 
hasSameContentsCheck to see if this table has the same contents as the provided table, optionally ignoring the order of rows.- Parameters:
- other- Table to compare to.
- ignoreOrder- true if tables can be considered equal despite order.
- Returns:
- Whether the tables have the same contents.
 
- 
getTableCheckSumpublic long getTableCheckSum(boolean includeHeader) Calculate a rudimentary checksum of the table. The result of this method will be the same for two tables with the same rows but not necessarily in the same order.When includeHeaderisfalsethe result of this checksum can be added to the result from another table to affectively concatenate the hash from this table with another to compare across tables.- Parameters:
- includeHeader- If- truethe table header will be included in the checksum
- Returns:
- checksum of table
 
- 
equalsDeprecated.Exists for unit testing, but probably shouldn't be called.An unreliable version ofObject.equals(Object)that should not be used. Only present for unit testing.
- 
hashCodeDeprecated.This only throws. Doesn't do anything.Also overridesObject.hashCode()since we are overridingObject.equals(Object). Throws anUnsupportedOperationException.- Overrides:
- hashCodein class- Object
- Throws:
- UnsupportedOperationException- if called.
 
- 
cloneGenerates 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 rowsrepeatedly.- Parameters:
- extraBytes- The number of extra bytes to leave for to-be-added rows beyond the header.
- Returns:
- An VoltTablewith the same column schema as the original and enough space for the specified number ofrowsand strings.
 
- 
getRowCountpublic final int getRowCount()
- 
getColumnCountpublic final int getColumnCount()Description copied from class:VoltTableRowReturns the number of columns in the table schema- Specified by:
- getColumnCountin class- VoltTableRow
- Returns:
- Number of columns in the table schema
 
- 
getStatusCodepublic byte getStatusCode()Set the status code associated with this table. Default value is 0.- Returns:
- Status code
 
- 
setStatusCodepublic void setStatusCode(byte code) Set the status code associated with this table. Default value if not set is 0- Parameters:
- code- Status code to set
 
- 
getSerializedSizepublic int getSerializedSize()Get the serialized size in bytes of this table. This is used mostly internally by VoltDB for table serialization purposes.- Returns:
- The size in bytes.
 
- 
flattenToBufferSerialize this table to a given ByteBuffer. Used mostly internally by VoltDB for moving tables over the network.- Parameters:
- buf- Buffer to serialize table to.
 
- 
buildReusableDependenyResultpublic byte[] buildReusableDependenyResult()Builds a dependency response that can be reused.- Returns:
- response as byte array
 
- 
convertToHeapBufferpublic final void convertToHeapBuffer()Converts the allocated direct buffer to a heap buffer, if necessary,
- 
getBufferDirectly access the table's underlyingByteBuffer. 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.- Returns:
- The underlying ByteBufferinstance.
 
- 
getTableSchemaGet the schema of the table. Can be fed into another table's constructor.- Returns:
- An ordered array of VoltTable.ColumnInfoinstances for each table column.
 
 
-