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