use of org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx in project ignite by apache.
the class OdbcRequestHandler method executeBatchQuery.
/**
* {@link OdbcQueryExecuteBatchRequest} command handler.
*
* @param req Execute query request.
* @return Response.
*/
private ClientListenerResponse executeBatchQuery(OdbcQueryExecuteBatchRequest req) {
try {
String sql = OdbcEscapeUtils.parse(req.sqlQuery());
if (log.isDebugEnabled())
log.debug("ODBC query parsed [reqId=" + req.requestId() + ", original=" + req.sqlQuery() + ", parsed=" + sql + ']');
SqlFieldsQueryEx qry = makeQuery(req.schema(), sql, null, req.timeout(), req.autoCommit());
Object[][] paramSet = req.arguments();
if (paramSet.length <= 0)
throw new IgniteException("Batch execute request with non-positive batch length. [len=" + paramSet.length + ']');
// Getting meta and do the checks for the first execution.
for (Object[] set : paramSet) qry.addBatchedArgs(set);
List<FieldsQueryCursor<List<?>>> qryCurs = ctx.query().querySqlFields(null, qry, cliCtx, true, true);
long[] rowsAffected = new long[req.arguments().length];
for (int i = 0; i < qryCurs.size(); ++i) rowsAffected[i] = OdbcUtils.rowsAffected(qryCurs.get(i));
OdbcQueryExecuteBatchResult res = new OdbcQueryExecuteBatchResult(rowsAffected);
return new OdbcResponse(res);
} catch (Exception e) {
U.error(log, "Failed to execute SQL query [reqId=" + req.requestId() + ", req=" + req + ']', e);
return exceptionToBatchResult(e);
}
}
use of org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx in project ignite by apache.
the class OdbcRequestHandler method getResultMeta.
/**
* {@link OdbcQueryGetQueryMetaRequest} command handler.
* Returns metadata for a columns of the result set.
*
* @param req Get resultset metadata request.
* @return Response.
*/
private ClientListenerResponse getResultMeta(OdbcQueryGetResultsetMetaRequest req) {
try {
String sql = OdbcEscapeUtils.parse(req.query());
String schema = OdbcUtils.prepareSchema(req.schema());
SqlFieldsQueryEx qry = makeQuery(schema, sql);
List<GridQueryFieldMetadata> columns = ctx.query().getIndexing().resultMetaData(schema, qry);
Collection<OdbcColumnMeta> meta = OdbcUtils.convertMetadata(columns);
OdbcQueryGetResultsetMetaResult res = new OdbcQueryGetResultsetMetaResult(meta);
return new OdbcResponse(res);
} catch (Exception e) {
U.error(log, "Failed to get resultset metadata [reqId=" + req.requestId() + ", req=" + req + ']', e);
return exceptionToResult(e);
}
}
use of org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx in project ignite by apache.
the class OdbcRequestHandler method processStreamingBatch.
/**
* @param req Request.
* @return Response.
*/
private ClientListenerResponse processStreamingBatch(OdbcStreamingBatchRequest req) {
assert cliCtx.isStream();
// Send back only the first error. Others will be written to the log.
IgniteBiTuple<Integer, String> firstErr = new IgniteBiTuple<>();
SqlFieldsQueryEx qry = null;
for (OdbcQuery q : req.queries()) {
if (q.sql() != null) {
// If we have a new query string in the batch,
if (// then execute the previous sub-batch and create a new SqlFieldsQueryEx.
qry != null)
processStreamingBatch(qry, firstErr);
qry = makeQuery(req.schemaName(), q.sql());
}
assert qry != null;
qry.addBatchedArgs(q.args());
}
if (qry != null)
processStreamingBatch(qry, firstErr);
if (req.last())
cliCtx.disableStreaming();
if (firstErr.isEmpty())
return new OdbcResponse(new OdbcStreamingBatchResult(req.order()));
else {
assert firstErr.getKey() != null;
return new OdbcResponse(new OdbcStreamingBatchResult(firstErr.getKey(), firstErr.getValue(), req.order()));
}
}
use of org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx in project ignite by apache.
the class WarningOnBigQueryResultsTest method testQueryCacheTest0.
/**
*/
@Test
public void testQueryCacheTest0() throws Exception {
assertEquals(KEYS_PER_NODE * 2, grid("cli").context().query().querySqlFields(new SqlFieldsQueryEx("SELECT * FROM TEST0 ORDER BY val DESC", true).setSchema("TEST0"), false).getAll().size());
assertEquals(6, listener(grid("cli")).messageCount());
assertEquals(Arrays.asList(10L, 30L, 90L, 270L, 810L, 2000L), listener(grid("cli")).fetched);
checkDurations(listener(grid("cli")).duration);
assertEquals("REDUCE", listener(grid("cli")).type);
assertEquals("TEST0", listener(grid("cli")).schema);
assertFalse(listener(grid("cli")).enforceJoinOrder);
assertFalse(listener(grid("cli")).distributedJoin);
assertFalse(listener(grid("cli")).lazy);
checkStateAfterQuery0("TEST0");
}
use of org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx in project ignite by apache.
the class WarningOnBigQueryResultsTest method testQueryCacheTest1.
/**
*/
@Test
public void testQueryCacheTest1() throws Exception {
assertEquals(KEYS_PER_NODE * 2, grid("cli").context().query().querySqlFields(new SqlFieldsQueryEx("SELECT * FROM TEST1", true).setSchema("TEST1").setLazy(true).setEnforceJoinOrder(true), false).getAll().size());
assertEquals(0, listener(grid(0)).messageCount());
assertEquals(0, listener(grid(1)).messageCount());
assertEquals(6, listener(grid(2)).messageCount());
assertEquals(2, listener(grid(3)).messageCount());
assertEquals(Arrays.asList(50L, 100L, 200L, 400L, 800L, 1000L), listener(grid(2)).fetched);
assertEquals(Arrays.asList(100L, 1000L), listener(grid(3)).fetched);
checkDurations(listener(grid(2)).duration);
checkDurations(listener(grid(3)).duration);
assertEquals("MAP", listener(grid(2)).type);
assertEquals("MAP", listener(grid(3)).type);
assertEquals("TEST1", listener(grid(2)).schema);
assertEquals("TEST1", listener(grid(3)).schema);
assertTrue(listener(grid(2)).enforceJoinOrder);
assertTrue(listener(grid(3)).enforceJoinOrder);
assertFalse(listener(grid(2)).distributedJoin);
assertFalse(listener(grid(3)).distributedJoin);
assertTrue(listener(grid(2)).lazy);
assertTrue(listener(grid(3)).lazy);
}
Aggregations