Beispiel #1
0
  public static ChangeLevel alterTable(
      DDLFunctions ddlFunctions,
      DMLFunctions dmlFunctions,
      Session session,
      String defaultSchemaName,
      AlterTableNode alterTable,
      QueryContext context) {
    final AkibanInformationSchema curAIS = ddlFunctions.getAIS(session);
    final TableName tableName = convertName(defaultSchemaName, alterTable.getObjectName());
    final Table table = curAIS.getTable(tableName);
    if ((table == null)
        && skipOrThrow(
            context, alterTable.getExistenceCheck(), null, new NoSuchTableException(tableName))) {
      return null;
    }

    if (alterTable.isUpdateStatistics()) {
      Collection<String> indexes = null;
      if (!alterTable.isUpdateStatisticsAll())
        indexes = Collections.singletonList(alterTable.getIndexNameForUpdateStatistics());
      ddlFunctions.updateTableStatistics(session, tableName, indexes);
      return null;
    }

    if (alterTable.isTruncateTable()) {
      dmlFunctions.truncateTable(session, table.getTableId(), alterTable.isCascade());
      return null;
    }

    ChangeLevel level = null;
    if ((alterTable.tableElementList != null) && !alterTable.tableElementList.isEmpty()) {
      level =
          processAlter(
              ddlFunctions,
              session,
              defaultSchemaName,
              table,
              alterTable.tableElementList,
              context);
    }

    if (level == null) {
      throw new UnsupportedSQLException(alterTable.statementToString(), alterTable);
    }
    return level;
  }