Search in sources :

Example 16 with ByteBufferRow

use of org.apache.ignite.internal.schema.ByteBufferRow 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 17 with ByteBufferRow

use of org.apache.ignite.internal.schema.ByteBufferRow 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 18 with ByteBufferRow

use of org.apache.ignite.internal.schema.ByteBufferRow 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)

Example 19 with ByteBufferRow

use of org.apache.ignite.internal.schema.ByteBufferRow 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 20 with ByteBufferRow

use of org.apache.ignite.internal.schema.ByteBufferRow in project ignite-3 by apache.

the class ItTablePersistenceTest method createKeyValueRow.

/**
 * Creates a {@link Row} with the supplied key and value.
 *
 * @param id    Key.
 * @param value Value.
 * @return Row.
 */
private static Row createKeyValueRow(long id, long value) {
    RowAssembler rowBuilder = new RowAssembler(SCHEMA, 0, 0);
    rowBuilder.appendLong(id);
    rowBuilder.appendLong(value);
    return new Row(SCHEMA, new ByteBufferRow(rowBuilder.toBytes()));
}
Also used : ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow)

Aggregations

ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)22 Row (org.apache.ignite.internal.schema.row.Row)14 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)10 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)10 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)10 Tuple (org.apache.ignite.table.Tuple)10 Test (org.junit.jupiter.api.Test)10 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)7 Random (java.util.Random)5 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)4 Column (org.apache.ignite.internal.schema.Column)3 SchemaAware (org.apache.ignite.internal.schema.SchemaAware)3 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)3 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)2 Timestamp (org.apache.ignite.internal.tx.Timestamp)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ByteBuffer (java.nio.ByteBuffer)1