Search in sources :

Example 1 with QueryContext

use of org.apache.ignite.internal.sql.engine.QueryContext in project ignite-3 by apache.

the class JdbcQueryEventHandlerImpl method batchPrepStatementAsync.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<BatchExecuteResult> batchPrepStatementAsync(BatchPreparedStmntRequest req) {
    IntList res = new IntArrayList(req.getArgs().size());
    QueryContext context = createQueryContext(JdbcStatementType.UPDATE_STATEMENT_TYPE);
    try {
        for (Object[] arg : req.getArgs()) {
            executeAndCollectUpdateCount(context, req.schemaName(), req.getQuery(), arg, res);
        }
    } catch (Exception e) {
        return handleBatchException(e, req.getQuery(), res);
    }
    return CompletableFuture.completedFuture(new BatchExecuteResult(res.toIntArray()));
}
Also used : QueryContext(org.apache.ignite.internal.sql.engine.QueryContext) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) BatchExecuteResult(org.apache.ignite.client.proto.query.event.BatchExecuteResult) QueryValidationException(org.apache.ignite.internal.sql.engine.exec.QueryValidationException) IntList(it.unimi.dsi.fastutil.ints.IntList)

Example 2 with QueryContext

use of org.apache.ignite.internal.sql.engine.QueryContext in project ignite-3 by apache.

the class JdbcQueryEventHandlerImpl method queryAsync.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<QueryExecuteResult> queryAsync(QueryExecuteRequest req) {
    if (req.pageSize() <= 0) {
        return CompletableFuture.completedFuture(new QueryExecuteResult(Response.STATUS_FAILED, "Invalid fetch size : [fetchSize=" + req.pageSize() + ']'));
    }
    List<SqlCursor<List<?>>> cursors;
    try {
        QueryContext context = createQueryContext(req.getStmtType());
        List<SqlCursor<List<?>>> queryCursors = processor.query(context, req.schemaName(), req.sqlQuery(), req.arguments() == null ? OBJECT_EMPTY_ARRAY : req.arguments());
        cursors = queryCursors.stream().map(cursor -> new JdbcQueryCursor<>(req.maxRows(), cursor)).collect(Collectors.toList());
    } catch (Exception e) {
        StringWriter sw = getWriterWithStackTrace(e);
        return CompletableFuture.completedFuture(new QueryExecuteResult(Response.STATUS_FAILED, "Exception while executing query " + req.sqlQuery() + ". Error message: " + sw));
    }
    if (cursors.isEmpty()) {
        return CompletableFuture.completedFuture(new QueryExecuteResult(Response.STATUS_FAILED, "At least one cursor is expected for query " + req.sqlQuery()));
    }
    List<QuerySingleResult> results = new ArrayList<>();
    try {
        for (SqlCursor<List<?>> cur : cursors) {
            QuerySingleResult res = createJdbcResult(cur, req);
            results.add(res);
        }
    } catch (Exception ex) {
        StringWriter sw = getWriterWithStackTrace(ex);
        return CompletableFuture.completedFuture(new QueryExecuteResult(Response.STATUS_FAILED, "Failed to fetch results for query " + req.sqlQuery() + ". Error message: " + sw));
    }
    return CompletableFuture.completedFuture(new QueryExecuteResult(results));
}
Also used : SqlCursor(org.apache.ignite.internal.sql.engine.SqlCursor) StringWriter(java.io.StringWriter) QueryExecuteResult(org.apache.ignite.client.proto.query.event.QueryExecuteResult) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) ArrayList(java.util.ArrayList) IntList(it.unimi.dsi.fastutil.ints.IntList) QueryContext(org.apache.ignite.internal.sql.engine.QueryContext) QuerySingleResult(org.apache.ignite.client.proto.query.event.QuerySingleResult) QueryValidationException(org.apache.ignite.internal.sql.engine.exec.QueryValidationException)

Example 3 with QueryContext

use of org.apache.ignite.internal.sql.engine.QueryContext in project ignite-3 by apache.

the class JdbcQueryEventHandlerImpl method batchAsync.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<BatchExecuteResult> batchAsync(BatchExecuteRequest req) {
    List<String> queries = req.queries();
    IntList res = new IntArrayList(queries.size());
    QueryContext context = createQueryContext(JdbcStatementType.UPDATE_STATEMENT_TYPE);
    for (String query : queries) {
        try {
            executeAndCollectUpdateCount(context, req.schemaName(), query, OBJECT_EMPTY_ARRAY, res);
        } catch (Exception e) {
            return handleBatchException(e, query, res);
        }
    }
    return CompletableFuture.completedFuture(new BatchExecuteResult(res.toIntArray()));
}
Also used : QueryContext(org.apache.ignite.internal.sql.engine.QueryContext) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) BatchExecuteResult(org.apache.ignite.client.proto.query.event.BatchExecuteResult) QueryValidationException(org.apache.ignite.internal.sql.engine.exec.QueryValidationException) IntList(it.unimi.dsi.fastutil.ints.IntList)

Aggregations

IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)3 IntList (it.unimi.dsi.fastutil.ints.IntList)3 QueryContext (org.apache.ignite.internal.sql.engine.QueryContext)3 QueryValidationException (org.apache.ignite.internal.sql.engine.exec.QueryValidationException)3 BatchExecuteResult (org.apache.ignite.client.proto.query.event.BatchExecuteResult)2 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 QueryExecuteResult (org.apache.ignite.client.proto.query.event.QueryExecuteResult)1 QuerySingleResult (org.apache.ignite.client.proto.query.event.QuerySingleResult)1 SqlCursor (org.apache.ignite.internal.sql.engine.SqlCursor)1