Search in sources :

Example 86 with Tuple

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());
}
Also used : Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 87 with Tuple

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"));
}
Also used : SchemaAware(org.apache.ignite.internal.schema.SchemaAware) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 88 with Tuple

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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 89 with Tuple

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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 90 with Tuple

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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Aggregations

Tuple (org.apache.ignite.table.Tuple)130 Test (org.junit.jupiter.api.Test)101 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)33 Table (org.apache.ignite.table.Table)27 Column (org.apache.ignite.internal.schema.Column)25 Row (org.apache.ignite.internal.schema.row.Row)21 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)19 Ignite (org.apache.ignite.Ignite)17 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)17 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)17 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)17 InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)10 TableDefinition (org.apache.ignite.schema.definition.TableDefinition)9 ArrayList (java.util.ArrayList)8 Disabled (org.junit.jupiter.api.Disabled)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)7 BigDecimal (java.math.BigDecimal)6 Transaction (org.apache.ignite.tx.Transaction)6