use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testColumnCountReturnsSchemaSize.
@Test
public void testColumnCountReturnsSchemaSize() {
assertEquals(2, getTuple().columnCount());
Tuple tuple = getTuple();
assertEquals(2, tuple.columnCount());
assertEquals(2, tuple.set("id", -1).columnCount());
tuple.valueOrDefault("name", "foo");
assertEquals(2, tuple.columnCount());
tuple.valueOrDefault("foo", "bar");
assertEquals(2, tuple.columnCount());
tuple.set("foo", "bar");
assertEquals(3, tuple.columnCount());
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testKeyValueTupleMutability.
@Test
public void testKeyValueTupleMutability() throws TupleMarshallerException {
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
Row row = new Row(schema, new ByteBufferRow(marshaller.marshal(Tuple.create().set("id", 1L).set("name", "Shirt")).bytes()));
Tuple tuple = TableRow.tuple(row);
Tuple key = TableRow.keyTuple(row);
final Tuple val = TableRow.valueTuple(row);
assertTrue(tuple instanceof SchemaAware);
key.set("id", 3L);
assertEquals(3L, (Long) key.value("id"));
assertEquals(1L, (Long) tuple.value("id"));
val.set("name", "noname");
assertEquals("noname", val.value("name"));
assertEquals("Shirt", tuple.value("name"));
val.set("foo", "bar");
assertEquals("bar", val.value("foo"));
assertThrows(IllegalArgumentException.class, () -> key.value("foo"));
assertThrows(IllegalArgumentException.class, () -> tuple.value("foo"));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method removeExact.
@Test
public void removeExact() {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, false) });
RecordView<Tuple> tbl = createTableImpl(schema).recordView();
final Tuple keyTuple = Tuple.create().set("id", 1L);
final Tuple tuple = Tuple.create().set("id", 1L).set("val", 11L);
final Tuple tuple2 = Tuple.create().set("id", 1L).set("val", 22L);
final Tuple nonExistedTuple = Tuple.create().set("id", 2L).set("val", 22L);
tbl.insert(null, tuple);
assertEqualsRows(schema, tuple, tbl.get(null, keyTuple));
// Fails to delete not existed tuple.
assertFalse(tbl.deleteExact(null, nonExistedTuple));
assertEqualsRows(schema, tuple, tbl.get(null, keyTuple));
// Fails to delete tuple with unexpected value.
assertFalse(tbl.deleteExact(null, tuple2));
assertEqualsRows(schema, tuple, tbl.get(null, keyTuple));
// TODO: IGNITE-14479: Fix default value usage.
// assertFalse(tbl.deleteExact(keyTuple));
// assertEqualsRows(schema, tuple, tbl.get(keyTuple));
// Delete tuple with expected value.
assertTrue(tbl.deleteExact(null, tuple));
assertNull(tbl.get(null, keyTuple));
// Once again.
assertFalse(tbl.deleteExact(null, tuple));
assertNull(tbl.get(null, keyTuple));
// Insert new.
tbl.insert(null, tuple2);
assertEqualsRows(schema, tuple2, tbl.get(null, keyTuple));
// Delete tuple with expected value.
assertTrue(tbl.deleteExact(null, tuple2));
assertNull(tbl.get(null, keyTuple));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method upsert.
@Test
public void upsert() {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, false) });
RecordView<Tuple> tbl = createTableImpl(schema).recordView();
final Tuple tuple = Tuple.create().set("id", 1L).set("val", 11L);
final Tuple newTuple = Tuple.create().set("id", 1L).set("val", 22L);
final Tuple nonExistedTuple = Tuple.create().set("id", 2L);
assertNull(tbl.get(null, Tuple.create().set("id", 1L)));
// Insert new tuple.
tbl.upsert(null, tuple);
assertEqualsRows(schema, tuple, tbl.get(null, Tuple.create().set("id", 1L)));
// Update exited row.
tbl.upsert(null, newTuple);
assertEqualsRows(schema, newTuple, tbl.get(null, Tuple.create().set("id", 1L)));
assertNull(tbl.get(null, nonExistedTuple));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method replace.
@Test
public void replace() {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, false) });
RecordView<Tuple> tbl = createTableImpl(schema).recordView();
final Tuple keyTuple = Tuple.create().set("id", 1L);
final Tuple tuple = Tuple.create().set("id", 1L).set("val", 11L);
final Tuple tuple2 = Tuple.create().set("id", 1L).set("val", 22L);
assertNull(tbl.get(null, keyTuple));
// Ignore replace operation for non-existed row.
assertFalse(tbl.replace(null, tuple));
assertNull(tbl.get(null, keyTuple));
// Insert row.
tbl.insert(null, tuple);
// Replace existed row.
assertTrue(tbl.replace(null, tuple2));
assertEqualsRows(schema, tuple2, tbl.get(null, keyTuple));
}
Aggregations