Search in sources :

Example 6 with Person

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

the class H2DynamicTableSelfTest method doTestCreateTable.

/**
     * Test that {@code CREATE TABLE} with given template cache name actually creates new cache,
     * H2 table and type descriptor on all nodes, optionally with cache type check.
     * @param tplCacheName Template cache name.
     * @param mode Expected cache mode, or {@code null} if no check is needed.
     */
private void doTestCreateTable(String tplCacheName, CacheMode mode) {
    executeDdl("CREATE TABLE \"Person\" (\"id\" int, \"city\" varchar," + " \"name\" varchar, \"surname\" varchar, \"age\" int, PRIMARY KEY (\"id\", \"city\")) WITH " + (F.isEmpty(tplCacheName) ? "" : "\"template=" + tplCacheName + "\",") + "\"backups=10,atomicity=atomic\"");
    for (int i = 0; i < 4; i++) {
        IgniteEx node = grid(i);
        assertNotNull(node.cache("Person"));
        DynamicCacheDescriptor cacheDesc = node.context().cache().cacheDescriptor("Person");
        assertNotNull(cacheDesc);
        if (mode == CacheMode.REPLICATED)
            assertEquals(Integer.MAX_VALUE, cacheDesc.cacheConfiguration().getBackups());
        else
            assertEquals(10, cacheDesc.cacheConfiguration().getBackups());
        assertEquals(CacheAtomicityMode.ATOMIC, cacheDesc.cacheConfiguration().getAtomicityMode());
        assertTrue(cacheDesc.sql());
        if (mode != null)
            assertEquals(mode, cacheDesc.cacheConfiguration().getCacheMode());
        QueryTypeDescriptorImpl desc = typeExisting(node, "Person", "Person");
        assertEquals(Object.class, desc.keyClass());
        assertEquals("PersonKey", desc.keyTypeName());
        assertEquals(Object.class, desc.valueClass());
        assertEquals("Person", desc.valueTypeName());
        assertEquals(F.asList("id", "city", "name", "surname", "age"), new ArrayList<>(desc.fields().keySet()));
        assertProperty(desc, "id", Integer.class, true);
        assertProperty(desc, "city", String.class, true);
        assertProperty(desc, "name", String.class, false);
        assertProperty(desc, "surname", String.class, false);
        assertProperty(desc, "age", Integer.class, false);
        GridH2Table tbl = ((IgniteH2Indexing) node.context().query().getIndexing()).dataTable("PUBLIC", "Person");
        assertNotNull(tbl);
    }
}
Also used : QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) IgniteEx(org.apache.ignite.internal.IgniteEx) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing)

Example 7 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 argss Batch of arguments.
 * @return {@link List} of rows from the plan for each query.
 * For example, if we have a batch of queries with multiple args: <br/>
 * <code>
 * INSERT INTO person VALUES (k1, v1), (k2, v2), (k3, v3); <br/>
 * INSERT INTO person VALUES (k4, v4), (k5, v5), (k6, v6);<br/>
 * </code>
 * we will get a {@link List} of {@link List} of {@link List} with items: <br/>
 * <code>
 * {[k1, v1], [k2, v2], [k3, v3]},<br/>
 * {[k4, v4], [k5, v5], [k6, v6]}<br/>
 *
 * @throws IgniteCheckedException If failed.
 */
public List<List<List<?>>> createRows(List<Object[]> argss) throws IgniteCheckedException {
    assert rowsNum > 0 && !F.isEmpty(colNames);
    assert argss != null;
    List<List<List<?>>> resPerQry = new ArrayList<>(argss.size());
    GridH2RowDescriptor desc = tbl.rowDescriptor();
    for (Object[] args : argss) {
        List<List<?>> res = new ArrayList<>();
        resPerQry.add(res);
        extractArgsValues(args, res, desc);
    }
    return resPerQry;
}
Also used : GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BinaryObject(org.apache.ignite.binary.BinaryObject)

Example 8 with Person

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

the class RetryCauseMessageSelfTest method testGrpReservationFailureMessage.

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

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