Search in sources :

Example 41 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class KeyValueBinaryViewOperationsTest method remove.

@Test
public void remove() {
    SchemaDescriptor schema = schemaDescriptor();
    KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
    final Tuple key = Tuple.create().set("id", 1L);
    final Tuple key2 = Tuple.create().set("id", 2L);
    final Tuple val = Tuple.create().set("val", 11L);
    final Tuple val2 = Tuple.create().set("val", 22L);
    // Put KV pair.
    tbl.put(null, key, val);
    // Delete existed key.
    assertEqualsValues(schema, val, tbl.get(null, key));
    assertTrue(tbl.remove(null, key));
    assertNull(tbl.get(null, key));
    // Delete already deleted key.
    assertFalse(tbl.remove(null, key));
    // Put KV pair.
    tbl.put(null, key, val2);
    assertEqualsValues(schema, val2, tbl.get(null, key));
    // Delete existed key.
    assertTrue(tbl.remove(null, Tuple.create().set("id", 1L)));
    assertNull(tbl.get(null, key));
    // Delete not existed key.
    assertNull(tbl.get(null, key2));
    assertFalse(tbl.remove(null, key2));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 42 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class KeyValueBinaryViewOperationsTest method put.

@Test
public void put() {
    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);
    final Tuple val3 = Tuple.create().set("val", 33L);
    assertNull(tbl.get(null, key));
    // Put KV pair.
    tbl.put(null, key, val);
    assertEqualsValues(schema, val, tbl.get(null, key));
    assertEqualsValues(schema, val, tbl.get(null, Tuple.create().set("id", 1L)));
    // Update KV pair.
    tbl.put(null, key, val2);
    assertEqualsValues(schema, val2, tbl.get(null, key));
    assertEqualsValues(schema, val2, tbl.get(null, Tuple.create().set("id", 1L)));
    // Remove KV pair.
    tbl.put(null, key, null);
    assertNull(tbl.get(null, key));
    // Put KV pair.
    tbl.put(null, key, val3);
    assertEqualsValues(schema, val3, tbl.get(null, key));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 43 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class KeyValueBinaryViewOperationsTest method replace.

@Test
public void replace() {
    SchemaDescriptor schema = schemaDescriptor();
    KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
    final Tuple key = Tuple.create().set("id", 1L);
    final Tuple key2 = Tuple.create().set("id", 2L);
    final Tuple val = Tuple.create().set("val", 11L);
    final Tuple val2 = Tuple.create().set("val", 22L);
    final Tuple val3 = Tuple.create().set("val", 33L);
    // Ignore replace operation for non-existed KV pair.
    assertFalse(tbl.replace(null, key, val));
    assertNull(tbl.get(null, key));
    tbl.put(null, key, val);
    // Replace existed KV pair.
    assertTrue(tbl.replace(null, key, val2));
    assertEqualsValues(schema, val2, tbl.get(null, key));
    // Ignore replace operation for non-existed KV pair.
    assertFalse(tbl.replace(null, key2, val3));
    assertNull(tbl.get(null, key2));
    tbl.put(null, key, val3);
    assertEqualsValues(schema, val3, tbl.get(null, key));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 44 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class MutableRowTupleAdapterTest method testVariousColumnTypes.

@Test
public void testVariousColumnTypes() throws TupleMarshallerException {
    Random rnd = new Random();
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(fullSchema));
    Tuple tuple = Tuple.create().set("valByteCol", (byte) 1).set("valShortCol", (short) 2).set("valIntCol", 3).set("valLongCol", 4L).set("valFloatCol", 0.055f).set("valDoubleCol", 0.066d).set("keyUuidCol", UUID.randomUUID()).set("valDateCol", LocalDate.now()).set("valDateTimeCol", truncatedLocalDateTimeNow()).set("valTimeCol", truncatedLocalTimeNow()).set("valTimeStampCol", truncatedInstantNow()).set("valBitmask1Col", randomBitSet(rnd, 12)).set("valBytesCol", IgniteTestUtils.randomBytes(rnd, 13)).set("valStringCol", IgniteTestUtils.randomString(rnd, 14)).set("valNumberCol", BigInteger.valueOf(rnd.nextLong())).set("valDecimalCol", BigDecimal.valueOf(rnd.nextLong(), 5));
    Tuple rowTuple = TableRow.tuple(new Row(fullSchema, new ByteBufferRow(marshaller.marshal(tuple).bytes())));
    assertEquals(tuple, rowTuple);
    // Force row to tuple conversion.
    rowTuple.set("foo", "bar");
    // Force row to tuple conversion.
    tuple.set("foo", "bar");
    assertEquals(tuple, rowTuple);
}
Also used : Random(java.util.Random) 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 45 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class MutableRowTupleAdapterTest method testRowTupleSchemaAwareness.

@Test
public void testRowTupleSchemaAwareness() 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);
    assertNotNull(((SchemaAware) tuple).schema());
    assertNotNull(((SchemaAware) key).schema());
    assertNotNull(((SchemaAware) val).schema());
    tuple.set("name", "noname");
    assertNull(((SchemaAware) tuple).schema());
    assertNotNull(((SchemaAware) key).schema());
    assertNotNull(((SchemaAware) val).schema());
}
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)

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