Search in sources :

Example 41 with IN

use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.IN in project ignite by apache.

the class BasicIndexTest method testCorrectPkFieldsSequenceAfterRestart.

/**
 * Checks that fields in primary index have correct order after node restart.
 *
 * @throws Exception If failed.
 */
@Test
public void testCorrectPkFieldsSequenceAfterRestart() throws Exception {
    inlineSize = 10;
    IgniteEx ig0 = startGrid(getConfiguration("0").setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true))));
    ig0.cluster().state(ClusterState.ACTIVE);
    {
        GridQueryProcessor qryProc = ig0.context().query();
        IgniteH2Indexing idx = (IgniteH2Indexing) (ig0).context().query().getIndexing();
        String tblName = "T1";
        qryProc.querySqlFields(new SqlFieldsQuery("CREATE TABLE PUBLIC." + tblName + " (F1 VARCHAR, F2 VARCHAR, F3 VARCHAR, " + "CONSTRAINT PK PRIMARY KEY (F2, F1))"), true).getAll();
        List<String> expect = Arrays.asList("F2", "F1");
        checkPkFldSequence(tblName, expect, idx);
    }
    stopAllGrids();
    ig0 = startGrid(getConfiguration("0").setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true))));
    ig0.cluster().state(ClusterState.ACTIVE);
    {
        IgniteH2Indexing idx = (IgniteH2Indexing) (ig0).context().query().getIndexing();
        String tblName = "T1";
        List<String> expect = Arrays.asList("F2", "F1");
        checkPkFldSequence(tblName, expect, idx);
    }
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) List(java.util.List) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Test(org.junit.Test)

Example 42 with IN

use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.IN in project ignite by apache.

the class BasicIndexTest method testCorrectPrimaryKeyFieldsSequence.

/**
 * Checks that fields in primary index have correct order.
 *
 * @throws Exception If failed.
 */
@Test
public void testCorrectPrimaryKeyFieldsSequence() throws Exception {
    inlineSize = 10;
    IgniteEx ig0 = startGrid(0);
    GridQueryProcessor qryProc = ig0.context().query();
    IgniteH2Indexing idx = (IgniteH2Indexing) (ig0).context().query().getIndexing();
    String tblName = "T1";
    qryProc.querySqlFields(new SqlFieldsQuery("CREATE TABLE PUBLIC." + tblName + " (F1 VARCHAR, F2 VARCHAR, F3 VARCHAR, " + "CONSTRAINT PK PRIMARY KEY (F1, F2))"), true).getAll();
    List<String> expect = Arrays.asList("F1", "F2");
    checkPkFldSequence(tblName, expect, idx);
    tblName = "T2";
    qryProc.querySqlFields(new SqlFieldsQuery("CREATE TABLE PUBLIC." + tblName + " (F1 VARCHAR, F2 VARCHAR, F3 VARCHAR, " + "CONSTRAINT PK PRIMARY KEY (F2, F1))"), true).getAll();
    expect = Arrays.asList("F2", "F1");
    checkPkFldSequence(tblName, expect, idx);
    tblName = "T3";
    qryProc.querySqlFields(new SqlFieldsQuery("CREATE TABLE PUBLIC." + tblName + " (F1 VARCHAR, F2 VARCHAR, F3 VARCHAR, " + "CONSTRAINT PK PRIMARY KEY (F3, F2))"), true).getAll();
    expect = Arrays.asList("F3", "F2");
    checkPkFldSequence(tblName, expect, idx);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Test(org.junit.Test)

Example 43 with IN

use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.IN in project ignite by apache.

the class StatisticsAbstractTest method awaitStatistics.

/**
 * Await statistic gathering is complete on specified node.
 *
 * @param timeout Timeout.
 * @param expectedVersions Expected versions for specified targets.
 * @param ign Node to await.
 * @throws Exception In case of errors.
 */
protected void awaitStatistics(long timeout, Map<StatisticsTarget, Long> expectedVersions, IgniteEx ign) throws Exception {
    long t0 = U.currentTimeMillis();
    IgniteH2Indexing indexing = (IgniteH2Indexing) ign.context().query().getIndexing();
    while (true) {
        try {
            checkStatisticTasksEmpty(ign);
            for (Map.Entry<StatisticsTarget, Long> targetVersionEntry : expectedVersions.entrySet()) {
                StatisticsTarget target = targetVersionEntry.getKey();
                Long ver = targetVersionEntry.getValue();
                ObjectStatisticsImpl s = (ObjectStatisticsImpl) indexing.statsManager().getLocalStatistics(target.key());
                assertNotNull(s);
                long minVer = Long.MAX_VALUE;
                Set<String> cols;
                if (F.isEmpty(target.columns()))
                    cols = s.columnsStatistics().keySet();
                else
                    cols = Arrays.stream(target.columns()).collect(Collectors.toSet());
                for (String col : cols) {
                    if (s.columnStatistics(col).version() < minVer)
                        minVer = s.columnStatistics(col).version();
                }
                if (minVer == Long.MAX_VALUE)
                    minVer = -1;
                assertEquals(String.format("Expected minimum statistics version %d but found %d", ver, minVer), (long) ver, minVer);
            }
            return;
        } catch (Throwable ex) {
            if (t0 + timeout < U.currentTimeMillis())
                throw ex;
            else
                U.sleep(200);
        }
    }
}
Also used : IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing) HashMap(java.util.HashMap) Map(java.util.Map)

Example 44 with IN

use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.IN 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 45 with IN

use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlOperationType.IN in project ignite by apache.

the class DmlStatementsProcessor method rowToKeyValue.

/**
     * Convert row presented as an array of Objects into key-value pair to be inserted to cache.
     * @param cctx Cache context.
     * @param row Row to process.
     * @param plan Update plan.
     * @throws IgniteCheckedException if failed.
     */
@SuppressWarnings({ "unchecked", "ConstantConditions", "ResultOfMethodCallIgnored" })
private IgniteBiTuple<?, ?> rowToKeyValue(GridCacheContext cctx, List<?> row, UpdatePlan plan) throws IgniteCheckedException {
    GridH2RowDescriptor rowDesc = plan.tbl.rowDescriptor();
    GridQueryTypeDescriptor desc = rowDesc.type();
    Object key = plan.keySupplier.apply(row);
    if (QueryUtils.isSqlType(desc.keyClass())) {
        assert plan.keyColIdx != -1;
        key = convert(key, rowDesc, desc.keyClass(), plan.colTypes[plan.keyColIdx]);
    }
    Object val = plan.valSupplier.apply(row);
    if (QueryUtils.isSqlType(desc.valueClass())) {
        assert plan.valColIdx != -1;
        val = convert(val, rowDesc, desc.valueClass(), plan.colTypes[plan.valColIdx]);
    }
    if (key == null)
        throw new IgniteSQLException("Key for INSERT or MERGE must not be null", IgniteQueryErrorCode.NULL_KEY);
    if (val == null)
        throw new IgniteSQLException("Value for INSERT or MERGE must not be null", IgniteQueryErrorCode.NULL_VALUE);
    Map<String, Object> newColVals = new HashMap<>();
    for (int i = 0; i < plan.colNames.length; i++) {
        if (i == plan.keyColIdx || i == plan.valColIdx)
            continue;
        String colName = plan.colNames[i];
        GridQueryProperty prop = desc.property(colName);
        assert prop != null;
        Class<?> expCls = prop.type();
        newColVals.put(colName, convert(row.get(i), rowDesc, expCls, plan.colTypes[i]));
    }
    // We update columns in the order specified by the table for a reason - table's
    // column order preserves their precedence for correct update of nested properties.
    Column[] cols = plan.tbl.getColumns();
    // First 3 columns are _key, _val and _ver. Skip 'em.
    for (int i = DEFAULT_COLUMNS_COUNT; i < cols.length; i++) {
        if (plan.tbl.rowDescriptor().isKeyValueOrVersionColumn(i))
            continue;
        String colName = cols[i].getName();
        if (!newColVals.containsKey(colName))
            continue;
        Object colVal = newColVals.get(colName);
        desc.setValue(colName, key, val, colVal);
    }
    if (cctx.binaryMarshaller()) {
        if (key instanceof BinaryObjectBuilder)
            key = ((BinaryObjectBuilder) key).build();
        if (val instanceof BinaryObjectBuilder)
            val = ((BinaryObjectBuilder) val).build();
    }
    return new IgniteBiTuple<>(key, val);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GridBoundedConcurrentLinkedHashMap(org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor) GridQueryProperty(org.apache.ignite.internal.processors.query.GridQueryProperty) GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) Column(org.h2.table.Column) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)35 ArrayList (java.util.ArrayList)29 IgniteException (org.apache.ignite.IgniteException)26 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)26 SQLException (java.sql.SQLException)21 List (java.util.List)21 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)21 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)19 CacheException (javax.cache.CacheException)15 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)13 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)13 Column (org.h2.table.Column)13 IgniteH2Indexing (org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing)10 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)10 ResultSet (java.sql.ResultSet)9 HashMap (java.util.HashMap)9 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)9 GridSqlSelect (org.apache.ignite.internal.processors.query.h2.sql.GridSqlSelect)9 PreparedStatement (java.sql.PreparedStatement)8 HashSet (java.util.HashSet)8