Search in sources :

Example 1 with AlterTableAlterColumn

use of org.h2.command.ddl.AlterTableAlterColumn in project ignite by apache.

the class GridSqlQueryParser method parseAddColumn.

/**
 * Parse {@code ALTER TABLE ... ADD COLUMN} statement.
 * @param addCol H2 statement.
 * @return Grid SQL statement.
 *
 * @see <a href="http://www.h2database.com/html/grammar.html#alter_table_add"></a>
 */
private GridSqlStatement parseAddColumn(AlterTableAlterColumn addCol) {
    assert addCol.getType() == CommandInterface.ALTER_TABLE_ADD_COLUMN;
    if (ALTER_COLUMN_BEFORE_COL.get(addCol) != null || ALTER_COLUMN_AFTER_COL.get(addCol) != null)
        throw new IgniteSQLException("ALTER TABLE ADD COLUMN BEFORE/AFTER is not supported", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
    GridSqlAlterTableAddColumn res = new GridSqlAlterTableAddColumn();
    ArrayList<Column> h2NewCols = ALTER_COLUMN_NEW_COLS.get(addCol);
    GridSqlColumn[] gridNewCols = new GridSqlColumn[h2NewCols.size()];
    for (int i = 0; i < h2NewCols.size(); i++) {
        Column col = h2NewCols.get(i);
        if (col.getDefaultExpression() != null)
            throw new IgniteSQLException("ALTER TABLE ADD COLUMN with DEFAULT value is not supported " + "[col=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
        gridNewCols[i] = parseColumn(h2NewCols.get(i));
    }
    res.columns(gridNewCols);
    if (gridNewCols.length == 1)
        res.ifNotExists(ALTER_COLUMN_IF_NOT_EXISTS.get(addCol));
    res.ifTableExists(ALTER_COLUMN_IF_TBL_EXISTS.get(addCol));
    Schema schema = SCHEMA_COMMAND_SCHEMA.get(addCol);
    res.schemaName(schema.getName());
    res.tableName(ALTER_COLUMN_TBL_NAME.get(addCol));
    return res;
}
Also used : GridSqlType.fromColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlType.fromColumn) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) Column(org.h2.table.Column) ExpressionColumn(org.h2.expression.ExpressionColumn) IndexColumn(org.h2.table.IndexColumn) Schema(org.h2.schema.Schema) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint)

Example 2 with AlterTableAlterColumn

use of org.h2.command.ddl.AlterTableAlterColumn in project ignite by apache.

the class GridSqlQueryParser method parseDropColumn.

/**
 * Parse {@code ALTER TABLE ... DROP COLUMN} statement.
 * @param dropCol H2 statement.
 * @see <a href="http://www.h2database.com/html/grammar.html#alter_table_add"></a>
 */
private GridSqlStatement parseDropColumn(AlterTableAlterColumn dropCol) {
    assert dropCol.getType() == CommandInterface.ALTER_TABLE_DROP_COLUMN;
    GridSqlAlterTableDropColumn res = new GridSqlAlterTableDropColumn();
    ArrayList<Column> h2DropCols = ALTER_COLUMN_REMOVE_COLS.get(dropCol);
    String[] gridDropCols = new String[h2DropCols.size()];
    for (int i = 0; i < h2DropCols.size(); i++) gridDropCols[i] = h2DropCols.get(i).getName();
    res.columns(gridDropCols);
    if (gridDropCols.length == 1)
        res.ifExists(!ALTER_COLUMN_IF_NOT_EXISTS.get(dropCol));
    res.ifTableExists(ALTER_COLUMN_IF_TBL_EXISTS.get(dropCol));
    Schema schema = SCHEMA_COMMAND_SCHEMA.get(dropCol);
    res.schemaName(schema.getName());
    res.tableName(ALTER_COLUMN_TBL_NAME.get(dropCol));
    return res;
}
Also used : GridSqlType.fromColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlType.fromColumn) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) Column(org.h2.table.Column) ExpressionColumn(org.h2.expression.ExpressionColumn) IndexColumn(org.h2.table.IndexColumn) Schema(org.h2.schema.Schema) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint)

Aggregations

GridSqlType.fromColumn (org.apache.ignite.internal.processors.query.h2.sql.GridSqlType.fromColumn)2 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)2 AlterTableAlterColumn (org.h2.command.ddl.AlterTableAlterColumn)2 ExpressionColumn (org.h2.expression.ExpressionColumn)2 Schema (org.h2.schema.Schema)2 Column (org.h2.table.Column)2 IndexColumn (org.h2.table.IndexColumn)2 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)1