All Implemented Interfaces:
IOptionContainer, IRelation, ISearchPath, IStatement, IStatementContainer, ITable, IHashable
Direct Known Subclasses:
ChTableLog

public class ChTable extends ChAbstractStatement implements ITable, IOptionContainer
Represents a ClickHouse table with engine configuration and projections. Supports ClickHouse-specific features like table engines, projections, and specialized DDL operations.
  • Constructor Details

    • ChTable

      public ChTable(String name)
      Creates a new ClickHouse table with the specified name.
      Parameters:
      name - the name of the table
  • Method Details

    • getCreationSQL

      public void getCreationSQL(SQLScript script)
      Description copied from interface: IStatement
      Generates the SQL statements needed to create this database object. This is an abstract method that must be implemented by subclasses to provide the specific CREATE SQL for each object type.
      Specified by:
      getCreationSQL in interface IStatement
      Parameters:
      script - the SQL script to append creation statements to
    • appendAlterSQL

      public ObjectState appendAlterSQL(IStatement newCondition, SQLScript script)
      Description copied from interface: IStatement
      Fill script with object changes and return change type
      Specified by:
      appendAlterSQL in interface IStatement
      Parameters:
      newCondition - new object state
      script - script to collect changes
      Returns:
      object change type
    • isRecreated

      public boolean isRecreated(ITable newTable, ISettings settings)
      Description copied from interface: ITable
      Compares this table with the newTable to determine if a full table recreation is required. A full recreation (DROP and CREATE) is needed when the tables differ in ways that cannot be altered using ALTER TABLE statements.
      Specified by:
      isRecreated in interface ITable
      Parameters:
      newTable - the new table definition to compare against
      settings - application settings that may affect the comparison logic
      Returns:
      true if the table requires recreation (DROP and CREATE) rather than being alterable, false if the changes can be applied via ALTER TABLE
    • getAlterTable

      public String getAlterTable(boolean only)
    • compareOptions

      public void compareOptions(IOptionContainer newContainer, SQLScript script)
      Description copied from interface: IOptionContainer
      Compares options between this container and a new container, generating SQL to update differences.
      Specified by:
      compareOptions in interface IOptionContainer
      Parameters:
      newContainer - the new container to compare against
      script - the script to append changes to
    • compareIgnoringColumnOrder

      public boolean compareIgnoringColumnOrder(ITable newTable)
      Specified by:
      compareIgnoringColumnOrder in interface ITable
      Parameters:
      newTable - new state of the table
      Returns:
      true if the tables are identical
    • appendMoveDataSql

      public void appendMoveDataSql(IStatement newCondition, SQLScript script, String tblTmpBareName, List<String> identityCols)
      Description copied from interface: ITable
      Adds commands to the script for move data from the temporary table to the new table, given the identity columns, and a command to delete the temporary table.
      Specified by:
      appendMoveDataSql in interface ITable
    • addProjection

      public void addProjection(String key, String expression)
      Adds a projection to this table.
      Parameters:
      key - the projection name
      expression - the projection expression
    • setEngine

      public void setEngine(ChEngine engine)
    • setPkExpr

      public void setPkExpr(String pkExpr)
    • fillChildrenList

      public void fillChildrenList(List<Collection<? extends AbstractStatement>> l)
      Overrides:
      fillChildrenList in class AbstractStatement
    • isClustered

      public boolean isClustered()
      Checks if this container has any clustered indexes or constraints.
    • getChild

      public AbstractStatement getChild(String name, DbObjType type)
      Description copied from interface: IStatementContainer
      Gets a child statement by name and type.
      Specified by:
      getChild in interface IStatementContainer
      Parameters:
      name - the name of the child to find
      type - the type of the child to find
      Returns:
      the child statement, or null if not found
    • getChildrenByType

      public Collection<IStatement> getChildrenByType(DbObjType type)
      Description copied from interface: IStatementContainer
      get all children by type
      Specified by:
      getChildrenByType in interface IStatementContainer
      Parameters:
      type - the type of the children
      Returns:
      unmodifiable collection of child statement, or empty list
    • addChild

      public void addChild(IStatement st)
      Description copied from interface: IStatementContainer
      Adds a child statement to this container.
      Specified by:
      addChild in interface IStatementContainer
      Parameters:
      st - the child statement to add
    • getColumn

      public ChColumn getColumn(String name)
      Finds column according to specified column name.
      Specified by:
      getColumn in interface ITable
      Parameters:
      name - name of the column to be searched
      Returns:
      found column or null if no such column has been found
    • getColumns

      public List<IColumn> getColumns()
      Getter for columns. The list cannot be modified.
      Specified by:
      getColumns in interface ITable
      Returns:
      columns
    • getConstraints

      public Collection<IConstraint> getConstraints()
      Specified by:
      getConstraints in interface ITable
    • getRelationColumns

      public Stream<Pair<String,String>> getRelationColumns()
      Description copied from interface: IRelation
      Gets the columns of this relation as name-type pairs.
      Specified by:
      getRelationColumns in interface IRelation
      Returns:
      a stream of column name and type pairs
    • getOptions

      public Map<String,String> getOptions()
      Description copied from interface: IOptionContainer
      Gets all options for this container.
      Specified by:
      getOptions in interface IOptionContainer
      Returns:
      a map of option keys to values
    • getOption

      public String getOption(String option)
      Gets the value for the specified option.
      Parameters:
      option - the option key
      Returns:
      the option value, or null if not found
    • addOption

      public void addOption(String option, String value)
      Description copied from interface: IOptionContainer
      Adds an option to this container.
      Specified by:
      addOption in interface IOptionContainer
      Parameters:
      option - the option key
      value - the option value
    • addColumn

      public void addColumn(ChColumn column)
      Adds a column to the table.
      Parameters:
      column - the column to add
    • containsColumn

      public boolean containsColumn(String name)
      Checks if a column with the specified name exists.
      Parameters:
      name - the column name
      Returns:
      true if column exists, false otherwise
    • computeHash

      public void computeHash(Hasher hasher)
      Description copied from interface: IHashable
      Computes the hash of the implementing object using the provided hasher. The implementation should call appropriate put methods on the hasher for all fields that should contribute to the hash value.
      Specified by:
      computeHash in interface IHashable
      Parameters:
      hasher - the hasher instance to use for hash computation
    • computeChildrenHash

      public void computeChildrenHash(Hasher hasher)
    • compare

      public boolean compare(IStatement obj)
      Description copied from class: AbstractStatement
      This method does not account for nested child PgStatements. Shallow version of AbstractStatement.equals(Object)
      Specified by:
      compare in interface IStatement
      Overrides:
      compare in class AbstractStatement
    • compareChildren

      public boolean compareChildren(AbstractStatement obj)
      Description copied from class: AbstractStatement
      Deep part of AbstractStatement.equals(Object). Compares all object's child PgStatements for equality.
      Overrides:
      compareChildren in class AbstractStatement