Package org.yamcs.yarch
Class TableDefinition
- java.lang.Object
-
- org.yamcs.yarch.TableDefinition
-
public class TableDefinition extends Object
A table definition consists of a (key,value) pair of tuple definitions. A tuple has to contain all the columns from the key while it can contain only a few of the columns from the value (basically it's a sparse table).The key is encoded as a bytestream of all the columns in order The value is encoded as a bytestream of all the columns prceded by their index.
A table can also be partitioned according to the partitioningSpec.
-
-
Field Summary
Fields Modifier and Type Field Description static intCURRENT_FORMAT_VERSION
-
Constructor Summary
Constructors Constructor Description TableDefinition(String name, TupleDefinition tdef, List<String> primaryKey)Used when creating an "empty"(i.e. no enum values) table via sql.TableDefinition(TupleDefinition keyDef, TupleDefinition valueDef, Map<String,com.google.common.collect.BiMap<String,Short>> enumValues)Used when creating the table from the serialized data on disk
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ShortaddAndGetEnumValue(String columnName, String value)get the enum value corresponding to a column, creating it if it does not existTupledeserialize(byte[] k, byte[] v)ColumnDefinitiongetColumnDefinition(String cname)ColumnSerializergetColumnSerializer(String columnName)com.google.common.collect.BiMap<String,Short>getEnumValues(String columnName)intgetFormatVersion()List<String>getHistogramColumns()TupleDefinitiongetKeyDefinition()StringgetName()PartitioningSpecgetPartitioningSpec()com.google.common.collect.BiMap<String,Short>getSerializedEnumValues(String columnName)Returns the enumerations to be serialized on disk.TupleDefinitiongetSerializedValueDefinition()Returns the value definition to be serialized on disk.StringgetStorageEngineName()TupleDefinitiongetTupleDefinition()TupleDefinitiongetValueDefinition()booleanhasHistogram()booleanhasPartitioning()booleanisCompressed()booleanisIndexedByKey(String cname)voidrenameColumn(String oldName, String newName)Renames column and serializes the table definition to disk.byte[]serializeKey(Tuple t)Transforms the key part of the tuple into a byte array to be written to disk.byte[]serializeValue(Tuple t)Transform the value part of the tuple into a byte array to be written on disk.voidsetCompressed(boolean compressed)voidsetDb(YarchDatabaseInstance ydb)voidsetHistogramColumns(List<String> histoColumns)voidsetName(String name)voidsetPartitioningSpec(PartitioningSpec pspec)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 columnvoidsetStorageEngineName(String storageEngineName)StringtoString()voidvalidate()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 Detail
-
CURRENT_FORMAT_VERSION
public static final int CURRENT_FORMAT_VERSION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TableDefinition
public TableDefinition(String name, TupleDefinition tdef, List<String> primaryKey) throws StreamSqlException
Used when creating an "empty"(i.e. no enum values) table via sql.- Parameters:
name-tdef-primaryKey-- Throws:
StreamSqlException
-
TableDefinition
public TableDefinition(TupleDefinition keyDef, TupleDefinition valueDef, Map<String,com.google.common.collect.BiMap<String,Short>> enumValues)
Used when creating the table from the serialized data on disk- Parameters:
keyDef-valueDef-enumValues-
-
-
Method Detail
-
setDb
public void setDb(YarchDatabaseInstance ydb)
-
setPartitioningSpec
public void setPartitioningSpec(PartitioningSpec pspec) throws StreamSqlException
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
public TupleDefinition getKeyDefinition()
-
getValueDefinition
public TupleDefinition getValueDefinition()
-
getName
public String getName()
-
setName
public void setName(String name)
-
getTupleDefinition
public TupleDefinition getTupleDefinition()
-
validate
public void validate() throws StreamSqlExceptionChecks 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
-
serializeKey
public byte[] serializeKey(Tuple t)
Transforms 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).- Parameters:
t-- Returns:
- serialized key value
-
renameColumn
public void renameColumn(String oldName, String newName)
Renames column and serializes the table definition to disk. Should not be used when the table is in used (e.g. by a table writer or reader).- Parameters:
oldName- - old name of the columnnewName- - new name of the column
-
addAndGetEnumValue
public Short addAndGetEnumValue(String columnName, String value)
get the enum value corresponding to a column, creating it if it does not exist- Returns:
-
serializeValue
public byte[] serializeValue(Tuple t)
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.- Parameters:
t-- Returns:
- the serialized version of the value part of the tuple
-
deserialize
public Tuple deserialize(byte[] k, byte[] v)
-
isCompressed
public boolean isCompressed()
-
isIndexedByKey
public boolean isIndexedByKey(String cname)
- Parameters:
cname- the column name- Returns:
- true if cname is the first column of the key
-
getColumnDefinition
public ColumnDefinition getColumnDefinition(String cname)
-
hasPartitioning
public boolean hasPartitioning()
-
getPartitioningSpec
public PartitioningSpec getPartitioningSpec()
-
setCompressed
public void setCompressed(boolean compressed)
-
setHistogramColumns
public void setHistogramColumns(List<String> histoColumns) throws StreamSqlException
- Throws:
StreamSqlException
-
hasHistogram
public boolean hasHistogram()
-
getEnumValues
public com.google.common.collect.BiMap<String,Short> getEnumValues(String columnName)
-
getColumnSerializer
public ColumnSerializer getColumnSerializer(String columnName)
-
getStorageEngineName
public String getStorageEngineName()
-
setStorageEngineName
public void setStorageEngineName(String storageEngineName)
-
getFormatVersion
public int getFormatVersion()
-
getSerializedValueDefinition
public TupleDefinition getSerializedValueDefinition()
Returns the value definition to be serialized on disk.This should only be used from the storage engine.
TODO: refactor to hide this method.
-
getSerializedEnumValues
public com.google.common.collect.BiMap<String,Short> getSerializedEnumValues(String columnName)
Returns the enumerations to be serialized on disk.This should only be used from the storage engine.
TODO: refactor to hide this method.
-
-