Class 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 Detail

    • Method Detail

      • 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
      • getName

        public String getName()
      • setName

        public void setName​(String name)
      • validate

        public void validate()
                      throws StreamSqlException
        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
      • 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 column
        newName - - 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
      • hasPartitioning

        public boolean hasPartitioning()
      • setCompressed

        public void setCompressed​(boolean compressed)
      • hasHistogram

        public boolean hasHistogram()
      • getEnumValues

        public com.google.common.collect.BiMap<String,​Short> getEnumValues​(String columnName)
      • getHistogramColumns

        public List<String> getHistogramColumns()
      • 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.