Search in sources :

Example 36 with Tuple

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

the class InteropOperationsTest method readRecordBinary.

/**
 * Read through record binary view.
 *
 * @param id Id to read.
 * @param nulls If {@code true} - nullable fields should be filled, if {@code false} - otherwise.
 * @return {@code true} if read successfully, {@code false} - otherwise.
 */
private boolean readRecordBinary(int id, boolean nulls) {
    Tuple k = Tuple.create().set("id", (long) id);
    Tuple res = R_BIN_VIEW.get(null, k);
    if (res == null) {
        return false;
    }
    validateTuple(id, res, nulls);
    return true;
}
Also used : Tuple(org.apache.ignite.table.Tuple)

Example 37 with Tuple

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

the class KeyValueBinaryViewOperationsTest method getAndPut.

@Test
public void getAndPut() {
    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));
    // Insert new tuple.
    assertNull(tbl.getAndPut(null, key, val));
    assertEqualsValues(schema, val, tbl.get(null, key));
    assertEqualsValues(schema, val, tbl.get(null, Tuple.create().set("id", 1L)));
    assertEqualsValues(schema, val, tbl.getAndPut(null, key, val2));
    assertEqualsValues(schema, val2, tbl.getAndPut(null, key, Tuple.create().set("val", 33L)));
    assertEqualsValues(schema, val3, tbl.get(null, key));
    assertNull(tbl.get(null, Tuple.create().set("id", 2L)));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 38 with Tuple

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

the class KeyValueBinaryViewOperationsTest method removeExact.

@Test
public void removeExact() {
    SchemaDescriptor schema = schemaDescriptor();
    final 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);
    assertEqualsValues(schema, val, tbl.get(null, key));
    // Fails to delete KV pair with unexpected value.
    assertFalse(tbl.remove(null, key, val2));
    assertEqualsValues(schema, val, tbl.get(null, key));
    // Delete KV pair with expected value.
    assertTrue(tbl.remove(null, key, val));
    assertNull(tbl.get(null, key));
    // Once again.
    assertFalse(tbl.remove(null, key, val));
    assertNull(tbl.get(null, key));
    // Try to remove non-existed key.
    assertThrows(Exception.class, () -> tbl.remove(null, key, null));
    assertNull(tbl.get(null, key));
    // Put KV pair.
    tbl.put(null, key, val2);
    assertEqualsValues(schema, val2, tbl.get(null, key));
    // Check null value ignored.
    assertThrows(Exception.class, () -> tbl.remove(null, key, null));
    assertEqualsValues(schema, val2, tbl.get(null, key));
    // Delete KV pair with expected value.
    assertTrue(tbl.remove(null, key, val2));
    assertNull(tbl.get(null, key));
    assertFalse(tbl.remove(null, key2, val2));
    assertNull(tbl.get(null, key2));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 39 with Tuple

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

the class KeyValueBinaryViewOperationsTest method getAll.

@Test
public void getAll() {
    SchemaDescriptor schema = schemaDescriptor();
    KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
    Tuple key1 = Tuple.create().set("id", 1L);
    Tuple key2 = Tuple.create().set("id", 2L);
    Tuple key3 = Tuple.create().set("id", 3L);
    tbl.putAll(null, Map.of(key1, Tuple.create().set("val", 11L), key3, Tuple.create().set("val", 33L)));
    Map<Tuple, Tuple> res = tbl.getAll(null, List.of(key1, key2, key3));
    assertEquals(2, res.size());
    assertEquals(Tuple.create().set("val", 11L), res.get(key1));
    assertEquals(Tuple.create().set("val", 33L), res.get(key3));
    assertNull(res.get(key2));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 40 with Tuple

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

the class KeyValueBinaryViewOperationsTest method replaceExact.

@Test
public void replaceExact() {
    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);
    // Ignore replace operation for non-existed KV pair.
    assertFalse(tbl.replace(null, key2, val, val2));
    assertNull(tbl.get(null, key2));
    tbl.put(null, key, val);
    // Replace existed KV pair.
    assertTrue(tbl.replace(null, key, val, val2));
    assertEqualsValues(schema, val2, 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)

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