Class TableElementList

All Implemented Interfaces:
Iterable<TableElementNode>, Visitable

class TableElementList extends QueryTreeNodeVector<TableElementNode>
A TableElementList represents the list of columns and other table elements such as constraints in a CREATE TABLE or ALTER TABLE statement.
  • Field Details

  • Constructor Details

  • Method Details

    • addTableElement

      void addTableElement(TableElementNode tableElement)
      Add a TableElementNode to this TableElementList
      Parameters:
      tableElement - The TableElementNode to add to this list
    • setCollationTypesOnCharacterStringColumns

      void setCollationTypesOnCharacterStringColumns(SchemaDescriptor sd) throws StandardException
      Use the passed schema descriptor's collation type to set the collation of the character string types in create table node
      Parameters:
      sd -
      Throws:
      StandardException
    • setCollationTypeOnCharacterStringColumn

      void setCollationTypeOnCharacterStringColumn(SchemaDescriptor sd, ColumnDefinitionNode cdn) throws StandardException
      Use the passed schema descriptor's collation type to set the collation of a character string column.
      Parameters:
      sd -
      Throws:
      StandardException
    • validate

      void validate(DDLStatementNode ddlStmt, DataDictionary dd, TableDescriptor td) throws StandardException
      Validate this TableElementList. This includes checking for duplicate columns names, and checking that user types really exist.
      Parameters:
      ddlStmt - DDLStatementNode which contains this list
      dd - DataDictionary to use
      td - TableDescriptor for table, if existing table.
      Throws:
      StandardException - Thrown on error
    • validatePrimaryKeyNullability

      public void validatePrimaryKeyNullability() throws StandardException
      Validate nullability of primary keys. This logic was moved out of the main validate method so that it can be called after binding generation clauses. We need to perform the nullability checks later on because the datatype may be omitted on the generation clause--we can't set/vet the nullability of the datatype until we determine what the datatype is.
      Throws:
      StandardException
    • countConstraints

      int countConstraints(int constraintType)
      Count the number of constraints of the specified type.
      Parameters:
      constraintType - The constraint type to search for.
      Returns:
      int The number of constraints of the specified type.
    • countGenerationClauses

      int countGenerationClauses()
      Count the number of generation clauses.
    • countNumberOfColumns

      int countNumberOfColumns()
      Count the number of columns.
      Returns:
      int The number of columns.
    • genColumnInfos

      int genColumnInfos(ColumnInfo[] colInfos) throws StandardException
      Fill in the ColumnInfo[] for this table element list.
      Parameters:
      colInfos - The ColumnInfo[] to be filled in.
      Returns:
      int The number of constraints in the create table.
      Throws:
      StandardException
    • appendNewColumnsToRCL

      void appendNewColumnsToRCL(FromBaseTable table) throws StandardException
      Append goobered up ResultColumns to the table's RCL. This is useful for binding check constraints for CREATE and ALTER TABLE.
      Parameters:
      table - The table in question.
      Throws:
      StandardException - Thrown on error
    • bindAndValidateCheckConstraints

      void bindAndValidateCheckConstraints(FromList fromList) throws StandardException
      Bind and validate all of the check constraints in this list against the specified FromList.
      Parameters:
      fromList - The FromList in question.
      Throws:
      StandardException - Thrown on error
    • bindAndValidateGenerationClauses

      void bindAndValidateGenerationClauses(SchemaDescriptor sd, FromList fromList, FormatableBitSet generatedColumns, TableDescriptor baseTable) throws StandardException
      Bind and validate all of the generation clauses in this list against the specified FromList.
      Parameters:
      sd - Schema where the table lives.
      fromList - The FromList in question.
      generatedColumns - Bitmap of generated columns in the table. Vacuous for CREATE TABLE, but may be non-trivial for ALTER TABLE. This routine may set bits for new generated columns.
      baseTable - Table descriptor if this is an ALTER TABLE statement.
      Throws:
      StandardException - Thrown on error
    • findIllegalGenerationReferences

      void findIllegalGenerationReferences(FromList fromList, TableDescriptor baseTable) throws StandardException
      Complain if a generation clause references other generated columns. This is required by the SQL Standard, part 2, section 4.14.8.
      Parameters:
      fromList - The FromList in question.
      baseTable - Table descriptor if this is an ALTER TABLE statement.
      Throws:
      StandardException - Thrown on error
    • validateForeignKeysOnGenerationClauses

      void validateForeignKeysOnGenerationClauses(FromList fromList, FormatableBitSet generatedColumns) throws StandardException
      Prevent foreign keys on generated columns from violating the SQL spec, part 2, section 11.8 (), syntax rule 12: the referential action may not specify SET NULL or SET DEFAULT and the update rule may not specify ON UPDATE CASCADE.
      Parameters:
      fromList - The FromList in question.
      generatedColumns - Bitmap of generated columns in the table.
      Throws:
      StandardException - Thrown on error
    • genConstraintActions

      void genConstraintActions(boolean forCreateTable, ConstraintConstantAction[] conActions, String tableName, SchemaDescriptor tableSd, DataDictionary dd) throws StandardException
      Fill in the ConstraintConstantAction[] for this create/alter table.
      Parameters:
      forCreateTable - ConstraintConstantAction is for a create table.
      conActions - The ConstraintConstantAction[] to be filled in.
      tableName - The name of the Table being created.
      tableSd - The schema for that table.
      dd - The DataDictionary
      Throws:
      StandardException - Thrown on failure
    • columnsMatch

      private boolean columnsMatch(String[] columnNames1, String[] columnNames2)
    • genIndexAction

      private IndexConstantAction genIndexAction(boolean forCreateTable, boolean isUnique, boolean isUniqueWithDuplicateNulls, boolean hasDeferrableChecking, boolean initiallyDeferred, String indexName, ConstraintDefinitionNode cdn, String[] columnNames, boolean isConstraint, SchemaDescriptor sd, String tableName, int constraintType, DataDictionary dd) throws StandardException
      utility to generated the call to create the index.

      Parameters:
      forCreateTable - Executed as part of a CREATE TABLE
      isUnique - True means it will be a unique index
      isUniqueWithDuplicateNulls - True means index check and disallow any duplicate key if key has no column with a null value. If any column in the key has a null value, no checking is done and insert will always succeed.
      hasDeferrableChecking - True if index is used to back a deferrable constraint
      initiallyDeferred - True means the deferrable constraint has deferred mode
      indexName - The type of index (BTREE, for example)
      cdn -
      columnNames - Names of the columns in the index, in order.
      isConstraint - TRUE if index is backing up a constraint, else FALSE.
      sd -
      tableName - Name of table the index will be on
      constraintType -
      dd -
      Throws:
      StandardException
    • checkIndexPageSizeProperty

      private Properties checkIndexPageSizeProperty(ConstraintDefinitionNode cdn) throws StandardException
      Checks if the index should use a larger page size. If the columns in the index are large, and if the user hasn't already specified a page size to use, then we may need to default to the large page size in order to get an index with sufficiently large pages. For example, this DDL should use a larger page size for the index that backs the PRIMARY KEY constraint: create table t (x varchar(1000) primary key)
      Parameters:
      cdn - Constraint node
      Returns:
      properties to use for creating the index
      Throws:
      StandardException
    • checkForDuplicateColumns

      private void checkForDuplicateColumns(DDLStatementNode ddlStmt, Set<String> seenNames, String colName) throws StandardException
      Check to make sure that there are no duplicate column names in the list. (The comparison here is case sensitive. The work of converting column names that are not quoted identifiers to upper case is handled by the parser.) RESOLVE: This check will also be performed by alter table.
      Parameters:
      ddlStmt - DDLStatementNode which contains this list
      seenNames - The column names seen so far (for enforcing uniqueness)
      colName - Column name to check for.
      Throws:
      StandardException - Thrown on error
    • checkForDuplicateConstraintNames

      private void checkForDuplicateConstraintNames(DDLStatementNode ddlStmt, Set<String> seenNames, String constraintName) throws StandardException
      Check to make sure that there are no duplicate constraint names in the list. (The comparison here is case sensitive. The work of converting column names that are not quoted identifiers to upper case is handled by the parser.) RESOLVE: This check will also be performed by alter table.
      Parameters:
      ddlStmt - DDLStatementNode which contains this list
      seenNames - The constraint names seen so far (for enforcing uniqueness)
      Throws:
      StandardException - Thrown on error
    • verifyUniqueColumnList

      private void verifyUniqueColumnList(DDLStatementNode ddlStmt, ConstraintDefinitionNode cdn) throws StandardException
      Verify that a primary/unique table constraint has a valid column list. (All columns in table and no duplicates.)
      Parameters:
      ddlStmt - The outer DDLStatementNode
      cdn - The ConstraintDefinitionNode
      Throws:
      StandardException - Thrown if the column list is invalid
    • setColumnListToNotNull

      private void setColumnListToNotNull(ConstraintDefinitionNode cdn)
      Set all columns in that appear in a PRIMARY KEY constraint in a CREATE TABLE statement to NOT NULL.
      Parameters:
      cdn - The ConstraintDefinitionNode for a PRIMARY KEY constraint
    • areColumnsNullable

      private boolean areColumnsNullable(ConstraintDefinitionNode cdn, TableDescriptor td)
      Checks if any of the columns in the constraint can be null.
      Parameters:
      cdn - Constraint node
      td - tabe descriptor of the target table
      Returns:
      true if any of the column can be null false other wise
    • checkForNullColumns

      private void checkForNullColumns(ConstraintDefinitionNode cdn, TableDescriptor td) throws StandardException
      Throws:
      StandardException
    • getColumnDataTypeDescriptor

      private DataTypeDescriptor getColumnDataTypeDescriptor(String colName)
    • getColumnDataTypeDescriptor

      private DataTypeDescriptor getColumnDataTypeDescriptor(String colName, TableDescriptor td)
    • findColumnDefinition

      private ColumnDefinitionNode findColumnDefinition(String colName)
      Find the column definition node in this list that matches the passed in column name.
      Parameters:
      colName -
      Returns:
      Reference to column definition node or null if the column is not in the list.
    • containsColumnName

      boolean containsColumnName(String colName)
      Determine whether or not the parameter matches a column name in this list.
      Parameters:
      colName - The column name to search for.
      Returns:
      boolean Whether or not a match is found.