Search in sources :

Example 21 with GridSqlColumn

use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn in project ignite by apache.

the class GridSqlQueryParser method parseUpdate.

/**
 * @param update Update.
 * @see <a href="http://h2database.com/html/grammar.html#update">H2 update spec</a>
 */
private GridSqlUpdate parseUpdate(Update update) {
    GridSqlUpdate res = (GridSqlUpdate) h2ObjToGridObj.get(update);
    if (res != null)
        return res;
    res = new GridSqlUpdate();
    h2ObjToGridObj.put(update, res);
    GridSqlElement tbl = parseTableFilter(UPDATE_TARGET.get(update));
    List<Column> srcCols = UPDATE_COLUMNS.get(update);
    Map<Column, Expression> srcSet = UPDATE_SET.get(update);
    ArrayList<GridSqlColumn> cols = new ArrayList<>(srcCols.size());
    LinkedHashMap<String, GridSqlElement> set = new LinkedHashMap<>(srcSet.size());
    for (Column c : srcCols) {
        GridSqlColumn col = new GridSqlColumn(c, tbl, null, null, c.getName());
        col.resultType(fromColumn(c));
        cols.add(col);
        set.put(col.columnName(), parseExpression(srcSet.get(c), true));
    }
    GridSqlElement where = parseExpression(UPDATE_WHERE.get(update), true);
    GridSqlElement limit = parseExpression(UPDATE_LIMIT.get(update), true);
    res.target(tbl).cols(cols).set(set).where(where).limit(limit);
    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) Expression(org.h2.expression.Expression) GridSqlType.fromExpression(org.apache.ignite.internal.processors.query.h2.sql.GridSqlType.fromExpression) ValueExpression(org.h2.expression.ValueExpression) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with GridSqlColumn

use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn in project ignite by apache.

the class GridSqlQueryParser method parseMerge.

/**
 * @param merge Merge.
 * @see <a href="http://h2database.com/html/grammar.html#merge">H2 merge spec</a>
 */
private GridSqlMerge parseMerge(Merge merge) {
    GridSqlMerge res = (GridSqlMerge) h2ObjToGridObj.get(merge);
    if (res != null)
        return res;
    res = new GridSqlMerge();
    h2ObjToGridObj.put(merge, res);
    Table srcTbl = MERGE_TABLE.get(merge);
    GridSqlElement tbl = parseTable(srcTbl);
    res.into(tbl);
    Column[] srcCols = MERGE_COLUMNS.get(merge);
    GridSqlColumn[] cols = new GridSqlColumn[srcCols.length];
    for (int i = 0; i < srcCols.length; i++) {
        cols[i] = new GridSqlColumn(srcCols[i], tbl, null, null, srcCols[i].getName());
        cols[i].resultType(fromColumn(srcCols[i]));
    }
    res.columns(cols);
    Column[] srcKeys = MERGE_KEYS.get(merge);
    GridH2Table intoTbl = DmlAstUtils.gridTableForElement(tbl).dataTable();
    GridH2RowDescriptor rowDesc = intoTbl.rowDescriptor();
    GridSqlColumn[] keys = new GridSqlColumn[srcKeys.length];
    for (int i = 0; i < srcKeys.length; i++) {
        String colName = srcKeys[i].getName();
        int colId = intoTbl.getColumn(colName).getColumnId();
        if (!rowDesc.isKeyColumn(colId) && !F.eq(colName, rowDesc.type().affinityKey()))
            throw new IgniteSQLException("Invalid column name in KEYS clause of MERGE - it may include only " + "key and/or affinity columns: " + colName, IgniteQueryErrorCode.PARSING);
        keys[i] = new GridSqlColumn(srcKeys[i], tbl, null, null, colName);
    }
    res.keys(keys);
    List<Expression[]> srcRows = MERGE_ROWS.get(merge);
    if (!srcRows.isEmpty()) {
        List<GridSqlElement[]> rows = new ArrayList<>(srcRows.size());
        for (Expression[] srcRow : srcRows) {
            GridSqlElement[] row = new GridSqlElement[srcRow.length];
            for (int i = 0; i < srcRow.length; i++) row[i] = parseExpression(srcRow[i], false);
            rows.add(row);
        }
        res.rows(rows);
    } else {
        res.rows(Collections.<GridSqlElement[]>emptyList());
        res.query(parseQuery(MERGE_QUERY.get(merge)));
    }
    return res;
}
Also used : 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) ArrayList(java.util.ArrayList) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) 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) Expression(org.h2.expression.Expression) GridSqlType.fromExpression(org.apache.ignite.internal.processors.query.h2.sql.GridSqlType.fromExpression) ValueExpression(org.h2.expression.ValueExpression) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Aggregations

Column (org.h2.table.Column)14 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)12 GridSqlColumn (org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn)12 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)9 GridSqlElement (org.apache.ignite.internal.processors.query.h2.sql.GridSqlElement)9 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)8 GridSqlSelect (org.apache.ignite.internal.processors.query.h2.sql.GridSqlSelect)8 AlterTableAlterColumn (org.h2.command.ddl.AlterTableAlterColumn)7 IndexColumn (org.h2.table.IndexColumn)7 GridSqlTable (org.apache.ignite.internal.processors.query.h2.sql.GridSqlTable)6 GridSqlType.fromColumn (org.apache.ignite.internal.processors.query.h2.sql.GridSqlType.fromColumn)6 ExpressionColumn (org.h2.expression.ExpressionColumn)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)5 Expression (org.h2.expression.Expression)5 LinkedHashMap (java.util.LinkedHashMap)4 GridSqlType.fromExpression (org.apache.ignite.internal.processors.query.h2.sql.GridSqlType.fromExpression)4 ValueExpression (org.h2.expression.ValueExpression)4 HashMap (java.util.HashMap)3