Java Code Examples for org.apache.ignite.cache.query.SqlFieldsQuery#setPageSize()

The following examples show how to use org.apache.ignite.cache.query.SqlFieldsQuery#setPageSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteH2Indexing.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override public SqlFieldsQuery generateFieldsQuery(String cacheName, SqlQuery qry) {
    String schemaName = schema(cacheName);

    String type = qry.getType();

    H2TableDescriptor tblDesc = schemaMgr.tableForType(schemaName, cacheName, type);

    if (tblDesc == null)
        throw new IgniteSQLException("Failed to find SQL table for type: " + type,
            IgniteQueryErrorCode.TABLE_NOT_FOUND);

    String sql;

    try {
        sql = generateFieldsQueryString(qry.getSql(), qry.getAlias(), tblDesc);
    }
    catch (IgniteCheckedException e) {
        throw new IgniteException(e);
    }

    SqlFieldsQuery res = new SqlFieldsQuery(sql);

    res.setArgs(qry.getArgs());
    res.setDistributedJoins(qry.isDistributedJoins());
    res.setLocal(qry.isLocal());
    res.setPageSize(qry.getPageSize());
    res.setPartitions(qry.getPartitions());
    res.setReplicatedOnly(qry.isReplicatedOnly());
    res.setSchema(schemaName);
    res.setSql(sql);

    if (qry.getTimeout() > 0)
        res.setTimeout(qry.getTimeout(), TimeUnit.MILLISECONDS);

    return res;
}
 
Example 2
Source File: SqlQueryHistorySelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Test metrics for SQL fields queries.
 *
 * @throws Exception In case of error.
 */
@Test
public void testSqlFieldsQueryHistoryNotFullyFetched() throws Exception {
    SqlFieldsQuery qry = new SqlFieldsQuery("select * from String");
    qry.setPageSize(10);

    checkQueryNotFullyFetchedMetrics(qry, false);
}
 
Example 3
Source File: SqlQueryHistorySelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Test metrics for SQL cross cache queries.
 *
 * @throws Exception In case of error.
 */
@Test
public void testSqlFieldsQueryHistoryCrossCacheQueryNotFullyFetched() throws Exception {
    SqlFieldsQuery qry = new SqlFieldsQuery("select * from \"B\".String");
    qry.setPageSize(10);

    checkQueryNotFullyFetchedMetrics(qry, false);
}
 
Example 4
Source File: CacheAbstractQueryMetricsSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Test metrics for SQL fields queries.
 *
 * @throws Exception In case of error.
 */
@Test
public void testSqlFieldsQueryNotFullyFetchedMetrics() throws Exception {
    IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");

    SqlFieldsQuery qry = new SqlFieldsQuery("select * from String");
    qry.setPageSize(10);

    checkQueryNotFullyFetchedMetrics(cache, qry, false);
}
 
Example 5
Source File: CacheAbstractQueryMetricsSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Test metrics for SQL cross cache queries.
 *
 * @throws Exception In case of error.
 */
@Test
public void testSqlFieldsCrossCacheQueryNotFullyFetchedMetrics() throws Exception {
    IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");

    SqlFieldsQuery qry = new SqlFieldsQuery("select * from \"B\".String");
    qry.setPageSize(10);

    checkQueryNotFullyFetchedMetrics(cache, qry, false);
}
 
Example 6
Source File: CacheAbstractQueryDetailMetricsSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Test metrics for SQL fields queries.
 *
 * @throws Exception In case of error.
 */
@Test
public void testSqlFieldsQueryNotFullyFetchedMetrics() throws Exception {
    IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");

    SqlFieldsQuery qry = new SqlFieldsQuery("select * from String");
    qry.setPageSize(10);

    checkQueryNotFullyFetchedMetrics(cache, qry, false);
}
 
Example 7
Source File: CacheAbstractQueryDetailMetricsSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Test metrics for SQL cross cache queries.
 *
 * @throws Exception In case of error.
 */
@Test
public void testSqlFieldsCrossCacheQueryNotFullyFetchedMetrics() throws Exception {
    IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");

    SqlFieldsQuery qry = new SqlFieldsQuery("select * from \"B\".String");
    qry.setPageSize(10);

    checkQueryNotFullyFetchedMetrics(cache, qry, false);
}
 
Example 8
Source File: JdbcStatement.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Sets parameters to query object. Logic should be consistent with {@link JdbcQueryTask#call()} and {@link
 * JdbcQueryMultipleStatementsTask#call()}. Parameters are determined from context: connection state and this
 * statement state.
 *
 * @param qry query which parameters to set up
 */
protected void setupQuery(SqlFieldsQuery qry) {
    qry.setPageSize(fetchSize);
    qry.setLocal(conn.nodeId() == null);
    qry.setCollocated(conn.isCollocatedQuery());
    qry.setDistributedJoins(conn.isDistributedJoins());
    qry.setEnforceJoinOrder(conn.isEnforceJoinOrder());
    qry.setLazy(conn.isLazy());
    qry.setSchema(conn.schemaName());
}
 
Example 9
Source File: GridMapQueryExecutor.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param node Node.
 * @param req DML request.
 */
public void onDmlRequest(final ClusterNode node, final GridH2DmlRequest req) {
    int[] parts = req.queryPartitions();

    List<Integer> cacheIds = req.caches();

    long reqId = req.requestId();

    AffinityTopologyVersion topVer = req.topologyVersion();

    PartitionReservation reserved = null;

    MapNodeResults nodeResults = resultsForNode(node.id());

    try {
        reserved = h2.partitionReservationManager().reservePartitions(
            cacheIds,
            topVer,
            parts,
            node.id(),
            reqId
        );

        if (reserved.failed()) {
            U.error(log, "Failed to reserve partitions for DML request. [localNodeId=" + ctx.localNodeId() +
                ", nodeId=" + node.id() + ", reqId=" + req.requestId() + ", cacheIds=" + cacheIds +
                ", topVer=" + topVer + ", parts=" + Arrays.toString(parts) + ']');

            sendUpdateResponse(node, reqId, null,
                "Failed to reserve partitions for DML request. " + reserved.error());

            return;
        }

        IndexingQueryFilter filter = h2.backupFilter(topVer, parts);

        GridQueryCancel cancel = nodeResults.putUpdate(reqId);

        SqlFieldsQuery fldsQry = new SqlFieldsQuery(req.query());

        if (req.parameters() != null)
            fldsQry.setArgs(req.parameters());

        fldsQry.setEnforceJoinOrder(req.isFlagSet(GridH2QueryRequest.FLAG_ENFORCE_JOIN_ORDER));
        fldsQry.setTimeout(req.timeout(), TimeUnit.MILLISECONDS);
        fldsQry.setPageSize(req.pageSize());
        fldsQry.setLocal(true);

        boolean local = true;

        final boolean replicated = req.isFlagSet(GridH2QueryRequest.FLAG_REPLICATED);

        if (!replicated && !F.isEmpty(cacheIds) &&
            CU.firstPartitioned(ctx.cache().context(), cacheIds).config().getQueryParallelism() > 1) {
            fldsQry.setDistributedJoins(true);

            local = false;
        }

        UpdateResult updRes = h2.executeUpdateOnDataNode(req.schemaName(), fldsQry, filter, cancel, local);

        GridCacheContext<?, ?> mainCctx =
            !F.isEmpty(cacheIds) ? ctx.cache().context().cacheContext(cacheIds.get(0)) : null;

        boolean evt = local && mainCctx != null && mainCctx.events().isRecordable(EVT_CACHE_QUERY_EXECUTED);

        if (evt) {
            ctx.event().record(new CacheQueryExecutedEvent<>(
                node,
                "SQL query executed.",
                EVT_CACHE_QUERY_EXECUTED,
                CacheQueryType.SQL.name(),
                mainCctx.name(),
                null,
                req.query(),
                null,
                null,
                req.parameters(),
                node.id(),
                null));
        }

        sendUpdateResponse(node, reqId, updRes, null);
    }
    catch (Exception e) {
        U.error(log, "Error processing dml request. [localNodeId=" + ctx.localNodeId() +
            ", nodeId=" + node.id() + ", req=" + req + ']', e);

        sendUpdateResponse(node, reqId, null, e.getMessage());
    }
    finally {
        if (reserved != null)
            reserved.release();

        nodeResults.removeUpdate(reqId);
    }
}
 
Example 10
Source File: JdbcBatchUpdateTask.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Performs update.
 *
 * @param cache Cache.
 * @param sqlText SQL text.
 * @param args Parameters.
 * @return Update counter.
 * @throws SQLException If failed.
 */
private Integer doSingleUpdate(IgniteCache<?, ?> cache, String sqlText, List<Object> args) throws SQLException {
    SqlFieldsQuery qry = new SqlFieldsQueryEx(sqlText, false);

    qry.setPageSize(fetchSize);
    qry.setLocal(locQry);
    qry.setCollocated(collocatedQry);
    qry.setDistributedJoins(distributedJoins);
    qry.setSchema(schemaName);
    qry.setArgs(args == null ? null : args.toArray());

    QueryCursorImpl<List<?>> qryCursor = (QueryCursorImpl<List<?>>)cache.withKeepBinary().query(qry);

    if (qryCursor.isQuery()) {
        throw createJdbcSqlException(getError("Query produced result set", qry),
            IgniteQueryErrorCode.STMT_TYPE_MISMATCH);
    }

    List<List<?>> rows = qryCursor.getAll();

    if (F.isEmpty(rows))
        return SUCCESS_NO_INFO;

    if (rows.size() != 1)
        throw new SQLException(getError("Expected single row for update operation result", qry));

    List<?> row = rows.get(0);

    if (F.isEmpty(row) || row.size() != 1)
        throw new SQLException(getError("Expected row size of 1 for update operation", qry));

    Object objRes = row.get(0);

    if (!(objRes instanceof Long))
        throw new SQLException(getError("Unexpected update result type", qry));

    Long longRes = (Long)objRes;

    if (longRes > Integer.MAX_VALUE) {
        IgniteLogger log = ignite.log();

        if (log != null)
            log.warning(getError("Query updated row counter (" + longRes + ") exceeds integer range", qry));

        return Integer.MAX_VALUE;
    }

    return longRes.intValue();
}
 
Example 11
Source File: CacheMvccSqlTxQueriesWithReducerAbstractTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
private void checkMultiBatchPerNode(boolean client) throws Exception {
    ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 2, DFLT_PARTITION_COUNT)
        .setIndexedTypes(Integer.class, CacheMvccSqlTxQueriesAbstractTest.MvccTestSqlIndexValue.class);

    Ignite checkNode;
    Ignite updateNode;

    Random rnd = ThreadLocalRandom.current();

    if (client) {
        startGridsMultiThreaded(3);

        updateNode = grid(rnd.nextInt(3));

        this.client = true;

        checkNode = startGrid(4);
    }
    else {
        startGridsMultiThreaded(4);

        checkNode = grid(rnd.nextInt(4));
        updateNode = grid(rnd.nextInt(4));
    }

    IgniteCache<Integer, CacheMvccSqlTxQueriesAbstractTest.MvccTestSqlIndexValue> cache =
        checkNode.cache(DEFAULT_CACHE_NAME);

    final int count = 6;

    Map<Integer, CacheMvccSqlTxQueriesAbstractTest.MvccTestSqlIndexValue> vals = new HashMap<>(count);

    for (int idx = 1; idx <= count; ++idx)
        vals.put(idx, new CacheMvccSqlTxQueriesAbstractTest.MvccTestSqlIndexValue(idx));

    cache.putAll(vals);

    try (Transaction tx = updateNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        tx.timeout(TIMEOUT);

        String sqlText = "INSERT INTO MvccTestSqlIndexValue (_key, idxVal1) " +
            "SELECT DISTINCT _key + 6, idxVal1 + 6 FROM MvccTestSqlIndexValue";

        SqlFieldsQuery qry = new SqlFieldsQuery(sqlText);

        qry.setDistributedJoins(true);
        qry.setPageSize(1);

        IgniteCache<Object, Object> cache0 = updateNode.cache(DEFAULT_CACHE_NAME);

        try (FieldsQueryCursor<List<?>> cur = cache0.query(qry)) {
            assertEquals((long)count, cur.iterator().next().get(0));
        }

        tx.commit();
    }
}