Search in sources :

Example 6 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDDL method compileCreateIndex.

// A VoltDB extension to support indexed expressions and the assume unique attribute
StatementSchema compileCreateIndex(boolean unique, boolean assumeUnique) {
    /* disable 1 line ...
    StatementSchema compileCreateIndex(boolean unique) {
    ... disabled 1 line */
    // End of VoltDB extension
    Table table;
    HsqlName indexHsqlName;
    read();
    indexHsqlName = readNewSchemaObjectName(SchemaObject.INDEX);
    readThis(Tokens.ON);
    table = readTableName();
    HsqlName tableSchema = table.getSchemaName();
    indexHsqlName.setSchemaIfNull(tableSchema);
    indexHsqlName.parent = table.getName();
    if (indexHsqlName.schema != tableSchema) {
        throw Error.error(ErrorCode.X_42505);
    }
    indexHsqlName.schema = table.getSchemaName();
    // A VoltDB extension to support indexed expressions and the assume unique attribute
    java.util.List<Boolean> ascDesc = new java.util.ArrayList<Boolean>();
    // A VoltDB extension to "readColumnList(table, true)" to support indexed expressions.
    java.util.List<Expression> indexExprs = XreadExpressions(ascDesc);
    OrderedHashSet set = getSimpleColumnNames(indexExprs);
    int[] indexColumns = null;
    if (set == null) {
        // A VoltDB extension to support indexed expressions.
        // Not just indexing columns.
        // The meaning of set and indexColumns shifts here to be
        // the set of unique base columns for the indexed expressions.
        set = getBaseColumnNames(indexExprs);
    } else {
        // Just indexing columns -- by-pass extended support for generalized index expressions.
        indexExprs = null;
    }
    // A VoltDB extension to support partial index
    Expression predicate = null;
    if (readIfThis(Tokens.WHERE)) {
        predicate = XreadBooleanValueExpression();
    }
    indexColumns = getColumnList(set, table);
    String sql = getLastPart();
    Object[] args = new Object[] { table, indexColumns, indexHsqlName, Boolean.valueOf(unique), indexExprs, Boolean.valueOf(assumeUnique), predicate };
    return new StatementSchema(sql, StatementTypes.CREATE_INDEX, args, null, table.getName());
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 7 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDDL method readTableAsSubqueryDefinition.

StatementSchema readTableAsSubqueryDefinition(Table table) {
    HsqlName readName = null;
    boolean withData = true;
    HsqlName[] columnNames = null;
    Statement statement = null;
    if (token.tokenType == Tokens.OPENBRACKET) {
        columnNames = readColumnNames(table.getName());
    }
    readThis(Tokens.AS);
    readThis(Tokens.OPENBRACKET);
    QueryExpression queryExpression = XreadQueryExpression();
    queryExpression.setAsTopLevel();
    queryExpression.resolve(session);
    readThis(Tokens.CLOSEBRACKET);
    readThis(Tokens.WITH);
    if (token.tokenType == Tokens.NO) {
        read();
        withData = false;
    } else if (table.getTableType() == TableBase.TEXT_TABLE) {
        throw unexpectedTokenRequire(Tokens.T_NO);
    }
    readThis(Tokens.DATA);
    if (token.tokenType == Tokens.ON) {
        if (!table.isTemp()) {
            throw unexpectedToken();
        }
        read();
        readThis(Tokens.COMMIT);
        if (token.tokenType == Tokens.DELETE) {
        } else if (token.tokenType == Tokens.PRESERVE) {
            table.persistenceScope = TableBase.SCOPE_SESSION;
        }
        read();
        readThis(Tokens.ROWS);
    }
    TableUtil.setColumnsInSchemaTable(table, queryExpression.getResultColumnNames(), queryExpression.getColumnTypes());
    if (columnNames != null) {
        if (columnNames.length != queryExpression.getColumnCount()) {
            throw Error.error(ErrorCode.X_42593);
        }
        for (int i = 0; i < columnNames.length; i++) {
            table.getColumn(i).getName().rename(columnNames[i]);
        }
    }
    table.createPrimaryKey();
    if (withData) {
        statement = new StatementQuery(session, queryExpression, compileContext);
    }
    Object[] args = new Object[] { table, null, statement };
    String sql = getLastPart();
    StatementSchema st = new StatementSchema(sql, StatementTypes.CREATE_TABLE, args, null, null);
    st.readTableNames = statement.getTableNamesForRead();
    return st;
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 8 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDDL method readConstraint.

/**
     * Reads and adds a table constraint definition to the list
     *
     * @param schemaObject table or domain
     * @param constraintList list of constraints
     */
private void readConstraint(SchemaObject schemaObject, HsqlArrayList constraintList) {
    HsqlName constName = null;
    boolean isAutogeneratedName = true;
    if (token.tokenType == Tokens.CONSTRAINT) {
        read();
        constName = readNewDependentSchemaObjectName(schemaObject.getName(), SchemaObject.CONSTRAINT);
        isAutogeneratedName = false;
    }
    // A VoltDB extension to support indexed expressions and the assume unique attribute
    // For VoltDB
    boolean assumeUnique = false;
    // End of VoltDB extension
    switch(token.tokenType) {
        case Tokens.PRIMARY:
            {
                if (schemaObject.getName().type != SchemaObject.TABLE) {
                    throw this.unexpectedTokenRequire(Tokens.T_CHECK);
                }
                read();
                readThis(Tokens.KEY);
                Constraint mainConst;
                mainConst = (Constraint) constraintList.get(0);
                if (mainConst.constType == Constraint.PRIMARY_KEY) {
                    throw Error.error(ErrorCode.X_42532);
                }
                if (constName == null) {
                    constName = database.nameManager.newAutoName("PK", schemaObject.getSchemaName(), schemaObject.getName(), SchemaObject.CONSTRAINT);
                }
                OrderedHashSet set = readColumnNames(false);
                Constraint c = new Constraint(constName, isAutogeneratedName, set, Constraint.PRIMARY_KEY);
                constraintList.set(0, c);
                break;
            }
        // A VoltDB extension to support indexed expressions and the assume unique attribute
        case Tokens.ASSUMEUNIQUE:
            assumeUnique = true;
        // End of VoltDB extension
        case Tokens.UNIQUE:
            {
                if (schemaObject.getName().type != SchemaObject.TABLE) {
                    throw this.unexpectedTokenRequire(Tokens.T_CHECK);
                }
                read();
                // A VoltDB extension to "readColumnNames(false)" to support indexed expressions.
                java.util.List<Expression> indexExprs = XreadExpressions(null);
                OrderedHashSet set = getSimpleColumnNames(indexExprs);
                if (constName == null) {
                    constName = database.nameManager.newAutoName("CT", schemaObject.getSchemaName(), schemaObject.getName(), SchemaObject.CONSTRAINT);
                }
                // A VoltDB extension to support indexed expressions.
                boolean hasNonColumnExprs = false;
                if (set == null) {
                    hasNonColumnExprs = true;
                    set = getBaseColumnNames(indexExprs);
                }
                // End of VoltDB extension
                Constraint c = new Constraint(constName, isAutogeneratedName, set, Constraint.UNIQUE);
                // A VoltDB extension to support indexed expressions and assume unique attribute.
                c.setAssumeUnique(assumeUnique);
                if (hasNonColumnExprs) {
                    c = c.withExpressions(indexExprs.toArray(new Expression[indexExprs.size()]));
                }
                // End of VoltDB extension
                constraintList.add(c);
                break;
            }
        case Tokens.FOREIGN:
            {
                if (schemaObject.getName().type != SchemaObject.TABLE) {
                    throw this.unexpectedTokenRequire(Tokens.T_CHECK);
                }
                read();
                readThis(Tokens.KEY);
                OrderedHashSet set = readColumnNames(false);
                Constraint c = readFKReferences((Table) schemaObject, constName, set);
                constraintList.add(c);
                break;
            }
        case Tokens.CHECK:
            {
                read();
                if (constName == null) {
                    constName = database.nameManager.newAutoName("CT", schemaObject.getSchemaName(), schemaObject.getName(), SchemaObject.CONSTRAINT);
                }
                Constraint c = new Constraint(constName, isAutogeneratedName, null, Constraint.CHECK);
                readCheckConstraintCondition(c);
                constraintList.add(c);
                break;
            }
        // A VoltDB extension to support LIMIT PARTITION ROWS
        case Tokens.LIMIT:
            {
                read();
                for (int i = 0; i < constraintList.size(); i++) {
                    if (((Constraint) constraintList.get(i)).getConstraintType() == Constraint.LIMIT) {
                        throw Error.error(ErrorCode.X_42524, String.format("Multiple LIMIT PARTITION ROWS constraints on table %s are forbidden.", schemaObject.getName().name));
                    }
                }
                if (constName == null) {
                    constName = database.nameManager.newAutoName("LIMIT", schemaObject.getSchemaName(), schemaObject.getName(), SchemaObject.CONSTRAINT);
                }
                Constraint c = new Constraint(constName, isAutogeneratedName, null, Constraint.LIMIT);
                readLimitConstraintCondition(c);
                constraintList.add(c);
                break;
            }
        // End of VoltDB extension
        default:
            {
                if (constName != null) {
                    throw Error.error(ErrorCode.X_42581);
                }
            }
    }
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) HsqlList(org.hsqldb_voltpatches.lib.HsqlList) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList)

Example 9 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDDL method processAlterTableRename.

/**
     * Responsible for handling tail of ALTER TABLE ... RENAME ...
     * @param table table
     */
void processAlterTableRename(Table table) {
    HsqlName name = readNewSchemaObjectName(SchemaObject.TABLE);
    name.setSchemaIfNull(table.getSchemaName());
    if (table.getSchemaName() != name.schema) {
        throw Error.error(ErrorCode.X_42505);
    }
    database.schemaManager.renameSchemaObject(table.getName(), name);
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 10 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDQL method readNewSchemaObjectNameNoCheck.

HsqlName readNewSchemaObjectNameNoCheck(int type) {
    checkIsSchemaObjectName();
    HsqlName hsqlName = database.nameManager.newHsqlName(token.tokenString, isDelimitedIdentifier(), type);
    if (token.namePrefix != null) {
        if (type == SchemaObject.GRANTEE) {
            throw unexpectedToken();
        }
        HsqlName schemaName = session.database.schemaManager.findSchemaHsqlName(token.namePrefix);
        if (schemaName == null) {
            schemaName = database.nameManager.newHsqlName(token.namePrefix, isDelimitedIdentifier(), SchemaObject.SCHEMA);
        }
        hsqlName.setSchemaIfNull(schemaName);
    }
    read();
    return hsqlName;
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Aggregations

HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)204 Table (org.hsqldb_voltpatches.Table)86 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)73 TextTable (org.hsqldb_voltpatches.TextTable)65 Iterator (org.hsqldb_voltpatches.lib.Iterator)64 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)61 SchemaObject (org.hsqldb_voltpatches.SchemaObject)60 Constraint (org.hsqldb_voltpatches.Constraint)59 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)48 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)22 HsqlException (org.hsqldb_voltpatches.HsqlException)20 Type (org.hsqldb_voltpatches.types.Type)20 Session (org.hsqldb_voltpatches.Session)16 Result (org.hsqldb_voltpatches.result.Result)15 Grantee (org.hsqldb_voltpatches.rights.Grantee)12 NumberType (org.hsqldb_voltpatches.types.NumberType)10 Routine (org.hsqldb_voltpatches.Routine)7 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)7 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 Index (org.hsqldb_voltpatches.index.Index)6