use of org.apache.ignite.table.Tuple 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);
}
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class InteropOperationsTest method readKeyValueBinary.
/**
* Read through binary view.
*
* @param id Id to read.
* @return {@code true} if read successfully, {@code false} - otherwise.
*/
private boolean readKeyValueBinary(int id, boolean nulls) {
Tuple k = Tuple.create().set("id", (long) id);
Tuple v = KV_BIN_VIEW.get(null, k);
boolean contains = KV_BIN_VIEW.contains(null, k);
assertEquals((v != null), contains);
if (v == null) {
return false;
}
v.set("id", (long) id);
validateTuple(id, v, nulls);
return true;
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method contains.
@Test
public void contains() {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id", NativeTypes.INT64, false) }, new Column[] { new Column("val", NativeTypes.INT64, false) });
KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
final Tuple key = Tuple.create().set("id", 1L);
final Tuple val = Tuple.create().set("val", 11L);
final Tuple val2 = Tuple.create().set("val", 22L);
// Not-existed value.
assertFalse(tbl.contains(null, key));
// Put KV pair.
tbl.put(null, key, val);
assertTrue(tbl.contains(null, Tuple.create().set("id", 1L)));
// Delete key.
assertTrue(tbl.remove(null, key));
assertFalse(tbl.contains(null, Tuple.create().set("id", 1L)));
// Put KV pair.
tbl.put(null, key, val2);
assertTrue(tbl.contains(null, Tuple.create().set("id", 1L)));
// Non-existed key.
assertFalse(tbl.contains(null, Tuple.create().set("id", 2L)));
tbl.remove(null, Tuple.create().set("id", 2L));
assertFalse(tbl.contains(null, Tuple.create().set("id", 2L)));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method putIfAbsent.
@Test
public void putIfAbsent() {
SchemaDescriptor schema = schemaDescriptor();
KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
final Tuple key = Tuple.create().set("id", 1L);
final Tuple val = Tuple.create().set("val", 11L);
final Tuple val2 = Tuple.create().set("val", 22L);
assertNull(tbl.get(null, key));
// Insert new KV pair.
assertTrue(tbl.putIfAbsent(null, key, val));
assertEqualsValues(schema, val, tbl.get(null, key));
assertEqualsValues(schema, val, tbl.get(null, Tuple.create().set("id", 1L)));
// Update KV pair.
assertFalse(tbl.putIfAbsent(null, key, val2));
assertEqualsValues(schema, val, tbl.get(null, key));
assertEqualsValues(schema, val, tbl.get(null, Tuple.create().set("id", 1L)));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class TupleMarshallerFixlenOnlyBenchmark method measureTupleBuildAndMarshallerCost.
/**
* Measure tuple build then marshall.
*
* @param bh Black hole.
*/
@Benchmark
public void measureTupleBuildAndMarshallerCost(Blackhole bh) throws TupleMarshallerException {
final Columns cols = schema.valueColumns();
final Tuple valBld = Tuple.create(cols.length());
for (int i = 0; i < cols.length(); i++) {
valBld.set(cols.column(i).name(), vals[i]);
}
Tuple keyTuple = Tuple.create(1).set("key", rnd.nextLong());
final Row row = marshaller.marshal(keyTuple, valBld);
bh.consume(row);
}
Aggregations