Search in sources :

Example 1 with Person

use of org.apache.ignite.internal.processors.query.h2.twostep.JoinSqlTestHelper.Person in project ignite by apache.

the class SqlFieldsQuerySelfTest method testQueryCaching.

/**
 * @throws Exception If error.
 */
public void testQueryCaching() throws Exception {
    startGrid(0);
    PreparedStatement stmt = null;
    for (int i = 0; i < 2; i++) {
        createAndFillCache();
        PreparedStatement stmt0 = grid(0).context().query().prepareNativeStatement("person", INSERT);
        // Statement should either be parsed initially or in response to schema change...
        assertTrue(stmt != stmt0);
        stmt = stmt0;
        // ...and be properly compiled considering schema changes to be properly parsed
        new GridSqlQueryParser(false).parse(GridSqlQueryParser.prepared(stmt));
        destroyCache();
    }
    stmt = null;
    createAndFillCache();
    // Now let's do the same without restarting the cache.
    for (int i = 0; i < 2; i++) {
        PreparedStatement stmt0 = grid(0).context().query().prepareNativeStatement("person", INSERT);
        // Statement should either be parsed or taken from cache as no schema changes occurred...
        assertTrue(stmt == null || stmt == stmt0);
        stmt = stmt0;
        // ...and be properly compiled considering schema changes to be properly parsed
        new GridSqlQueryParser(false).parse(GridSqlQueryParser.prepared(stmt));
    }
    destroyCache();
}
Also used : GridSqlQueryParser(org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser) PreparedStatement(java.sql.PreparedStatement)

Example 2 with Person

use of org.apache.ignite.internal.processors.query.h2.twostep.JoinSqlTestHelper.Person in project ignite by apache.

the class UpdatePlan method createRows.

/**
 * Extract rows from plan without performing any query.
 *
 * @param args Original query arguments.
 * @return {@link List} of rows from the plan for a single query.
 * For example, if we have multiple args in a query: <br/>
 * {@code INSERT INTO person VALUES (k1, v1), (k2, v2), (k3, v3);} <br/>
 * we will get a {@link List} of {@link List} with items {@code {[k1, v1], [k2, v2], [k3, v3]}}.
 * @throws IgniteCheckedException if failed.
 */
public List<List<?>> createRows(Object[] args) throws IgniteCheckedException {
    assert rowsNum > 0 && !F.isEmpty(colNames);
    List<List<?>> res = new ArrayList<>(rowsNum);
    GridH2RowDescriptor desc = tbl.rowDescriptor();
    extractArgsValues(args, res, desc);
    return res;
}
Also used : GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Person

use of org.apache.ignite.internal.processors.query.h2.twostep.JoinSqlTestHelper.Person in project ignite by apache.

the class RetryCauseMessageSelfTest method testPartitionedCacheReserveFailureMessage.

/**
 * 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();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CacheException(javax.cache.CacheException) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridH2QueryRequest(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2QueryRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) Person(org.apache.ignite.internal.processors.query.h2.twostep.JoinSqlTestHelper.Person) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 4 with Person

use of org.apache.ignite.internal.processors.query.h2.twostep.JoinSqlTestHelper.Person in project ignite by apache.

the class RetryCauseMessageSelfTest method testNonCollocatedFailureMessage.

/**
 * 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();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CacheException(javax.cache.CacheException) GridH2QueryRequest(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2QueryRequest) GridReservable(org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable) Person(org.apache.ignite.internal.processors.query.h2.twostep.JoinSqlTestHelper.Person) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 5 with Person

use of org.apache.ignite.internal.processors.query.h2.twostep.JoinSqlTestHelper.Person in project ignite by apache.

the class RetryCauseMessageSelfTest method beforeTest.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTest() throws Exception {
    Ignite ignite = startGridsMultiThreaded(NODES_COUNT, false);
    GridQueryProcessor qryProc = grid(ignite.name()).context().query();
    h2Idx = GridTestUtils.getFieldValue(qryProc, GridQueryProcessor.class, "idx");
    personCache = ignite(0).getOrCreateCache(new CacheConfiguration<String, Person>("pers").setQueryEntities(JoinSqlTestHelper.personQueryEntity()));
    orgCache = ignite(0).getOrCreateCache(new CacheConfiguration<String, Organization>(ORG).setCacheMode(CacheMode.REPLICATED).setQueryEntities(JoinSqlTestHelper.organizationQueryEntity()));
    awaitPartitionMapExchange();
    JoinSqlTestHelper.populateDataIntoOrg(orgCache);
    JoinSqlTestHelper.populateDataIntoPerson(personCache);
}
Also used : GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) Ignite(org.apache.ignite.Ignite) Person(org.apache.ignite.internal.processors.query.h2.twostep.JoinSqlTestHelper.Person) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

Person (org.apache.ignite.internal.processors.query.h2.twostep.JoinSqlTestHelper.Person)4 CacheException (javax.cache.CacheException)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 AbstractIndexingCommonTest (org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest)3 GridH2QueryRequest (org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2QueryRequest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GridReservable (org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable)2 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)2 PreparedStatement (java.sql.PreparedStatement)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Ignite (org.apache.ignite.Ignite)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)1 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)1 GridQueryProcessor (org.apache.ignite.internal.processors.query.GridQueryProcessor)1