Class TableDefinition

java.lang.Object
io.deephaven.engine.table.TableDefinition
All Implemented Interfaces:
LogOutputAppendable

public class TableDefinition extends Object implements LogOutputAppendable
Table definition for all Deephaven tables.
  • Method Details

    • of

      public static TableDefinition of(ColumnDefinition<?>... columnDefinitions)
    • of

      public static TableDefinition of(Collection<ColumnDefinition<?>> columnDefinitions)
    • inferFrom

      public static TableDefinition inferFrom(@NotNull @NotNull Map<String,? extends ColumnSource<?>> sources)
    • from

      public static TableDefinition from(@NotNull @NotNull Iterable<ColumnHeader<?>> headers)
    • from

      public static TableDefinition from(@NotNull @NotNull String[] columnNames, @NotNull @NotNull Class<?>[] columnDataTypes)
      Convenience factory method for use with parallel arrays of column names and data types. All column definitions will have default component type and normal column type.
      Parameters:
      columnNames - An array of column names to use, parallel to columnDataTypes
      columnDataTypes - An array of column data types to use, parallel to columnNames
      Returns:
      The resulting TableDefinition
    • from

      public static TableDefinition from(@NotNull @NotNull Iterable<String> columnNames, @NotNull @NotNull Iterable<Class<?>> columnDataTypes)
      Convenience factory method for use with parallel structures of column names and data types. All column definitions will have default component type and normal column type.
      Parameters:
      columnNames - Column names to use, parallel to columnDataTypes
      columnDataTypes - Column data types to use, parallel to columnNames
      Returns:
      The resulting TableDefinition
    • intern

      public TableDefinition intern()
      Intern this TableDefinition in order to avoid storing many identical instances. Useful (for example) in heavily partitioned workloads.
      Returns:
      An interned TableDefinition that is equal to this
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • append

      public LogOutput append(@NotNull @NotNull LogOutput logOutput)
      Specified by:
      append in interface LogOutputAppendable
    • numColumns

      public int numColumns()
      Returns:
      The number of columns for this table definition
    • getColumns

      public List<ColumnDefinition<?>> getColumns()
      Returns:
      An unmodifiable list of the column definitions for this table definition
    • getColumnsArray

      public ColumnDefinition<?>[] getColumnsArray()
      Returns:
      An array of the column definitions for this table definition
    • getColumnStream

      public Stream<ColumnDefinition<?>> getColumnStream()
      Returns:
      A stream of the column definitions for this table definition
    • getColumnNameMap

      public Map<String,ColumnDefinition<?>> getColumnNameMap()
      Returns:
      An unmodifiable map from column name to column definition
    • getColumnNameSet

      public Set<String> getColumnNameSet()
      Returns:
      An unmodifiable set of column names
    • getPartitioningColumns

      public List<ColumnDefinition<?>> getPartitioningColumns()
      Returns:
      A list of column definitions for all partitioning columns in the same relative order as the column definitions list
    • getColumnNames

      public List<String> getColumnNames()
      Returns:
      The column names as a list in the same order as getColumns()
    • getTypedColumnNames

      public List<ColumnName> getTypedColumnNames()
      Returns:
      The column names as a list in the same order as getColumns()
    • getColumnNamesArray

      public String[] getColumnNamesArray()
      Returns:
      The column names as an array in the same order as getColumns()
    • getColumnTypes

      public List<Class<?>> getColumnTypes()
      Returns:
      The column data types as a list in the same order as getColumns()
    • getColumnTypesArray

      public Class<?>[] getColumnTypesArray()
      Returns:
      The column data types as an array in the same order as getColumns()
    • getColumn

      public <T> ColumnDefinition<T> getColumn(@NotNull @NotNull String columnName)
      Type Parameters:
      T - The column data types, as a type parameter
      Parameters:
      columnName - The column name to search for
      Returns:
      The ColumnDefinition for the supplied name, or null if no such column exists in this table definition
    • getColumnIndex

      public int getColumnIndex(@NotNull @NotNull ColumnDefinition<?> column)
      Parameters:
      column - The ColumnDefinition to search for
      Returns:
      The index of column, or -1 if no such column exists in this table definition
      ApiNote:
      This is an O(numColumns()) lookup.
    • getColumnNamesAsString

      public String getColumnNamesAsString()
      Returns:
      A String of column names joined with ','
    • checkHasColumn

      public final void checkHasColumn(@NotNull @NotNull String columnName)
      Check this definition to ensure that columnName is present.
      Parameters:
      columnName - The column name to check
      Throws:
      NoSuchColumnException - If columnName is missing
    • checkHasColumn

      public final void checkHasColumn(@NotNull @NotNull String columnName, @NotNull @NotNull Class<?> clazz)
      Checks if columnName exists and supports ColumnDefinition.checkCastTo(Class) with clazz. Otherwise, throws a NoSuchColumnException or a ClassCastException.
      Parameters:
      columnName - the column name
      clazz - the data type
      See Also:
    • checkHasColumn

      public final void checkHasColumn(@NotNull @NotNull String columnName, @NotNull @NotNull Class<?> clazz, Class<?> componentType)
      Checks if columnName exists and supports ColumnDefinition.checkCastTo(Class, Class) with clazz and componentType. Otherwise, throws a NoSuchColumnException or a ClassCastException.
      Parameters:
      columnName - the column name
      clazz - the data type
      componentType - the component type
      See Also:
    • checkHasColumns

      public final void checkHasColumns(@NotNull @NotNull Collection<String> columns)
      Check this definition to ensure that all columns are present.
      Parameters:
      columns - The column names to check
      Throws:
      NoSuchColumnException - If any columns were missing
    • checkMutualCompatibility

      public TableDefinition checkMutualCompatibility(@NotNull @NotNull TableDefinition other)
      Tests mutual-compatibility of this and other. To be mutually compatible, they must have the same number of columns, each matched up with ColumnDefinition.isCompatible(io.deephaven.engine.table.ColumnDefinition<?>). As such, this method has an equivalence relation, ie A.checkMutualCompatibility(B) == B.checkMutualCompatibility(A).
      Parameters:
      other - The other definition
      Returns:
      this table definition, but in the column order of other
      Throws:
      TableDefinition.IncompatibleTableDefinitionException - if the definitions are not compatible
    • checkMutualCompatibility

      public TableDefinition checkMutualCompatibility(@NotNull @NotNull TableDefinition other, @NotNull @NotNull String lhsName, @NotNull @NotNull String rhsName)
      Tests mutual-compatibility of this and other. To be mutually compatible, they must have the same number of columns, each matched up with ColumnDefinition.isCompatible(io.deephaven.engine.table.ColumnDefinition<?>). As such, this method has an equivalence relation, ie A.checkMutualCompatibility(B) == B.checkMutualCompatibility(A).
      Parameters:
      other - The other definition
      lhsName - Name to use when describing this if an exception is thrown
      rhsName - Name to use when describing other if an exception is thrown
      Returns:
      this table definition, but in the column order of other
      Throws:
      TableDefinition.IncompatibleTableDefinitionException - if the definitions are not compatible
    • checkCompatibility

      public TableDefinition checkCompatibility(@NotNull @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, as defined by ColumnDefinition.isCompatible(ColumnDefinition).

      Note: unlike ColumnDefinition.isCompatible(ColumnDefinition), this method does not have an equivalence relation. For a stricter check, use checkMutualCompatibility(TableDefinition).

      Parameters:
      other - comparison table definition
      Returns:
      the minimized compatible table definition, in the same order as other
      Throws:
      TableDefinition.IncompatibleTableDefinitionException - if the definitions are not compatible
    • checkCompatibility

      public TableDefinition checkCompatibility(@NotNull @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, as defined by ColumnDefinition.isCompatible(ColumnDefinition).

      Partitioning columns in other will be ignored if ignorePartitioningColumns is true.

      Note: unlike ColumnDefinition.isCompatible(ColumnDefinition), this method does not have an equivalence relation. For a stricter check, use checkMutualCompatibility(TableDefinition).

      Parameters:
      other - comparison table definition
      ignorePartitioningColumns - if true, other definition may contain partitioning columns not in this definition
      Returns:
      the minimized compatible table definition, in the same order as other
      Throws:
      TableDefinition.IncompatibleTableDefinitionException - if the definitions are not compatible
    • describeDifferences

      public List<String> describeDifferences(@NotNull @NotNull TableDefinition other, @NotNull @NotNull String lhs, @NotNull @NotNull String rhs)
      Build a description of the difference between this definition and the other. Should correspond to equalsIgnoreOrder(io.deephaven.engine.table.TableDefinition) 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
    • describeCompatibilityDifferences

      public List<String> describeCompatibilityDifferences(@NotNull @NotNull TableDefinition other, @NotNull @NotNull String lhs, @NotNull @NotNull String rhs)
      Build a description of the difference between this definition and the other. Should correspond to checkMutualCompatibility(io.deephaven.engine.table.TableDefinition) 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 @NotNull TableDefinition other, @NotNull @NotNull String lhs, @NotNull @NotNull String rhs, @NotNull @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 @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 Object
      Parameters:
      other - - The object to compare with.
      Returns:
      True if other is a TableDefinition and contains equal ColumnDefinitions in the same order. False otherwise.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • 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.