Search in sources :

Example 21 with SqlFieldsQueryEx

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);
    }
}
Also used : FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) BatchUpdateException(java.sql.BatchUpdateException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IgniteException(org.apache.ignite.IgniteException) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx)

Example 22 with SqlFieldsQueryEx

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);
    }
}
Also used : SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) GridQueryFieldMetadata(org.apache.ignite.internal.processors.query.GridQueryFieldMetadata) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) BatchUpdateException(java.sql.BatchUpdateException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Example 23 with SqlFieldsQueryEx

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()));
    }
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx)

Example 24 with SqlFieldsQueryEx

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");
}
Also used : SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) Test(org.junit.Test)

Example 25 with SqlFieldsQueryEx

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);
}
Also used : SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) Test(org.junit.Test)

Aggregations

SqlFieldsQueryEx (org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx)42 Test (org.junit.Test)23 AbstractIndexingCommonTest (org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest)17 List (java.util.List)11 ArrayList (java.util.ArrayList)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)8 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)7 BatchUpdateException (java.sql.BatchUpdateException)6 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)6 FieldsQueryCursor (org.apache.ignite.cache.query.FieldsQueryCursor)5 SQLException (java.sql.SQLException)4 IgniteException (org.apache.ignite.IgniteException)4 QueryCursorImpl (org.apache.ignite.internal.processors.cache.QueryCursorImpl)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 BulkLoadContextCursor (org.apache.ignite.cache.query.BulkLoadContextCursor)3 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)3 IgniteLogger (org.apache.ignite.IgniteLogger)2 QueryCursor (org.apache.ignite.cache.query.QueryCursor)2 GridKernalContext (org.apache.ignite.internal.GridKernalContext)2