Search in sources :

Example 1 with SimpleName

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

the class ParserDQL method readSimpleRangeVariable.

protected RangeVariable readSimpleRangeVariable(int operation) {
    Table table = readTableName();
    SimpleName alias = null;
    if (operation != StatementTypes.DELETE_WHERE) {
        if (token.tokenType == Tokens.AS) {
            read();
            checkIsNonCoreReservedIdentifier();
        }
        if (isNonCoreReservedIdentifier()) {
            alias = HsqlNameManager.getSimpleName(token.tokenString, isDelimitedIdentifier());
            read();
        }
    }
    if (table.isView) {
        switch(operation) {
            case StatementTypes.MERGE:
                if (!table.isUpdatable() || !table.isInsertable()) {
                    throw Error.error(ErrorCode.X_42545);
                }
                break;
            case StatementTypes.UPDATE_WHERE:
            case StatementTypes.DELETE_WHERE:
                /* A VoltDB Extension.
                     * Views from Streams are now updatable.
                     * Comment out this guard and check if it is a view
                     * from Stream or PersistentTable in planner.
                    if (!table.isUpdatable()) {
                        throw Error.error(ErrorCode.X_42545);
                    }
                    A VoltDB Extension */
                break;
        }
        SubQuery sq = getViewSubquery((View) table);
        table = sq.getTable();
    }
    RangeVariable range = new RangeVariable(table, alias, null, null, compileContext);
    return range;
}
Also used : SimpleName(org.hsqldb_voltpatches.HsqlNameManager.SimpleName)

Example 2 with SimpleName

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

the class QuerySpecification method setReferenceableColumns.

void setReferenceableColumns() {
    accessibleColumns = new boolean[indexLimitVisible];
    IntValueHashMap aliases = new IntValueHashMap();
    // Bundle up all the user defined aliases here.
    // We can't import java.util.Set because there is a Set
    // already imported into this class from Hsql itself.
    java.util.Set<String> userAliases = new java.util.HashSet<>();
    // Bundle up all the generated aliases here.
    java.util.Map<String, Integer> genAliases = new java.util.HashMap<>();
    for (int i = 0; i < indexLimitVisible; i++) {
        Expression expression = exprColumns[i];
        String alias = expression.getAlias();
        if (alias.length() == 0) {
            SimpleName name = HsqlNameManager.getAutoColumnName(i);
            expression.setAlias(name);
            genAliases.put(name.name, i);
            continue;
        }
        int index = aliases.get(alias, -1);
        userAliases.add(alias);
        if (index == -1) {
            aliases.put(alias, i);
            accessibleColumns[i] = true;
        } else {
            accessibleColumns[index] = false;
        }
    }
    for (java.util.Map.Entry<String, Integer> genAlias : genAliases.entrySet()) {
        String alias = genAlias.getKey();
        while (userAliases.contains(alias)) {
            alias = "_" + alias;
        }
        if (!alias.equals(genAlias.getKey())) {
            int idx = genAlias.getValue();
            SimpleName realAlias = HsqlNameManager.getAutoColumnName(alias);
            exprColumns[idx].setAlias(realAlias);
        }
    }
}
Also used : IntValueHashMap(org.hsqldb_voltpatches.lib.IntValueHashMap) SimpleName(org.hsqldb_voltpatches.HsqlNameManager.SimpleName) IntValueHashMap(org.hsqldb_voltpatches.lib.IntValueHashMap) IntValueHashMap(org.hsqldb_voltpatches.lib.IntValueHashMap) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HashSet(org.hsqldb_voltpatches.lib.HashSet) OrderedIntHashSet(org.hsqldb_voltpatches.lib.OrderedIntHashSet)

Example 3 with SimpleName

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

the class QuerySpecification method createResultTable.

@Override
void createResultTable(Session session) {
    HsqlName tableName;
    HashMappedList columnList;
    int tableType;
    tableName = session.database.nameManager.getSubqueryTableName();
    tableType = persistenceScope == TableBase.SCOPE_STATEMENT ? TableBase.SYSTEM_SUBQUERY : TableBase.RESULT_TABLE;
    columnList = new HashMappedList();
    for (int i = 0; i < indexLimitVisible; i++) {
        Expression e = exprColumns[i];
        SimpleName simpleName = e.getSimpleName();
        String nameString = simpleName.name;
        HsqlName name = session.database.nameManager.newColumnSchemaHsqlName(tableName, simpleName);
        if (!accessibleColumns[i]) {
            nameString = HsqlNameManager.getAutoNoNameColumnString(i);
        }
        ColumnSchema column = new ColumnSchema(name, e.dataType, true, false, null);
        columnList.add(nameString, column);
    }
    try {
        resultTable = new TableDerived(session.database, tableName, tableType, columnTypes, columnList, null);
    } catch (Exception e) {
    }
}
Also used : HashMappedList(org.hsqldb_voltpatches.lib.HashMappedList) SimpleName(org.hsqldb_voltpatches.HsqlNameManager.SimpleName) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 4 with SimpleName

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

the class ParserDQL method readTableOrSubquery.

/**
     * Creates a RangeVariable from the parse context. <p>
     */
protected RangeVariable readTableOrSubquery() {
    Table table = null;
    SimpleName alias = null;
    OrderedHashSet columnList = null;
    BitMap columnNameQuoted = null;
    SimpleName[] columnNameList = null;
    if (token.tokenType == Tokens.OPENBRACKET) {
        Expression e = XreadTableSubqueryOrJoinedTable();
        table = e.subQuery.getTable();
        if (table instanceof TableDerived) {
            ((TableDerived) table).dataExpression = e;
        }
    } else {
        table = readTableName();
        if (table.isView()) {
            SubQuery sq = getViewSubquery((View) table);
            //                sq.queryExpression = ((View) table).queryExpression;
            table = sq.getTable();
        }
    }
    boolean hasAs = false;
    if (token.tokenType == Tokens.AS) {
        read();
        checkIsNonCoreReservedIdentifier();
        hasAs = true;
    }
    if (isNonCoreReservedIdentifier()) {
        boolean limit = token.tokenType == Tokens.LIMIT || token.tokenType == Tokens.OFFSET;
        int position = getPosition();
        alias = HsqlNameManager.getSimpleName(token.tokenString, isDelimitedIdentifier());
        read();
        if (token.tokenType == Tokens.OPENBRACKET) {
            columnNameQuoted = new BitMap(32);
            columnList = readColumnNames(columnNameQuoted, false);
        } else if (!hasAs && limit) {
            if (token.tokenType == Tokens.QUESTION || token.tokenType == Tokens.X_VALUE) {
                alias = null;
                rewind(position);
            }
        }
    }
    if (columnList != null) {
        if (table.getColumnCount() != columnList.size()) {
            throw Error.error(ErrorCode.X_42593);
        }
        columnNameList = new SimpleName[columnList.size()];
        for (int i = 0; i < columnList.size(); i++) {
            SimpleName name = HsqlNameManager.getSimpleName((String) columnList.get(i), columnNameQuoted.isSet(i));
            columnNameList[i] = name;
        }
    }
    RangeVariable range = new RangeVariable(table, alias, columnList, columnNameList, compileContext);
    return range;
}
Also used : BitMap(org.hsqldb_voltpatches.store.BitMap) SimpleName(org.hsqldb_voltpatches.HsqlNameManager.SimpleName) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Aggregations

SimpleName (org.hsqldb_voltpatches.HsqlNameManager.SimpleName)4 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)2 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)1 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)1 HashSet (org.hsqldb_voltpatches.lib.HashSet)1 IntValueHashMap (org.hsqldb_voltpatches.lib.IntValueHashMap)1 OrderedIntHashSet (org.hsqldb_voltpatches.lib.OrderedIntHashSet)1 BitMap (org.hsqldb_voltpatches.store.BitMap)1