Search in sources :

Example 91 with Tuple

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

the class RecordBinaryViewOperationsTest method defaultValues.

@Test
public void defaultValues() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, true, () -> 28L), new Column("str".toUpperCase(), NativeTypes.stringOf(3), true, () -> "ABC"), new Column("blob".toUpperCase(), NativeTypes.blobOf(3), true, () -> new byte[] { 0, 1, 2 }) });
    RecordView<Tuple> tbl = createTableImpl(schema).recordView();
    final Tuple keyTuple0 = Tuple.create().set("id", 0L);
    final Tuple keyTuple1 = Tuple.create().set("id", 1L);
    final Tuple tuple0 = Tuple.create().set("id", 0L);
    final Tuple tupleExpected0 = Tuple.create().set("id", 0L).set("val", 28L).set("str", "ABC").set("blob", new byte[] { 0, 1, 2 });
    final Tuple tuple1 = Tuple.create().set("id", 1L).set("val", null).set("str", null).set("blob", null);
    tbl.insert(null, tuple0);
    tbl.insert(null, tuple1);
    assertEqualsRows(schema, tupleExpected0, tbl.get(null, keyTuple0));
    assertEqualsRows(schema, tuple1, tbl.get(null, keyTuple1));
}
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 92 with Tuple

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

the class RecordBinaryViewOperationsTest method remove.

@Test
public void remove() {
    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();
    tbl.upsert(null, Tuple.create().set("id", 1L).set("val", 11L));
    final Tuple keyTuple = Tuple.create().set("id", 1L);
    // Delete not existed keyTuple.
    assertFalse(tbl.delete(null, Tuple.create().set("id", 2L)));
    // Delete existed keyTuple.
    assertTrue(tbl.delete(null, keyTuple));
    assertNull(tbl.get(null, keyTuple));
    // Delete already deleted keyTuple.
    assertFalse(tbl.delete(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 93 with Tuple

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

the class RecordBinaryViewOperationsTest method validateSchema.

@Test
public void validateSchema() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, true), new Column("str".toUpperCase(), NativeTypes.stringOf(3), true), new Column("blob".toUpperCase(), NativeTypes.blobOf(3), true) });
    RecordView<Tuple> tbl = createTableImpl(schema).recordView();
    final Tuple keyTuple0 = new TestTupleBuilder().set("id", 0).set("id1", 0);
    final Tuple keyTuple1 = new TestTupleBuilder().set("id1", 0);
    final Tuple tuple0 = new TestTupleBuilder().set("id", 1L).set("str", "qweqweqwe").set("val", 11L);
    final Tuple tuple1 = new TestTupleBuilder().set("id", 1L).set("blob", new byte[] { 0, 1, 2, 3 }).set("val", 22L);
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.get(null, keyTuple0));
    assertThrowsWithCause(SchemaMismatchException.class, () -> tbl.get(null, keyTuple1));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple0));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple1));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.insert(null, tuple0));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.insert(null, tuple1));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple0));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple1));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TestTupleBuilder(org.apache.ignite.internal.table.impl.TestTupleBuilder) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 94 with Tuple

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

the class ClientKeyValueBinaryViewTest method testGetAndReplace.

@Test
public void testGetAndReplace() {
    KeyValueView<Tuple, Tuple> kvView = defaultTable().keyValueView();
    kvView.put(null, tupleKey(1L), tupleVal("1"));
    assertNull(kvView.getAndReplace(null, tupleKey(2L), tupleVal("2")));
    Tuple res = kvView.getAndReplace(null, tupleKey(1L), tupleVal("2"));
    assertEquals("1", res.stringValue(0));
    assertEquals("2", kvView.get(null, tupleKey(1L)).stringValue(0));
}
Also used : Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 95 with Tuple

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

the class ClientKeyValueBinaryViewTest method testKvPutRecordGet.

@Test
public void testKvPutRecordGet() {
    Table table = defaultTable();
    KeyValueView<Tuple, Tuple> kvView = table.keyValueView();
    Tuple key = defaultTupleKey();
    Tuple val = Tuple.create().set("name", "bar");
    kvView.put(null, key, val);
    Tuple res = table.recordView().get(null, key);
    assertEquals("bar", res.stringValue("name"));
    assertEquals(DEFAULT_ID, res.longValue("id"));
}
Also used : Table(org.apache.ignite.table.Table) 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