Class TableDefinition

java.lang.Object
com.illumon.dataobjects.generated.DefaultTableDefinition
com.illumon.iris.db.tables.TableDefinition
All Implemented Interfaces:
com.fishlib.base.Copyable<com.illumon.dataobjects.generated.DefaultTableDefinition>, com.fishlib.base.log.LogOutputAppendable, com.fishlib.base.SafeCloneable<com.illumon.dataobjects.generated.DefaultTableDefinition>, com.fishlib.dataobjects.persistence.WObjectStreamConstants, com.fishlib.dataobjects.WAbstractDataObject, Externalizable, Serializable, Cloneable

public class TableDefinition
extends com.illumon.dataobjects.generated.DefaultTableDefinition
Table definition for all Deephaven tables. Adds non-stateful functionality to DefaultTableDefinition.
See Also:
Serialized Form
  • Field Details

  • Constructor Details

    • TableDefinition

      public TableDefinition()
    • TableDefinition

      public TableDefinition​(@NotNull List<Class> types, @NotNull List<String> columnNames)
    • TableDefinition

      public TableDefinition​(@NotNull List<com.illumon.dataobjects.ColumnDefinition> columnDefs)
    • TableDefinition

      public TableDefinition​(@NotNull com.illumon.dataobjects.ColumnDefinition[] columnDefs)
    • TableDefinition

      public TableDefinition​(@NotNull TableDefinition other)
      Creates a partial copy of a TableDefinition. A new object is created, but the ColumnDefinitions of the new object are the same instances as the ColumnDefinitions in the original (other).
      Parameters:
      other - A TableDefinition to partially copy when creating the new definition.
    • TableDefinition

      public TableDefinition​(@NotNull TableDefinition other, boolean setColumns)
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class com.illumon.dataobjects.generated.DefaultTableDefinition
    • append

      public com.fishlib.base.log.LogOutput append​(@NotNull com.fishlib.base.log.LogOutput logOutput)
      Specified by:
      append in interface com.fishlib.base.log.LogOutputAppendable
      Overrides:
      append in class com.illumon.dataobjects.generated.DefaultTableDefinition
    • setColumns

      public void setColumns​(com.illumon.dataobjects.ColumnDefinition[] columns)
      Overrides:
      setColumns in class com.illumon.dataobjects.generated.DefaultTableDefinition
    • getColumnList

      public List<com.illumon.dataobjects.ColumnDefinition> getColumnList()
      Returns:
      A list view of the column definition array for this table definition.
    • getColumnStream

      public Stream<com.illumon.dataobjects.ColumnDefinition> getColumnStream()
      Returns:
      A stream of the column definition array for this table definition
    • getColumnNameMap

      public Map<String,​com.illumon.dataobjects.ColumnDefinition> getColumnNameMap()
      Returns:
      A freshly-allocated, unmodifiable map from column name to column definition.
    • getPartitioningColumns

      public List<com.illumon.dataobjects.ColumnDefinition> getPartitioningColumns()
      Returns:
      A freshly-allocated list of column definitions for all partitioning columns, in the same relative order as in the column definitions array.
    • getGroupingColumns

      public List<com.illumon.dataobjects.ColumnDefinition> getGroupingColumns()
      Returns:
      A freshly-allocated list of column definitions for all grouping columns, in the same relative order as in the column definitions array.
    • getGroupingColumnNamesArray

      public String[] getGroupingColumnNamesArray()
      Returns:
      A freshly-allocated array of column names for all grouping columns, in the same relative order as in the column definitions array.
    • getColumnNames

      public List<String> getColumnNames()
      Returns:
      A freshly-allocated list of column names in the same order as the column definitions array.
    • getColumnNamesArray

      public String[] getColumnNamesArray()
      Returns:
      A freshly-allocated array of column names in the same order as the column definitions array.
    • getColumnTypes

      public List<Class> getColumnTypes()
      Returns:
      A freshly-allocated list of column types in the same order as the column definitions array.
    • getColumnTypesArray

      public Class[] getColumnTypesArray()
      Returns:
      A freshly-allocated array of column types in the same order as the column definitions array.
    • getColumn

      public com.illumon.dataobjects.ColumnDefinition getColumn​(@NotNull String columnName)
      Parameters:
      columnName - the column name to search for
      Returns:
      The column definition for the supplied name, or null if no such column exists in this table definition.
    • getColumnIndex

      public int getColumnIndex​(@NotNull com.illumon.dataobjects.ColumnDefinition column)
      Parameters:
      column - the ColumnDefinition to search for
      Returns:
      The index of the column for the supplied name, or -1 if no such column exists in this table definition. Note: This is an O(columns.length) lookup.
    • getColumnNamesAsString

      public String getColumnNamesAsString()
      Returns:
      A freshly-allocated String of column names joined with ','.
    • checkCompatibility

      public void checkCompatibility​(@NotNull TableDefinition other)
      Test compatibility of this definition with another. This definition must have all columns of the other, and the column definitions in common must be compatible.
      Parameters:
      other - comparison table definition
      Throws:
      TableDefinition.IncompatibleTableDefinitionException - if the definitions are not compatible
    • checkCompatibility

      public void checkCompatibility​(@NotNull TableDefinition other, boolean ignorePartitioningColumns)
      Test compatibility of this definition with another. This definition must have all columns of the other, and the column definitions in common must be compatible. Partitioning columns in other will be ignored if ignorePartitioningColumns is true.
      Parameters:
      other - comparison table definition
      ignorePartitioningColumns - if true, other definition may contain partitioning columns not in this definition
      Throws:
      TableDefinition.IncompatibleTableDefinitionException - if the definitions are not compatible
    • describeDifferences

      public List<String> describeDifferences​(@NotNull TableDefinition other, @NotNull String lhs, @NotNull String rhs)
      Build a description of the difference between this definition and the other. Should correspond to equalsIgnoreOrder logic.
      Parameters:
      other - another TableDefinition to compare
      lhs - what to call "this" definition
      rhs - what to call the other definition
      Returns:
      a list of strings representing the difference between two table definitions
    • getDifferenceDescription

      public String getDifferenceDescription​(@NotNull TableDefinition other, @NotNull String lhs, @NotNull String rhs, @NotNull String separator)
      Build a description of the difference between this definition and the other. Should correspond to equalsIgnoreOrder logic.
      Parameters:
      other - another TableDefinition to compare
      lhs - what to call "this" definition
      rhs - what to call the other definition
      separator - separate strings in the list of differences with this separator
      Returns:
      A string in which the differences are enumerated, separated by the given separator
    • equalsIgnoreOrder

      public boolean equalsIgnoreOrder​(@NotNull TableDefinition other)
      Strict comparison (column-wise only).
      Parameters:
      other - - The other TableDefinition to compare with.
      Returns:
      True if other contains equal ColumnDefinitions in any order. False otherwise.
    • equals

      public boolean equals​(Object other)
      Strict comparison (column-wise only).
      Overrides:
      equals in class com.illumon.dataobjects.generated.DefaultTableDefinition
      Parameters:
      other - - The object to compare with.
      Returns:
      True if other is a TableDefinition and contains equal ColumnDefinitions in the same order. False otherwise.
    • isOnDisk

      @Deprecated public boolean isOnDisk()
      Deprecated.
    • setStorageType

      public void setStorageType​(int storageType)
      Overrides:
      setStorageType in class com.illumon.dataobjects.generated.DefaultTableDefinition
    • isValidStorageType

      public static boolean isValidStorageType​(int storageType)
    • getWritable

      public TableDefinition getWritable()
      Returns:
      This definition if it's writable, or a freshly-allocated definition that is identical but for the columns array, which will exclude all non-writable columns.
    • getWritable

      public TableDefinition getWritable​(boolean partitioningToNormal)
      Parameters:
      partitioningToNormal - Whether partitioning columns should be preserved as normal columns, or excluded
      Returns:
      This definition if it's writable, or a freshly-allocated definition that is identical but for the columns array, which will exclude all non-writable columns, optionally converting partitioning columns to normal columns.
    • getWritableColumns

      public com.illumon.dataobjects.ColumnDefinition[] getWritableColumns​(boolean partitioningToNormal)
      Parameters:
      partitioningToNormal - Whether partitioning columns should be preserved as normal columns, or excluded
      Returns:
      This definition's array of column definitions if they're all writable, or a freshly-allocated array of column definitions which will exclude all non-writable columns, optionally converting partitioning columns to normal columns.
    • persistDefinition

      public static void persistDefinition​(@NotNull TableDefinition definition, @NotNull File destination)
      Persist the supplied TableDefinition to the supplied file.
      Parameters:
      definition - The definition
      destination - The destination file
      Throws:
      UncheckedIOException - if the table definition file could not be written
    • persistDefinition

      @Deprecated public static void persistDefinition​(@NotNull TableDefinition definition, @NotNull File destinationDirectory, @NotNull String tableName)
      Deprecated.
      This method is for backward compatibility. persistDefinition(TableDefinition, File) or persistDefinitionToDirectory(TableDefinition, File) are preferred.
      Persist the supplied TableDefinition to tableName.tbl (given by the parameter) in the given directory. This directory and file name are not necessarily the ones that will be used by the system.
      Parameters:
      definition - The definition
      destinationDirectory - The destination directory
      tableName - The base part of the file name in which to persist the definition
    • persistDefinitionToDirectory

      public static void persistDefinitionToDirectory​(@NotNull TableDefinition definition, @NotNull File destinationDirectory)
      Persist the supplied TableDefinition to the default file for the supplied directory and table name. The default definition file is "table.tbl", but this is subject to change.
      Parameters:
      definition - The definition
      destinationDirectory - The destination directory
    • loadDefinition

      public static TableDefinition loadDefinition​(@NotNull File source)
      Load a TableDefinition from the supplied file.
      Parameters:
      source - The file to find the definition in
      Returns:
      The TableDefinition object
      Throws:
      UncheckedIOException - or other RuntimeException if the file is not found or read fails
    • loadDefinition

      public static TableDefinition loadDefinition​(@NotNull File sourceDirectory, @NotNull String tableName)
      Load a TableDefinition from the "tableName.tbl" file (given by the tableName parameter), in the specified directory. This may not be the file name or location used by the system.
      Parameters:
      sourceDirectory - The directory to find the definition file in
      tableName - The table name to use when determining the definition file name
      Returns:
      The TableDefinition object
      Throws:
      UncheckedIOException - or other RuntimeException if the file is not found or read fails
    • loadDefinition

      @Nullable public static TableDefinition loadDefinition​(@NotNull File sourceDirectory, @NotNull String tableName, boolean allowMissing)
      Load a TableDefinition from the "tableName.tbl" file (given by the tableName parameter), in the specified directory. This may not be the file name or location used by the system.
      Parameters:
      sourceDirectory - The directory to find the definition file in
      tableName - The table name to use when determining the definition file name
      allowMissing - Whether to return null if the file is not found, rather than throwing an exception
      Returns:
      The TableDefinition object, or null if not found and allowMissing
      Throws:
      UncheckedIOException - or other RuntimeException if the file is not found and !allowMissing, or read fails
    • loadDefinitionFromDirectory

      @Nullable public static TableDefinition loadDefinitionFromDirectory​(@NotNull File sourceDirectory, @NotNull String tableName, boolean allowMissing)
      Load a TableDefinition from the implementation-defined default definition file in the specified directory. Currently, this will load "table.tbl" in preference to "tableName.tbl", but that behavior is not guaranteed.
      Parameters:
      sourceDirectory - The directory to find the definition file in
      tableName - The table name to use when determining the implementation-defined definition file name
      allowMissing - Whether to return null if the definition is not found, rather than throwing an exception
      Returns:
      The TableDefinition object, or null if not found and allowMissing
      Throws:
      UncheckedIOException - or other RuntimeException if the file is not found and !allowMissing, or read fails
    • getColumnDefinitionsTable

      public Table getColumnDefinitionsTable()
    • createUserPartitionedTableDefinition

      public static TableDefinition createUserPartitionedTableDefinition​(@NotNull String partitioningColumnName, @NotNull TableDefinition baseDefinition)
      Helper method to assist with definition creation for user-namespace partitioned tables. This version automatically converts grouping columns to normal columns.
      Parameters:
      partitioningColumnName - The name of the column to use for partitioning
      baseDefinition - The definition to work from
      Returns:
      A new definition suitable for passing to OnDiskDatabase.addTableDefinition()
    • createUserPartitionedTableDefinition

      public static TableDefinition createUserPartitionedTableDefinition​(@NotNull String partitioningColumnName, @NotNull TableDefinition baseDefinition, boolean groupingColumnsAsNormal)
      Helper method to assist with definition creation for user-namespace partitioned tables.
      Parameters:
      partitioningColumnName - The name of the column to use for partitioning
      baseDefinition - The definition to work from
      groupingColumnsAsNormal - Whether grouping columns should be converted to normal columns
      Returns:
      A new definition suitable for passing to OnDiskDatabase.addTableDefinition()
    • readExternal

      public void readExternal​(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Overrides:
      readExternal in class com.illumon.dataobjects.generated.DefaultTableDefinition
      Throws:
      IOException
      ClassNotFoundException
    • writeExternal

      public void writeExternal​(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Overrides:
      writeExternal in class com.illumon.dataobjects.generated.DefaultTableDefinition
      Throws:
      IOException
    • main

      public static void main​(String[] args)