use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlSubquery in project ignite by apache.
the class DmlAstUtils method findParams.
/**
* @param el Element.
* @param params Parameters.
* @param target Extracted parameters.
* @param paramIdxs Parameter indexes.
*/
private static void findParams(@Nullable GridSqlElement el, Object[] params, ArrayList<Object> target, IntArray paramIdxs) {
if (el == null)
return;
if (el instanceof GridSqlParameter) {
// H2 Supports queries like "select ?5" but first 4 non-existing parameters are need to be set to any value.
// Here we will set them to NULL.
final int idx = ((GridSqlParameter) el).index();
while (target.size() < idx) target.add(null);
if (params.length <= idx)
throw new IgniteException("Invalid number of query parameters. " + "Cannot find " + idx + " parameter.");
Object param = params[idx];
if (idx == target.size())
target.add(param);
else
target.set(idx, param);
paramIdxs.add(idx);
} else if (el instanceof GridSqlSubquery)
findParams(((GridSqlSubquery) el).subquery(), params, target, paramIdxs);
else
for (int i = 0; i < el.size(); i++) findParams((GridSqlElement) el.child(i), params, target, paramIdxs);
}
use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlSubquery in project ignite by apache.
the class DmlAstUtils method injectKeysFilterParam.
/**
* Append additional condition to WHERE for it to select only specific keys.
*
* @param where Initial condition.
* @param keyCol Column to base the new condition on.
* @return New condition.
*/
private static GridSqlElement injectKeysFilterParam(GridSqlElement where, GridSqlColumn keyCol, int paramIdx) {
// Yes, we need a subquery for "WHERE _key IN ?" to work with param being an array without dirty query rewriting.
GridSqlSelect sel = new GridSqlSelect();
GridSqlFunction from = new GridSqlFunction(GridSqlFunctionType.TABLE);
sel.from(from);
GridSqlColumn col = new GridSqlColumn(null, from, null, "TABLE", "_IGNITE_ERR_KEYS");
sel.addColumn(col, true);
GridSqlAlias alias = new GridSqlAlias("_IGNITE_ERR_KEYS", new GridSqlParameter(paramIdx));
alias.resultType(keyCol.resultType());
from.addChild(alias);
GridSqlElement e = new GridSqlOperation(GridSqlOperationType.IN, keyCol, new GridSqlSubquery(sel));
if (where == null)
return e;
else
return new GridSqlOperation(GridSqlOperationType.AND, where, e);
}
Aggregations