use of org.apache.ignite.internal.processors.query.GridQueryFieldsResult in project ignite by apache.
the class DmlStatementsProcessor method streamUpdateQuery.
/**
* Perform given statement against given data streamer. Only rows based INSERT is supported.
*
* @param schemaName Schema name.
* @param streamer Streamer to feed data to.
* @param stmt Statement.
* @param args Statement arguments.
* @return Number of rows in given INSERT statement.
* @throws IgniteCheckedException if failed.
*/
@SuppressWarnings({ "unchecked", "ConstantConditions" })
long streamUpdateQuery(String schemaName, IgniteDataStreamer streamer, PreparedStatement stmt, final Object[] args) throws IgniteCheckedException {
idx.checkStatementStreamable(stmt);
Prepared p = GridSqlQueryParser.prepared(stmt);
assert p != null;
final UpdatePlan plan = getPlanForStatement(schemaName, null, p, null, true, null);
assert plan.isLocalSubquery();
final GridCacheContext cctx = plan.cacheContext();
QueryCursorImpl<List<?>> cur;
final ArrayList<List<?>> data = new ArrayList<>(plan.rowCount());
QueryCursorImpl<List<?>> stepCur = new QueryCursorImpl<>(new Iterable<List<?>>() {
@Override
public Iterator<List<?>> iterator() {
try {
Iterator<List<?>> it;
if (!F.isEmpty(plan.selectQuery())) {
GridQueryFieldsResult res = idx.queryLocalSqlFields(idx.schema(cctx.name()), plan.selectQuery(), F.asList(U.firstNotNull(args, X.EMPTY_OBJECT_ARRAY)), null, false, 0, null);
it = res.iterator();
} else
it = plan.createRows(U.firstNotNull(args, X.EMPTY_OBJECT_ARRAY)).iterator();
return new GridQueryCacheObjectsIterator(it, idx.objectContext(), cctx.keepBinary());
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
}
}, null);
data.addAll(stepCur.getAll());
cur = new QueryCursorImpl<>(new Iterable<List<?>>() {
@Override
public Iterator<List<?>> iterator() {
return data.iterator();
}
}, null);
if (plan.rowCount() == 1) {
IgniteBiTuple t = plan.processRow(cur.iterator().next());
streamer.addData(t.getKey(), t.getValue());
return 1;
}
Map<Object, Object> rows = new LinkedHashMap<>(plan.rowCount());
for (List<?> row : cur) {
final IgniteBiTuple t = plan.processRow(row);
rows.put(t.getKey(), t.getValue());
}
streamer.addData(rows);
return rows.size();
}
use of org.apache.ignite.internal.processors.query.GridQueryFieldsResult in project ignite by apache.
the class IgniteH2Indexing method executeSelect0.
/**
* Execute an all-ready {@link SqlFieldsQuery}.
*
* @param qryId Query id.
* @param qryDesc Plan key.
* @param qryParams Parameters.
* @param select Select.
* @param keepBinary Whether binary objects must not be deserialized automatically.
* @param mvccTracker MVCC tracker.
* @param cancel Query cancel state holder.
* @param inTx Flag whether query is executed within transaction.
* @param timeout Timeout.
* @return Query result.
* @throws IgniteCheckedException On error.
*/
private Iterable<List<?>> executeSelect0(long qryId, QueryDescriptor qryDesc, QueryParameters qryParams, QueryParserResultSelect select, boolean keepBinary, MvccQueryTracker mvccTracker, GridQueryCancel cancel, boolean inTx, int timeout) throws IgniteCheckedException {
assert !select.mvccEnabled() || mvccTracker != null;
// Check security.
if (ctx.security().enabled())
checkSecurity(select.cacheIds());
Iterable<List<?>> iter;
if (select.splitNeeded()) {
// Distributed query.
GridCacheTwoStepQuery twoStepQry = select.forUpdate() && inTx ? select.forUpdateTwoStepQuery() : select.twoStepQuery();
assert twoStepQry != null;
iter = executeSelectDistributed(qryId, qryDesc, qryParams, twoStepQry, keepBinary, mvccTracker, cancel, timeout);
} else {
// Local query.
IndexingQueryFilter filter = (qryDesc.local() ? backupFilter(null, qryParams.partitions()) : null);
GridQueryFieldsResult res = executeSelectLocal(qryId, qryDesc, qryParams, select, filter, mvccTracker, cancel, inTx, timeout);
iter = () -> {
try {
return new GridQueryCacheObjectsIterator(res.iterator(), objectContext(), keepBinary);
} catch (IgniteCheckedException | IgniteSQLException e) {
throw new CacheException(e);
}
};
}
return iter;
}
Aggregations