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;
}
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;
}
Aggregations