Search in sources :

Example 36 with Row

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

Example 37 with Row

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

the class MutableRowTupleAdapterTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    Random rnd = new Random();
    Tuple tup1 = 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));
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(fullSchema));
    Row row = new Row(fullSchema, new ByteBufferRow(marshaller.marshal(tup1).bytes()));
    Tuple tup2 = deserializeTuple(serializeTuple(TableRow.tuple(row)));
    assertEquals(tup1, tup2);
    assertEquals(tup2, tup1);
}
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 38 with Row

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

the class PartitionCommandListenerTest method getTestRow.

/**
 * Prepares a test row which contains key and value fields.
 *
 * @return Row.
 */
@NotNull
private Row getTestRow(int key, int val) {
    RowAssembler rowBuilder = new RowAssembler(SCHEMA, 0, 0);
    rowBuilder.appendInt(key);
    rowBuilder.appendInt(val);
    return new Row(SCHEMA, rowBuilder.build());
}
Also used : RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Row(org.apache.ignite.internal.schema.row.Row) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) NotNull(org.jetbrains.annotations.NotNull) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull)

Example 39 with Row

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

the class NumericTypesSerializerTest method testStringDecimalSpecialCase.

@Test
public void testStringDecimalSpecialCase() throws TupleMarshallerException {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(1, 0), false) });
    // representation of "0000" value.
    final Tuple tup = createTuple().set("key", rnd.nextLong()).set("decimalCol", new BigDecimal("0E+3"));
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    final Row row = marshaller.marshal(tup);
    assertEquals(row.decimalValue(1), BigDecimal.ZERO);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Row(org.apache.ignite.internal.schema.row.Row) Tuple(org.apache.ignite.table.Tuple) BigDecimal(java.math.BigDecimal) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with Row

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

the class NumericTypesSerializerTest method testSameBinaryRepresentation.

/**
 * Test.
 */
@ParameterizedTest
@MethodSource("sameDecimals")
public void testSameBinaryRepresentation(Pair<BigInteger, BigInteger> pair) throws Exception {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(19, 3), false) });
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    long randomKey = rnd.nextLong();
    final Tuple firstTup = createTuple().set("key", randomKey).set("decimalCol", pair.getFirst());
    final Tuple secondTup = createTuple().set("key", randomKey).set("decimalCol", pair.getSecond());
    final Row firstRow = marshaller.marshal(firstTup);
    final Row secondRow = marshaller.marshal(secondTup);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    firstRow.writeTo(stream);
    byte[] firstRowInBytes = stream.toByteArray();
    stream.reset();
    secondRow.writeTo(stream);
    byte[] secondRowInBytes = stream.toByteArray();
    assertArrayEquals(firstRowInBytes, secondRowInBytes);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Row(org.apache.ignite.internal.schema.row.Row) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Tuple(org.apache.ignite.table.Tuple) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Row (org.apache.ignite.internal.schema.row.Row)83 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)55 Column (org.apache.ignite.internal.schema.Column)34 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)30 NotNull (org.jetbrains.annotations.NotNull)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 MethodSource (org.junit.jupiter.params.provider.MethodSource)22 Tuple (org.apache.ignite.table.Tuple)21 Test (org.junit.jupiter.api.Test)18 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)17 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)15 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)15 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)15 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)14 ArrayList (java.util.ArrayList)8 InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)6 Random (java.util.Random)5 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)5 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)5 IgniteException (org.apache.ignite.lang.IgniteException)5