Search in sources :

Example 81 with Tuple

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

the class MutableRowTupleAdapterTest method testKeyValueSerialization.

@Test
public void testKeyValueSerialization() throws Exception {
    Random rnd = new Random();
    Tuple key1 = Tuple.create().set("keyUuidCol", UUID.randomUUID());
    Tuple val1 = 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("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));
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(fullSchema));
    Row row = new Row(fullSchema, new ByteBufferRow(marshaller.marshal(key1, val1).bytes()));
    Tuple key2 = deserializeTuple(serializeTuple(TableRow.keyTuple(row)));
    Tuple val2 = deserializeTuple(serializeTuple(TableRow.valueTuple(row)));
    assertEquals(key1, key2);
    assertEquals(val1, val2);
}
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) Tuple(org.apache.ignite.table.Tuple) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Test(org.junit.jupiter.api.Test)

Example 82 with Tuple

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

the class MutableRowTupleAdapterTest method testKeyValueTupleSchemaAwareness.

@Test
public void testKeyValueTupleSchemaAwareness() 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("foo", "bar");
    assertNotNull(((SchemaAware) tuple).schema());
    assertNull(((SchemaAware) key).schema());
    assertNotNull(((SchemaAware) val).schema());
    val.set("id", 1L);
    assertNotNull(((SchemaAware) tuple).schema());
    assertNull(((SchemaAware) key).schema());
    assertNull(((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)

Example 83 with Tuple

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

the class MutableRowTupleAdapterTest method testTupleEquality.

@Test
public void testTupleEquality() throws Exception {
    Random rnd = new Random();
    Tuple keyTuple = Tuple.create().set("keyUuidCol", UUID.randomUUID());
    Tuple valTuple = 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("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 tuple = Tuple.create(valTuple).set(keyTuple.columnName(0), keyTuple.value(0));
    // Check tuples backed with Row.
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(fullSchema));
    Row row = new Row(fullSchema, new ByteBufferRow(marshaller.marshal(keyTuple, valTuple).bytes()));
    Tuple rowKeyTuple = TableRow.keyTuple(row);
    Tuple rowValTuple = TableRow.valueTuple(row);
    final Tuple rowTuple = TableRow.tuple(new Row(fullSchema, new ByteBufferRow(marshaller.marshal(tuple).bytes())));
    assertEquals(keyTuple, rowKeyTuple);
    assertEquals(rowKeyTuple, keyTuple);
    assertEquals(valTuple, rowValTuple);
    assertEquals(rowValTuple, valTuple);
    assertEquals(tuple, rowTuple);
    assertEquals(rowTuple, tuple);
    // Check deserialized.
    Tuple keyTuple2 = deserializeTuple(serializeTuple(rowKeyTuple));
    Tuple valTuple2 = deserializeTuple(serializeTuple(rowValTuple));
    final Tuple tuple2 = deserializeTuple(serializeTuple(rowTuple));
    assertEquals(keyTuple, keyTuple2);
    assertEquals(keyTuple2, keyTuple);
    assertEquals(valTuple, valTuple2);
    assertEquals(valTuple2, valTuple);
    assertEquals(tuple, tuple2);
    assertEquals(tuple2, tuple);
    // Check the tuples backed with Row after update.
    rowKeyTuple.set("foo", "bar");
    rowValTuple.set("foo", "bar");
    rowTuple.set("foo", "bar");
    assertNotEquals(keyTuple, rowKeyTuple);
    assertNotEquals(rowKeyTuple, keyTuple);
    assertNotEquals(valTuple, rowValTuple);
    assertNotEquals(rowValTuple, valTuple);
    assertNotEquals(tuple, rowTuple);
    assertNotEquals(rowTuple, tuple);
    // Update original to make them equal.
    keyTuple.set("foo", "bar");
    valTuple.set("foo", "bar");
    tuple.set("foo", "bar");
    assertEquals(keyTuple, rowKeyTuple);
    assertEquals(rowKeyTuple, keyTuple);
    assertEquals(valTuple, rowValTuple);
    assertEquals(rowValTuple, valTuple);
    assertEquals(tuple, rowTuple);
    assertEquals(rowTuple, tuple);
}
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) Tuple(org.apache.ignite.table.Tuple) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Test(org.junit.jupiter.api.Test)

Example 84 with Tuple

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

the class MutableRowTupleAdapterTest method testKeyValueChunks.

@Test
public void testKeyValueChunks() throws TupleMarshallerException {
    SchemaDescriptor schema = new SchemaDescriptor(42, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("name".toUpperCase(), NativeTypes.STRING, true), new Column("price".toUpperCase(), NativeTypes.DOUBLE, true) });
    Tuple original = Tuple.create().set("id", 3L).set("name", "Shirt").set("price", 5.99d);
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    Row row = new Row(schema, new ByteBufferRow(marshaller.marshal(original).bytes()));
    Tuple key = TableRow.keyTuple(row);
    Tuple val = TableRow.valueTuple(row);
    assertEquals(3L, (Long) key.value("id"));
    assertEquals(3L, (Long) key.value(0));
    assertEquals("Shirt", val.value("name"));
    assertEquals("Shirt", val.value(1));
    assertEquals(5.99d, val.value("price"));
    assertEquals(5.99d, val.value(0));
    // Wrong columns.
    assertThrows(IndexOutOfBoundsException.class, () -> key.value(1));
    assertThrows(IllegalArgumentException.class, () -> key.value("price"));
    assertThrows(IndexOutOfBoundsException.class, () -> val.value(2));
    assertThrows(IllegalArgumentException.class, () -> val.value("id"));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) 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) Tuple(org.apache.ignite.table.Tuple) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Test(org.junit.jupiter.api.Test)

Example 85 with Tuple

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

the class MutableRowTupleAdapterTest method testRowTupleMutability.

@Test
public void testRowTupleMutability() 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);
    tuple.set("id", 2L);
    assertEquals(2L, (Long) tuple.value("id"));
    assertEquals(1L, (Long) key.value("id"));
    tuple.set("name", "noname");
    assertEquals("noname", tuple.value("name"));
    assertEquals("Shirt", val.value("name"));
    tuple.set("foo", "bar");
    assertEquals("bar", tuple.value("foo"));
    assertThrows(IllegalArgumentException.class, () -> key.value("foo"));
    assertThrows(IllegalArgumentException.class, () -> val.value("foo"));
}
Also used : 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