Search in sources :

Example 21 with TableView

use of org.h2.table.TableView in project ignite by apache.

the class GridSqlQueryParser method parseTable.

/**
 * @param tbl Table.
 */
private GridSqlElement parseTable(Table tbl) {
    GridSqlElement res = (GridSqlElement) h2ObjToGridObj.get(tbl);
    if (res == null) {
        // Table here is semantically equivalent to a table filter.
        if (tbl instanceof TableBase || tbl instanceof MetaTable)
            return new GridSqlTable(tbl);
        // different table filters anyways. Thus the semantics will be correct.
        if (tbl instanceof TableView) {
            if (((TableView) tbl).isRecursive()) {
                throw new IgniteSQLException("Recursive CTE ('WITH RECURSIVE (...)') is not supported.", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
            }
            Query qry = VIEW_QUERY.get((TableView) tbl);
            res = new GridSqlSubquery(parseQuery(qry));
        } else if (tbl instanceof FunctionTable)
            res = parseExpression(FUNC_EXPR.get((FunctionTable) tbl), false);
        else if (tbl instanceof RangeTable) {
            res = new GridSqlFunction(GridSqlFunctionType.SYSTEM_RANGE);
            res.addChild(parseExpression(RANGE_MIN.get((RangeTable) tbl), false));
            res.addChild(parseExpression(RANGE_MAX.get((RangeTable) tbl), false));
        } else if (tbl instanceof MetaTable)
            res = new GridSqlTable(tbl);
        else
            assert0(false, "Unexpected Table implementation [cls=" + tbl.getClass().getSimpleName() + ']');
        h2ObjToGridObj.put(tbl, res);
    }
    return res;
}
Also used : Query(org.h2.command.dml.Query) FunctionTable(org.h2.table.FunctionTable) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) MetaTable(org.h2.table.MetaTable) TableBase(org.h2.table.TableBase) TableView(org.h2.table.TableView) RangeTable(org.h2.table.RangeTable)

Example 22 with TableView

use of org.h2.table.TableView in project ignite by apache.

the class GridSqlQueryParser method collectOptimizedTableFiltersOrder.

/**
 * @param qry Query.
 */
private void collectOptimizedTableFiltersOrder(Query qry) {
    if (qry instanceof SelectUnion) {
        collectOptimizedTableFiltersOrder(((SelectUnion) qry).getLeft());
        collectOptimizedTableFiltersOrder(((SelectUnion) qry).getRight());
    } else {
        Select select = (Select) qry;
        TableFilter filter = select.getTopTableFilter();
        int i = 0;
        do {
            assert0(filter != null, select);
            assert0(filter.getNestedJoin() == null, select);
            // Here all the table filters must have generated unique aliases,
            // thus we can store them in the same map for all the subqueries.
            optimizedTableFilterOrder.put(filter.getTableAlias(), i++);
            Table tbl = filter.getTable();
            // Go down and collect inside of optimized subqueries.
            if (tbl instanceof TableView) {
                ViewIndex viewIdx = (ViewIndex) filter.getIndex();
                collectOptimizedTableFiltersOrder(viewIdx.getQuery());
            }
            filter = filter.getJoin();
        } while (filter != null);
    }
}
Also used : SelectUnion(org.h2.command.dml.SelectUnion) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) RangeTable(org.h2.table.RangeTable) MetaTable(org.h2.table.MetaTable) CreateTable(org.h2.command.ddl.CreateTable) FunctionTable(org.h2.table.FunctionTable) Table(org.h2.table.Table) DropTable(org.h2.command.ddl.DropTable) TableFilter(org.h2.table.TableFilter) ConditionInSelect(org.h2.expression.ConditionInSelect) Select(org.h2.command.dml.Select) ViewIndex(org.h2.index.ViewIndex) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) TableView(org.h2.table.TableView)

Aggregations

TableView (org.h2.table.TableView)14 Table (org.h2.table.Table)10 Column (org.h2.table.Column)8 ArrayList (java.util.ArrayList)6 Query (org.h2.command.dml.Query)6 ExpressionColumn (org.h2.expression.ExpressionColumn)6 Constraint (org.h2.constraint.Constraint)5 DbObject (org.h2.engine.DbObject)5 Schema (org.h2.schema.Schema)5 IndexColumn (org.h2.table.IndexColumn)5 Sequence (org.h2.schema.Sequence)4 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)3 AlterTableAlterColumn (org.h2.command.ddl.AlterTableAlterColumn)3 AlterTableRenameColumn (org.h2.command.ddl.AlterTableRenameColumn)3 CreateTable (org.h2.command.ddl.CreateTable)3 DropTable (org.h2.command.ddl.DropTable)3 Index (org.h2.index.Index)3 DbException (org.h2.message.DbException)3 TriggerObject (org.h2.schema.TriggerObject)3 FunctionTable (org.h2.table.FunctionTable)3