use of org.apache.ignite.table.RecordView in project ignite-3 by apache.
the class ItSetOpTest method testSetOpBigBatch.
@Test
@Disabled
public void testSetOpBigBatch() {
TableDefinition schTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "BIG_TABLE1").columns(SchemaBuilders.column("KEY", ColumnType.INT32).build(), SchemaBuilders.column("VAL", ColumnType.INT32).asNullable(true).build()).withPrimaryKey("KEY").build();
Table tbl1 = CLUSTER_NODES.get(0).tables().createTable(schTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl1, tblCh).changeReplicas(2).changePartitions(10));
TableDefinition schTbl2 = SchemaBuilders.tableBuilder("PUBLIC", "BIG_TABLE2").columns(SchemaBuilders.column("KEY", ColumnType.INT32).build(), SchemaBuilders.column("VAL", ColumnType.INT32).asNullable(true).build()).withPrimaryKey("KEY").build();
Table tbl2 = CLUSTER_NODES.get(0).tables().createTable(schTbl2.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl2, tblCh).changeReplicas(2).changePartitions(10));
int key = 0;
RecordView<Tuple> recordView1 = tbl1.recordView();
RecordView<Tuple> recordView2 = tbl2.recordView();
for (int i = 0; i < 5; i++) {
for (int j = 0; j < ((i == 0) ? 1 : (1 << (i * 4 - 1))); j++) {
// Cache1 keys count: 1 of "0", 8 of "1", 128 of "2", 2048 of "3", 32768 of "4".
recordView1.insert(null, Tuple.create().set("KEY", key++).set("VAL", i));
// Cache2 keys count: 1 of "5", 128 of "3", 32768 of "1".
if ((i & 1) == 0) {
recordView2.insert(null, Tuple.create().set("KEY", key++).set("VAL", 5 - i));
}
}
}
// Check 2 partitioned caches.
List<List<?>> rows = sql("SELECT val FROM BIG_TABLE1 EXCEPT SELECT val FROM BIG_TABLE2");
assertEquals(3, rows.size());
assertEquals(1, countIf(rows, r -> r.get(0).equals(0)));
assertEquals(1, countIf(rows, r -> r.get(0).equals(2)));
assertEquals(1, countIf(rows, r -> r.get(0).equals(4)));
rows = sql("SELECT val FROM BIG_TABLE1 EXCEPT ALL SELECT val FROM BIG_TABLE2");
assertEquals(34817, rows.size());
assertEquals(1, countIf(rows, r -> r.get(0).equals(0)));
assertEquals(128, countIf(rows, r -> r.get(0).equals(2)));
assertEquals(1920, countIf(rows, r -> r.get(0).equals(3)));
assertEquals(32768, countIf(rows, r -> r.get(0).equals(4)));
rows = sql("SELECT val FROM BIG_TABLE1 INTERSECT SELECT val FROM BIG_TABLE2");
assertEquals(2, rows.size());
assertEquals(1, countIf(rows, r -> r.get(0).equals(1)));
assertEquals(1, countIf(rows, r -> r.get(0).equals(3)));
rows = sql("SELECT val FROM BIG_TABLE1 INTERSECT ALL SELECT val FROM BIG_TABLE2");
assertEquals(136, rows.size());
assertEquals(8, countIf(rows, r -> r.get(0).equals(1)));
assertEquals(128, countIf(rows, r -> r.get(0).equals(3)));
}
use of org.apache.ignite.table.RecordView in project ignite-3 by apache.
the class RecordViewOperationsTest method recordView.
/**
* Creates RecordView.
*/
private RecordViewImpl<TestObjectWithAllTypes> recordView() {
ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
TxManager txManager = new TxManagerImpl(clusterService, new HeapLockManager());
MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
Mapper<TestObjectWithAllTypes> recMapper = Mapper.of(TestObjectWithAllTypes.class);
Column[] valCols = { new Column("primitiveByteCol".toUpperCase(), INT8, false), new Column("primitiveShortCol".toUpperCase(), INT16, false), new Column("primitiveIntCol".toUpperCase(), INT32, false), new Column("primitiveFloatCol".toUpperCase(), FLOAT, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("byteCol".toUpperCase(), INT8, true), new Column("shortCol".toUpperCase(), INT16, true), new Column("intCol".toUpperCase(), INT32, true), new Column("longCol".toUpperCase(), INT64, true), new Column("nullLongCol".toUpperCase(), INT64, true), new Column("floatCol".toUpperCase(), FLOAT, true), new Column("doubleCol".toUpperCase(), DOUBLE, true), new Column("dateCol".toUpperCase(), DATE, true), new Column("timeCol".toUpperCase(), time(), true), new Column("dateTimeCol".toUpperCase(), datetime(), true), new Column("timestampCol".toUpperCase(), timestamp(), true), new Column("uuidCol".toUpperCase(), NativeTypes.UUID, true), new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("stringCol".toUpperCase(), STRING, true), new Column("nullBytesCol".toUpperCase(), BYTES, true), new Column("bytesCol".toUpperCase(), BYTES, true), new Column("numberCol".toUpperCase(), NativeTypes.numberOf(12), true), new Column("decimalCol".toUpperCase(), NativeTypes.decimalOf(19, 3), true) };
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("primitiveLongCol".toUpperCase(), NativeTypes.INT64, false) }, valCols);
// Validate all types are tested.
Set<NativeTypeSpec> testedTypes = Arrays.stream(valCols).map(c -> c.type().spec()).collect(Collectors.toSet());
Set<NativeTypeSpec> missedTypes = Arrays.stream(NativeTypeSpec.values()).filter(t -> !testedTypes.contains(t)).collect(Collectors.toSet());
assertEquals(Collections.emptySet(), missedTypes);
return new RecordViewImpl<>(table, new DummySchemaManagerImpl(schema), recMapper);
}
use of org.apache.ignite.table.RecordView in project ignite-3 by apache.
the class ItFunctionsTest method testRangeWithCache.
@Test
public void testRangeWithCache() {
TableDefinition tblDef = SchemaBuilders.tableBuilder("PUBLIC", "TEST").columns(SchemaBuilders.column("ID", ColumnType.INT32).build(), SchemaBuilders.column("VAL", ColumnType.INT32).build()).withPrimaryKey("ID").build();
String tblName = tblDef.canonicalName();
RecordView<Tuple> tbl = CLUSTER_NODES.get(0).tables().createTable(tblDef.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(tblDef, tblCh).changeReplicas(1).changePartitions(10)).recordView();
try {
for (int i = 0; i < 100; i++) {
tbl.insert(null, Tuple.create().set("ID", i).set("VAL", i));
}
// Correlated INNER join.
assertQuery("SELECT t.val FROM test t WHERE t.val < 5 AND " + "t.id in (SELECT x FROM table(system_range(t.val, t.val))) ").returns(0).returns(1).returns(2).returns(3).returns(4).check();
// Correlated LEFT joins.
assertQuery("SELECT t.val FROM test t WHERE t.val < 5 AND " + "EXISTS (SELECT x FROM table(system_range(t.val, t.val)) WHERE mod(x, 2) = 0) ").returns(0).returns(2).returns(4).check();
assertQuery("SELECT t.val FROM test t WHERE t.val < 5 AND " + "NOT EXISTS (SELECT x FROM table(system_range(t.val, t.val)) WHERE mod(x, 2) = 0) ").returns(1).returns(3).check();
assertQuery("SELECT t.val FROM test t WHERE " + "EXISTS (SELECT x FROM table(system_range(t.val, null))) ").check();
// Non-correlated join.
assertQuery("SELECT t.val FROM test t JOIN table(system_range(1, 50)) as r ON t.id = r.x " + "WHERE mod(r.x, 10) = 0").returns(10).returns(20).returns(30).returns(40).returns(50).check();
} finally {
CLUSTER_NODES.get(0).tables().dropTable(tblName);
}
}
Aggregations