Search in sources :

Example 6 with OrderedHashSet

use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.

the class ParserDQL method XreadTableReference.

void XreadTableReference(QuerySpecification select) {
    boolean natural = false;
    RangeVariable range = readTableOrSubquery();
    select.addRangeVariable(range);
    while (true) {
        int type = token.tokenType;
        boolean left = false;
        boolean right = false;
        boolean end = false;
        type = token.tokenType;
        switch(token.tokenType) {
            case Tokens.INNER:
                read();
                readThis(Tokens.JOIN);
                break;
            case Tokens.CROSS:
                if (natural) {
                    throw unexpectedToken();
                }
                read();
                readThis(Tokens.JOIN);
                break;
            case Tokens.UNION:
                if (natural) {
                    throw unexpectedToken();
                }
                int position = getPosition();
                read();
                if (token.tokenType == Tokens.JOIN) {
                    read();
                    break;
                } else {
                    rewind(position);
                    end = true;
                    break;
                }
            case Tokens.NATURAL:
                if (natural) {
                    throw unexpectedToken();
                }
                read();
                natural = true;
                continue;
            case Tokens.LEFT:
                read();
                readIfThis(Tokens.OUTER);
                readThis(Tokens.JOIN);
                left = true;
                break;
            case Tokens.RIGHT:
                read();
                readIfThis(Tokens.OUTER);
                readThis(Tokens.JOIN);
                right = true;
                break;
            case Tokens.FULL:
                read();
                readIfThis(Tokens.OUTER);
                readThis(Tokens.JOIN);
                left = true;
                right = true;
                break;
            case Tokens.JOIN:
                read();
                type = Tokens.INNER;
                break;
            case Tokens.COMMA:
                if (natural) {
                    throw unexpectedToken();
                }
                read();
                type = Tokens.CROSS;
                break;
            default:
                if (natural) {
                    throw unexpectedToken();
                }
                end = true;
                break;
        }
        if (end) {
            break;
        }
        range = readTableOrSubquery();
        Expression condition = null;
        switch(type) {
            case Tokens.CROSS:
                select.addRangeVariable(range);
                break;
            case Tokens.UNION:
                select.addRangeVariable(range);
                condition = Expression.EXPR_FALSE;
                range.setJoinType(true, true);
                break;
            case Tokens.LEFT:
            case Tokens.RIGHT:
            case Tokens.INNER:
            case Tokens.FULL:
                {
                    if (natural) {
                        OrderedHashSet columns = range.getUniqueColumnNameSet();
                        condition = select.getEquiJoinExpressions(columns, range, false);
                        select.addRangeVariable(range);
                    } else if (token.tokenType == Tokens.USING) {
                        read();
                        OrderedHashSet columns = new OrderedHashSet();
                        readThis(Tokens.OPENBRACKET);
                        readSimpleColumnNames(columns, range);
                        readThis(Tokens.CLOSEBRACKET);
                        condition = select.getEquiJoinExpressions(columns, range, true);
                        select.addRangeVariable(range);
                    } else if (token.tokenType == Tokens.ON) {
                        read();
                        condition = XreadBooleanValueExpression();
                        select.addRangeVariable(range);
                    // must ensure references are limited to the current table
                    //                        select.finaliseRangeVariables();
                    //                        select.resolveColumnReferencesAndAllocate(condition);
                    } else {
                        throw Error.error(ErrorCode.X_42581);
                    }
                    range.setJoinType(left, right);
                    break;
                }
        }
        range.addJoinCondition(condition);
        natural = false;
    }
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 7 with OrderedHashSet

use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.

the class ParserDQL method readColumnNameList.

OrderedHashSet readColumnNameList(BitMap quotedFlags, boolean readAscDesc) {
    int i = 0;
    OrderedHashSet set = new OrderedHashSet();
    while (true) {
        if (session.isProcessingScript) {
            // SEE: ENG-912
            if (!isSimpleName(strictSQLNames)) {
                /* disable 1 line ...
                if (!isSimpleName()) {
                ... disabled 1 line */
                // End of VoltDB extension
                token.isDelimitedIdentifier = true;
            }
        } else {
            // A VoltDB extension to make reserved words more consistent.
            checkIsSimpleName(strictSQLNames);
        /* disable 1 line ...
                checkIsSimpleName();
                ... disabled 1 line */
        // End of VoltDB extension
        }
        if (!set.add(token.tokenString)) {
            throw Error.error(ErrorCode.X_42577, token.tokenString);
        }
        if (quotedFlags != null && isDelimitedIdentifier()) {
            quotedFlags.set(i);
        }
        read();
        i++;
        if (readAscDesc) {
            if (token.tokenType == Tokens.ASC || token.tokenType == Tokens.DESC) {
                read();
            }
        }
        if (readIfThis(Tokens.COMMA)) {
            continue;
        }
        break;
    }
    return set;
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 8 with OrderedHashSet

use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.

the class ParserDML method compileMergeStatement.

/**
     * Retrieves a MERGE Statement from this parse context.
     */
StatementDMQL compileMergeStatement(RangeVariable[] outerRanges) {
    boolean[] insertColumnCheckList;
    int[] insertColumnMap = null;
    int[] updateColumnMap = null;
    int[] baseUpdateColumnMap;
    Table table;
    RangeVariable targetRange;
    RangeVariable sourceRange;
    Expression mergeCondition;
    HsqlArrayList updateList = new HsqlArrayList();
    Expression[] updateExpressions = null;
    HsqlArrayList insertList = new HsqlArrayList();
    Expression insertExpression = null;
    read();
    readThis(Tokens.INTO);
    targetRange = readSimpleRangeVariable(StatementTypes.MERGE);
    table = targetRange.rangeTable;
    readThis(Tokens.USING);
    sourceRange = readTableOrSubquery();
    // parse ON search conditions
    readThis(Tokens.ON);
    mergeCondition = XreadBooleanValueExpression();
    if (mergeCondition.getDataType() != Type.SQL_BOOLEAN) {
        throw Error.error(ErrorCode.X_42568);
    }
    RangeVariable[] fullRangeVars = new RangeVariable[] { sourceRange, targetRange };
    RangeVariable[] sourceRangeVars = new RangeVariable[] { sourceRange };
    RangeVariable[] targetRangeVars = new RangeVariable[] { targetRange };
    // parse WHEN clause(s) and convert lists to arrays
    insertColumnMap = table.getColumnMap();
    insertColumnCheckList = table.getNewColumnCheckList();
    OrderedHashSet updateColNames = new OrderedHashSet();
    OrderedHashSet insertColNames = new OrderedHashSet();
    readMergeWhen(insertColNames, updateColNames, insertList, updateList, targetRangeVars, sourceRange);
    if (insertList.size() > 0) {
        int colCount = insertColNames.size();
        if (colCount != 0) {
            insertColumnMap = table.getColumnIndexes(insertColNames);
            insertColumnCheckList = table.getColumnCheckList(insertColumnMap);
        }
        insertExpression = (Expression) insertList.get(0);
        setParameterTypes(insertExpression, table, insertColumnMap);
    }
    if (updateList.size() > 0) {
        updateExpressions = new Expression[updateList.size()];
        updateList.toArray(updateExpressions);
        updateColumnMap = table.getColumnIndexes(updateColNames);
    }
    if (updateExpressions != null) {
        Table baseTable = table.getBaseTable();
        baseUpdateColumnMap = updateColumnMap;
        if (table != baseTable) {
            baseUpdateColumnMap = new int[updateColumnMap.length];
            ArrayUtil.projectRow(table.getBaseTableColumnMap(), updateColumnMap, baseUpdateColumnMap);
        }
        resolveUpdateExpressions(table, sourceRangeVars, updateColumnMap, updateExpressions, outerRanges);
    }
    HsqlList unresolved = null;
    unresolved = mergeCondition.resolveColumnReferences(fullRangeVars, null);
    ExpressionColumn.checkColumnsResolved(unresolved);
    mergeCondition.resolveTypes(session, null);
    if (mergeCondition.isParam()) {
        mergeCondition.dataType = Type.SQL_BOOLEAN;
    }
    if (mergeCondition.getDataType() != Type.SQL_BOOLEAN) {
        throw Error.error(ErrorCode.X_42568);
    }
    RangeVariableResolver resolver = new RangeVariableResolver(fullRangeVars, mergeCondition, compileContext);
    resolver.processConditions();
    fullRangeVars = resolver.rangeVariables;
    if (insertExpression != null) {
        unresolved = insertExpression.resolveColumnReferences(sourceRangeVars, unresolved);
        ExpressionColumn.checkColumnsResolved(unresolved);
        insertExpression.resolveTypes(session, null);
    }
    StatementDMQL cs = new StatementDML(session, fullRangeVars, insertColumnMap, updateColumnMap, insertColumnCheckList, mergeCondition, insertExpression, updateExpressions, compileContext);
    return cs;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) HsqlList(org.hsqldb_voltpatches.lib.HsqlList) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 9 with OrderedHashSet

use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.

the class ParserDDL method compileTriggerSetStatement.

/**
     * Creates SET Statement for a trigger row from this parse context.
     */
StatementDMQL compileTriggerSetStatement(Table table, RangeVariable[] rangeVars) {
    read();
    Expression[] updateExpressions;
    int[] columnMap;
    OrderedHashSet colNames = new OrderedHashSet();
    HsqlArrayList exprList = new HsqlArrayList();
    RangeVariable[] targetRangeVars = new RangeVariable[] { rangeVars[TriggerDef.NEW_ROW] };
    readSetClauseList(targetRangeVars, colNames, exprList);
    columnMap = table.getColumnIndexes(colNames);
    updateExpressions = new Expression[exprList.size()];
    exprList.toArray(updateExpressions);
    resolveUpdateExpressions(table, rangeVars, columnMap, updateExpressions, RangeVariable.emptyArray);
    StatementDMQL cs = new StatementDML(session, table, rangeVars, columnMap, updateExpressions, compileContext);
    return cs;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 10 with OrderedHashSet

use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.

the class ParserDDL method compileAlterTableAddUniqueConstraint.

// A VoltDB extension to support the assume unique attribute
Statement compileAlterTableAddUniqueConstraint(Table table, HsqlName name, boolean assumeUnique) {
    if (name == null) {
        name = database.nameManager.newAutoName("CT", table.getSchemaName(), table.getName(), SchemaObject.CONSTRAINT);
    }
    // A VoltDB extension to support indexed expressions.
    java.util.List<Expression> indexExprs = XreadExpressions(null);
    OrderedHashSet set = getSimpleColumnNames(indexExprs);
    int[] cols = getColumnList(set, table);
    if ((indexExprs != null) && (cols == null)) {
        // Not just indexing columns.
        // The meaning of cols shifts here to be
        // the set of unique base columns for the indexed expressions.
        set = getBaseColumnNames(indexExprs);
        cols = getColumnList(set, table);
    }
    /* disable 1 line ...
        int[] cols = this.readColumnList(table, false);
        ... disabled 1 line */
    // End of VoltDB extension
    String sql = getLastPart();
    // A VoltDB extension to support the assume unique attribute and indexed expressions
    Object[] args = new Object[] { cols, name, indexExprs, Boolean.valueOf(assumeUnique) };
    return new StatementSchema(sql, StatementTypes.ALTER_TABLE, args, null, table.getName());
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Aggregations

OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)86 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)47 Iterator (org.hsqldb_voltpatches.lib.Iterator)26 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)24 Constraint (org.hsqldb_voltpatches.Constraint)19 SchemaObject (org.hsqldb_voltpatches.SchemaObject)19 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)19 Table (org.hsqldb_voltpatches.Table)18 HsqlException (org.hsqldb_voltpatches.HsqlException)16 TextTable (org.hsqldb_voltpatches.TextTable)16 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)11 HsqlList (org.hsqldb_voltpatches.lib.HsqlList)8 Grantee (org.hsqldb_voltpatches.rights.Grantee)6 Routine (org.hsqldb_voltpatches.Routine)5 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)5 Right (org.hsqldb_voltpatches.rights.Right)5 TriggerDef (org.hsqldb_voltpatches.TriggerDef)4 OrderedIntHashSet (org.hsqldb_voltpatches.lib.OrderedIntHashSet)3 Type (org.hsqldb_voltpatches.types.Type)3 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)2