Java Code Examples for org.apache.ignite.cache.query.SqlQuery#setDistributedJoins()

The following examples show how to use org.apache.ignite.cache.query.SqlQuery#setDistributedJoins() . 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: DisappearedCacheWasNotFoundMessageSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
@Test
public void testDisappearedCacheWasNotFoundMessage() {
    SqlQuery<String, Person> qry = new SqlQuery<String, Person>(Person.class, JoinSqlTestHelper.JOIN_SQL).setArgs("Organization #0");

    qry.setDistributedJoins(true);

    try {
        personCache.query(qry).getAll();

        fail("No CacheException emitted.");
    }
    catch (CacheException e) {
        boolean exp = e.getMessage().contains("Cache not found on local node (was concurrently destroyed?)");

        if (!exp)
            throw e;
    }
}
 
Example 2
Source File: DisappearedCacheCauseRetryMessageSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
@Test
public void testDisappearedCacheCauseRetryMessage() {
    SqlQuery<String, JoinSqlTestHelper.Person> qry =
        new SqlQuery<String, JoinSqlTestHelper.Person>(JoinSqlTestHelper.Person.class, JoinSqlTestHelper.JOIN_SQL)
            .setArgs("Organization #0");

    qry.setDistributedJoins(true);

    try {
        personCache.query(qry).getAll();

        fail("No CacheException emitted.");
    }
    catch (CacheException e) {
        if (!e.getMessage().contains("Failed to reserve partitions for query (cache is not found on local node) ["))
            e.printStackTrace();

        assertTrue(e.getMessage(), e.getMessage().contains("Failed to reserve partitions for query (cache is not found on local node) ["));
    }
}
 
Example 3
Source File: NonCollocatedRetryMessageSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
@Test
public void testNonCollocatedRetryMessage() {
    SqlQuery<String, JoinSqlTestHelper.Person> qry = new SqlQuery<String, JoinSqlTestHelper.Person>(
        JoinSqlTestHelper.Person.class, JoinSqlTestHelper.JOIN_SQL).setArgs("Organization #0");

    qry.setDistributedJoins(true);

    try {
        List<Cache.Entry<String, JoinSqlTestHelper.Person>> prsns = personCache.query(qry).getAll();

        fail("No CacheException emitted. Collection size=" + prsns.size());
    }
    catch (CacheException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("Failed to execute non-collocated query"));
    }
}
 
Example 4
Source File: RetryCauseMessageSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Failed to reserve partitions for query (cache is not found on local node)
 */
@Test
public void testSynthCacheWasNotFoundMessage() {
    GridMapQueryExecutor mapQryExec = GridTestUtils.getFieldValue(h2Idx, IgniteH2Indexing.class, "mapQryExec");

    GridTestUtils.setFieldValue(h2Idx, "mapQryExec",
        new MockGridMapQueryExecutor() {
            @Override public void onQueryRequest(ClusterNode node, GridH2QueryRequest qryReq)
                throws IgniteCheckedException {
                qryReq.caches().add(Integer.MAX_VALUE);

                startedExecutor.onQueryRequest(node, qryReq);

                qryReq.caches().remove(qryReq.caches().size() - 1);
            }
        }.insertRealExecutor(mapQryExec));

    SqlQuery<String, Person> qry = new SqlQuery<String, Person>(Person.class, JOIN_SQL).setArgs("Organization #0");

    qry.setDistributedJoins(true);

    try {
        personCache.query(qry).getAll();
    }
    catch (CacheException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("Failed to reserve partitions for query (cache is not found on local node) ["));

        return;
    }
    finally {
        GridTestUtils.setFieldValue(h2Idx, "mapQryExec", mapQryExec);
    }
    fail();
}
 
Example 5
Source File: IgniteSqlDistributedJoinSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testNonCollocatedDistributedJoin() throws Exception {
    CacheConfiguration ccfg1 = cacheConfig("pers", true, String.class, Person.class);
    CacheConfiguration ccfg2 = cacheConfig("org", true, String.class, Organization.class);

    IgniteCache<String, Person> c1 = ignite(0).getOrCreateCache(ccfg1);
    IgniteCache<String, Organization> c2 = ignite(0).getOrCreateCache(ccfg2);

    try {
        awaitPartitionMapExchange();

        populateDataIntoCaches(c1, c2);

        String joinSql =
            "select * from Person, \"org\".Organization as org " +
                "where Person.orgId = org.id " +
                "and lower(org.name) = lower(?)";

        SqlQuery qry = new SqlQuery<String, Person>(Person.class, joinSql).setArgs("Organization #0");

        qry.setDistributedJoins(true);

        List<Person> prns = c1.query(qry).getAll();

        assertEquals(PERSON_PER_ORG_COUNT, prns.size());
    }
    finally {
        c1.destroy();
        c2.destroy();
    }
}
 
Example 6
Source File: RetryCauseMessageSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Failed to reserve partitions for query (group reservation failed)
 */
@Test
public void testGrpReservationFailureMessage() {
    final GridMapQueryExecutor mapQryExec = GridTestUtils.getFieldValue(h2Idx, IgniteH2Indexing.class, "mapQryExec");

    final ConcurrentMap<PartitionReservationKey, GridReservable> reservations = reservations(h2Idx);

    GridTestUtils.setFieldValue(h2Idx, "mapQryExec",
        new MockGridMapQueryExecutor() {
            @Override public void onQueryRequest(ClusterNode node, GridH2QueryRequest qryReq)
                throws IgniteCheckedException {
                final PartitionReservationKey grpKey = new PartitionReservationKey(ORG, null);

                reservations.put(grpKey, new GridReservable() {

                    @Override public boolean reserve() {
                        return false;
                    }

                    @Override public void release() {}
                });
                startedExecutor.onQueryRequest(node, qryReq);
            }
        }.insertRealExecutor(mapQryExec));

    SqlQuery<String, Person> qry = new SqlQuery<String, Person>(Person.class, JOIN_SQL).setArgs("Organization #0");

    qry.setDistributedJoins(true);

    try {
        personCache.query(qry).getAll();
    }
    catch (CacheException e) {
        assertTrue(e.getMessage().contains("Failed to reserve partitions for query (group reservation failed) ["));

        return;
    }
    finally {
        GridTestUtils.setFieldValue(h2Idx, "mapQryExec", mapQryExec);
    }
    fail();
}
 
Example 7
Source File: RetryCauseMessageSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Failed to reserve partitions for query (partition of REPLICATED cache is not in OWNING state)
 */
@Ignore("https://issues.apache.org/jira/browse/IGNITE-7039")
@Test
public void testReplicatedCacheReserveFailureMessage() {
    GridMapQueryExecutor mapQryExec = GridTestUtils.getFieldValue(h2Idx, IgniteH2Indexing.class, "mapQryExec");

    final GridKernalContext ctx = GridTestUtils.getFieldValue(mapQryExec, GridMapQueryExecutor.class, "ctx");

    GridTestUtils.setFieldValue(h2Idx, "mapQryExec",
        new MockGridMapQueryExecutor() {
            @Override public void onQueryRequest(ClusterNode node, GridH2QueryRequest qryReq) throws IgniteCheckedException {
                GridCacheContext<?, ?> cctx = ctx.cache().context().cacheContext(qryReq.caches().get(0));

                GridDhtLocalPartition part = cctx.topology().localPartition(0, NONE, false);

                AtomicLong aState = GridTestUtils.getFieldValue(part, GridDhtLocalPartition.class, "state");

                long stateVal = aState.getAndSet(2);

                startedExecutor.onQueryRequest(node, qryReq);

                aState.getAndSet(stateVal);
            }
        }.insertRealExecutor(mapQryExec));

    SqlQuery<String, Organization> qry = new SqlQuery<>(Organization.class, ORG_SQL);

    qry.setDistributedJoins(true);

    try {
        orgCache.query(qry).getAll();
    }
    catch (CacheException e) {
        assertTrue(e.getMessage().contains("Failed to reserve partitions for query (partition of REPLICATED cache is not in OWNING state) ["));

        return;
    }
    finally {
        GridTestUtils.setFieldValue(h2Idx, "mapQryExec", mapQryExec);
    }
    fail();
}
 
Example 8
Source File: RetryCauseMessageSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Failed to reserve partitions for query (partition of PARTITIONED cache cannot be reserved)
 */
@Test
public void testPartitionedCacheReserveFailureMessage() {
    GridMapQueryExecutor mapQryExec = GridTestUtils.getFieldValue(h2Idx, IgniteH2Indexing.class, "mapQryExec");

    final GridKernalContext ctx = GridTestUtils.getFieldValue(mapQryExec, GridMapQueryExecutor.class, "ctx");

    GridTestUtils.setFieldValue(h2Idx, "mapQryExec",
        new MockGridMapQueryExecutor() {
            @Override public void onQueryRequest(ClusterNode node, GridH2QueryRequest qryReq)
                throws IgniteCheckedException {
                GridCacheContext<?, ?> cctx = ctx.cache().context().cacheContext(qryReq.caches().get(0));

                GridDhtLocalPartition part = cctx.topology().localPartition(0, NONE, false);

                AtomicLong aState = GridTestUtils.getFieldValue(part, GridDhtLocalPartition.class, "state");

                long stateVal = aState.getAndSet(2);

                startedExecutor.onQueryRequest(node, qryReq);

                aState.getAndSet(stateVal);
            }
        }.insertRealExecutor(mapQryExec));

    SqlQuery<String, Person> qry = new SqlQuery<String, Person>(Person.class, JOIN_SQL).setArgs("Organization #0");

    qry.setDistributedJoins(true);
    try {
        personCache.query(qry).getAll();
    }
    catch (CacheException e) {
        assertTrue(e.getMessage().contains("Failed to reserve partitions for query (partition of PARTITIONED " +
            "cache is not found or not in OWNING state) "));

        return;
    }
    finally {
        GridTestUtils.setFieldValue(h2Idx, "mapQryExec", mapQryExec);
    }
    fail();
}
 
Example 9
Source File: RetryCauseMessageSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Failed to execute non-collocated query (will retry)
 */
@Test
public void testNonCollocatedFailureMessage() {
    final GridMapQueryExecutor mapQryExec = GridTestUtils.getFieldValue(h2Idx, IgniteH2Indexing.class, "mapQryExec");

    final ConcurrentMap<PartitionReservationKey, GridReservable> reservations = reservations(h2Idx);

    GridTestUtils.setFieldValue(h2Idx, "mapQryExec",
        new MockGridMapQueryExecutor() {
            @Override public void onQueryRequest(ClusterNode node, GridH2QueryRequest qryReq)
                throws IgniteCheckedException {
                final PartitionReservationKey grpKey = new PartitionReservationKey(ORG, null);

                reservations.put(grpKey, new GridReservable() {
                    @Override public boolean reserve() {
                        throw H2Utils.retryException("test retry exception");
                    }

                    @Override public void release() {}
                });

                startedExecutor.onQueryRequest(node, qryReq);
            }
        }.insertRealExecutor(mapQryExec));

    SqlQuery<String, Person> qry = new SqlQuery<String, Person>(Person.class, JOIN_SQL).setArgs("Organization #0");

    qry.setDistributedJoins(true);
    try {
        personCache.query(qry).getAll();
    }
    catch (CacheException e) {
        assertTrue(e.getMessage().contains("Failed to execute non-collocated query (will retry) ["));

        return;
    }
    finally {
        GridTestUtils.setFieldValue(h2Idx, "mapQryExec", mapQryExec);
    }
    fail();
}
 
Example 10
Source File: IgniteSqlQueryWithBaselineTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 *
 */
private void doQuery() {
    CacheConfiguration<Integer, C1> c1Conf = new CacheConfiguration<>("C1");
    c1Conf.setIndexedTypes(Integer.class, C1.class).setBackups(2);

    CacheConfiguration<Integer, C2> c2Conf = new CacheConfiguration<>("C2");
    c2Conf.setIndexedTypes(Integer.class, C2.class).setBackups(2);

    final IgniteCache<Integer, C1> cache = grid(0).getOrCreateCache(c1Conf);

    final IgniteCache<Integer, C2> cache1 = grid(0).getOrCreateCache(c2Conf);

    for (int i = 0; i < 100; i++) {
        cache.put(i, new C1(i));

        cache1.put(i, new C2(i));
    }

    String sql = "SELECT C1.*" +
            " from C1 inner join \"C2\".C2 as D on C1.id = D.id" +
            " order by C1.id asc";

    SqlQuery<Integer, C1> qry = new SqlQuery<>(C1.class, sql);

    qry.setDistributedJoins(true);

    log.info("before query run...");

    Collection<Cache.Entry<Integer, C1>> res = cache.query(qry).getAll();

    log.info("result size: " + res.size());
}