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();
}
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;
}
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();
}
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();
}
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);
}
Aggregations