Class TableDefinition
The key is encoded as a byte array of all the columns in order. The value is encoded as a byte array of all the columns preceded by the id of their data type (1 byte) and their index (3 bytes).
The secondary index key is encoded as a byte array of all the columns in order preceded by the id of their data type with the first bit set to 1 for the columns present and 0 for the column not present (i.e. null).
A table can also be partitioned according to the partitioningSpec.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTableDefinition
(int formatVersion, List<TableColumnDefinition> key, List<TableColumnDefinition> value) Used when creating the table from the serialized data on diskTableDefinition
(String name, TupleDefinition tdef, List<String> primaryKey) Used when creating an empty table via sql. -
Method Summary
Modifier and TypeMethodDescriptionaddAndGetEnumValue
(String columnName, String value) get the enum value corresponding to a column, creating it if it does not existvoid
changeDataType
(String cname, DataType dataType) this method is used during table migration between two versionsdeserialize
(byte[] k, byte[] v) generateRow
(Tuple t) Generate a new table row by transforming the key part of the tuple into a byte array to be written to disk.getColumnDefinition
(String colName) <T> ColumnSerializer<T>
getColumnSerializer
(String columnName) getEnumValues
(String columnName) int
getName()
boolean
boolean
boolean
boolean
boolean
boolean
isIndexedByKey
(String cname) boolean
isPartitionedBy
(String colName) Return true if the table is partitioned and the colName is used as partition column (either time or value)boolean
byte[]
serializeValue
(Tuple tuple, Row sertuple) Transform the value part of the tuple into a byte array to be written on disk.void
serializeValue
(Tuple tuple, Row sertuple, ByteArray byteArray) Same asserializeValue(Tuple, Row)
but encodes the output in user provided byte arrayvoid
setCompressed
(boolean compressed) void
void
setHistogramColumns
(List<String> histoColumns) void
void
time based partitions can be on the first column of the key (which has to be of type timestamp) value based partitions can be on any other mandatory columnvoid
setSecondaryIndex
(List<String> index) void
setStorageEngineName
(String storageEngineName) toString()
void
validate()
Checks that the table definition is valid: - primary key not string, except for the last in the list (otherwise the binary sorting does not work properly)
-
Field Details
-
CURRENT_FORMAT_VERSION
public static final int CURRENT_FORMAT_VERSION- See Also:
-
-
Constructor Details
-
TableDefinition
public TableDefinition(String name, TupleDefinition tdef, List<String> primaryKey) throws StreamSqlException Used when creating an empty table via sql.- Parameters:
name
-tdef
-primaryKey
-- Throws:
StreamSqlException
-
TableDefinition
public TableDefinition(int formatVersion, List<TableColumnDefinition> key, List<TableColumnDefinition> value) Used when creating the table from the serialized data on disk
-
-
Method Details
-
setDb
-
setPartitioningSpec
time based partitions can be on the first column of the key (which has to be of type timestamp) value based partitions can be on any other mandatory column- Parameters:
pspec
-- Throws:
StreamSqlException
-
getKeyDefinition
-
getValueDefinition
-
getName
-
setName
-
getTupleDefinition
-
validate
Checks that the table definition is valid: - primary key not string, except for the last in the list (otherwise the binary sorting does not work properly)- Throws:
StreamSqlException
-
generateRow
Generate a new table row by transforming the key part of the tuple into a byte array to be written to disk. The tuple must contain each column from the key and they are written in order (such that sorting is according to the definition of the primary key).In addition, it stores into the returned row all the values for the columns used in histograms or indices
- Parameters:
t
-- Returns:
- a tuple containing the histogram and secondary index values as well as the generated key
- Throws:
YarchException
-
addAndGetEnumValue
get the enum value corresponding to a column, creating it if it does not exist- Returns:
-
serializeValue
Same asserializeValue(Tuple, Row)
but encodes the output in user provided byte array- Parameters:
tuple
-sertuple
-byteArray
-
-
serializeValue
Transform the value part of the tuple into a byte array to be written on disk. Each column is preceded by a tag (the column index).If there are columns in the tuple which are not in the valueDef, they are added and the TableDefinition is serialized on disk.
Columns whose values are null are not serialized but their definition is still added to the table definition if not present already.
- Parameters:
tuple
-sertuple
- - if not null, store all the values of the columns to this tuple as written to the database (possibly after some data casting)- Returns:
- the serialized version of the value part of the tuple
-
deserialize
-
isCompressed
public boolean isCompressed() -
isIndexedByKey
- Parameters:
cname
- the column name- Returns:
- true if cname is the first column of the key
-
getColumnDefinition
-
hasPartitioning
public boolean hasPartitioning() -
getPartitioningSpec
-
setCompressed
public void setCompressed(boolean compressed) -
setHistogramColumns
- Throws:
StreamSqlException
-
setSecondaryIndex
- Throws:
StreamSqlException
-
hasHistogram
public boolean hasHistogram() -
getEnumValues
-
getHistogramColumns
-
getSecondaryIndex
-
getColumnSerializer
-
getStorageEngineName
-
setStorageEngineName
-
getFormatVersion
public int getFormatVersion() -
toString
-
changeDataType
this method is used during table migration between two versionsIt should not be used for other things.
-
hasKey
- Parameters:
colName
-- Returns:
- true if the column is part of the primary key
-
isPartitionedByTime
public boolean isPartitionedByTime() -
getHistoIdx
-
hasSecondaryIndex
public boolean hasSecondaryIndex() -
isPartitionedBy
Return true if the table is partitioned and the colName is used as partition column (either time or value)- Parameters:
colName
-- Returns:
-