Search in sources :

Example 71 with Row

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

the class KvMarshallerTest method wideType.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void wideType(MarshallerFactory factory) throws MarshallerException {
    Column[] cols = new Column[] { new Column("primitiveLongCol".toUpperCase(), INT64, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("stringCol".toUpperCase(), STRING, false) };
    SchemaDescriptor schema = new SchemaDescriptor(1, cols, cols);
    KvMarshaller<TestObjectWithAllTypes, TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class, TestObjectWithAllTypes.class);
    final TestObjectWithAllTypes key = TestObjectWithAllTypes.randomObject(rnd);
    final TestObjectWithAllTypes val = TestObjectWithAllTypes.randomObject(rnd);
    BinaryRow row = marshaller.marshal(key, val);
    TestObjectWithAllTypes restoredVal = marshaller.unmarshalValue(new Row(schema, row));
    TestObjectWithAllTypes restoredKey = marshaller.unmarshalKey(new Row(schema, row));
    assertTrue(key.getClass().isInstance(restoredKey));
    assertTrue(val.getClass().isInstance(restoredVal));
    TestObjectWithAllTypes expectedKey = new TestObjectWithAllTypes();
    expectedKey.setPrimitiveLongCol(key.getPrimitiveLongCol());
    expectedKey.setPrimitiveDoubleCol(key.getPrimitiveDoubleCol());
    expectedKey.setStringCol(key.getStringCol());
    TestObjectWithAllTypes expectedVal = new TestObjectWithAllTypes();
    expectedVal.setPrimitiveLongCol(val.getPrimitiveLongCol());
    expectedVal.setPrimitiveDoubleCol(val.getPrimitiveDoubleCol());
    expectedVal.setStringCol(val.getStringCol());
    assertEquals(expectedKey, restoredKey);
    assertEquals(expectedVal, restoredVal);
    // Check non-mapped fields has default values.
    assertNull(restoredKey.getUuidCol());
    assertNull(restoredVal.getUuidCol());
    assertEquals(0, restoredKey.getPrimitiveIntCol());
    assertEquals(0, restoredVal.getPrimitiveIntCol());
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 72 with Row

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

the class KvMarshallerTest method narrowType.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void narrowType(MarshallerFactory factory) throws MarshallerException {
    Assumptions.assumeFalse(factory instanceof AsmMarshallerGenerator, "Generated marshaller doesn't support truncated values, yet.");
    Column[] cols = new Column[] { new Column("primitiveIntCol".toUpperCase(), INT32, false), new Column("primitiveLongCol".toUpperCase(), INT64, false), new Column("primitiveFloatCol".toUpperCase(), FLOAT, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("stringCol".toUpperCase(), STRING, false), new Column("uuidCol".toUpperCase(), UUID, false) };
    SchemaDescriptor schema = new SchemaDescriptor(1, cols, columnsAllTypes(true));
    KvMarshaller<TestTruncatedObject, TestTruncatedObject> marshaller = factory.create(schema, TestTruncatedObject.class, TestTruncatedObject.class);
    final TestTruncatedObject key = TestTruncatedObject.randomObject(rnd);
    final TestTruncatedObject val = TestTruncatedObject.randomObject(rnd);
    BinaryRow row = marshaller.marshal(key, val);
    Object restoredVal = marshaller.unmarshalValue(new Row(schema, row));
    Object restoredKey = marshaller.unmarshalKey(new Row(schema, row));
    assertTrue(key.getClass().isInstance(restoredKey));
    assertTrue(val.getClass().isInstance(restoredVal));
    assertEquals(key, restoredKey);
    assertEquals(val, restoredVal);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) AsmMarshallerGenerator(org.apache.ignite.internal.schema.marshaller.asm.AsmMarshallerGenerator) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 73 with Row

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

the class KvMarshallerTest method checkBasicType.

/**
 * Generate random key-value pair of given types and check serialization and deserialization works fine.
 *
 * @param factory KvMarshaller factory.
 * @param keyType Key type.
 * @param valType Value type.
 * @throws MarshallerException If (de)serialization failed.
 */
private void checkBasicType(MarshallerFactory factory, NativeType keyType, NativeType valType) throws MarshallerException {
    final Object key = generateRandomValue(keyType);
    final Object val = generateRandomValue(valType);
    Column[] keyCols = new Column[] { new Column("key", keyType, false) };
    Column[] valCols = new Column[] { new Column("val", valType, false) };
    SchemaDescriptor schema = new SchemaDescriptor(1, keyCols, valCols);
    KvMarshaller<Object, Object> marshaller = factory.create(schema, Mapper.of((Class<Object>) key.getClass(), "\"key\""), Mapper.of((Class<Object>) val.getClass(), "\"val\""));
    BinaryRow row = marshaller.marshal(key, val);
    Object key1 = marshaller.unmarshalKey(new Row(schema, row));
    Object val1 = marshaller.unmarshalValue(new Row(schema, row));
    assertTrue(key.getClass().isInstance(key1));
    assertTrue(val.getClass().isInstance(val1));
    compareObjects(keyType, key, key);
    compareObjects(valType, val, val1);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) BinaryRow(org.apache.ignite.internal.schema.BinaryRow)

Example 74 with Row

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

the class ColumnBindingTest method fieldBinding.

/**
 * All native types field binding.
 *
 * @throws Exception If failed.
 */
@Test
public void fieldBinding() throws Exception {
    Column[] cols = new Column[] { new Column("primitiveByteCol", INT8, false), new Column("primitiveShortCol", INT16, false), new Column("primitiveIntCol", INT32, false), new Column("primitiveLongCol", INT64, false), new Column("primitiveFloatCol", FLOAT, false), new Column("primitiveDoubleCol", DOUBLE, false), new Column("byteCol", INT8, false), new Column("shortCol", INT16, false), new Column("intCol", INT32, false), new Column("longCol", INT64, false), new Column("floatCol", FLOAT, false), new Column("doubleCol", DOUBLE, false), new Column("dateCol", DATE, false), new Column("timeCol", time(), false), new Column("dateTimeCol", datetime(), false), new Column("timestampCol", timestamp(), false), new Column("uuidCol", UUID, false), new Column("bitmaskCol", NativeTypes.bitmaskOf(9), false), new Column("stringCol", STRING, false), new Column("bytesCol", BYTES, false), new Column("numberCol", NativeTypes.numberOf(21), false), new Column("decimalCol", NativeTypes.decimalOf(19, 3), false) };
    final Pair<RowAssembler, Row> mocks = createMocks();
    final RowAssembler rowAssembler = mocks.getFirst();
    final Row row = mocks.getSecond();
    final TestObjectWithAllTypes obj = TestObjectWithAllTypes.randomObject(rnd);
    for (int i = 0; i < cols.length; i++) {
        ColumnBinding.createFieldBinding(cols[i].copy(i), TestObjectWithAllTypes.class, cols[i].name(), null).write(rowAssembler, obj);
    }
    final TestObjectWithAllTypes restoredObj = new TestObjectWithAllTypes();
    for (int i = 0; i < cols.length; i++) {
        ColumnBinding.createFieldBinding(cols[i].copy(i), TestObjectWithAllTypes.class, cols[i].name(), null).read(row, restoredObj);
    }
    assertEquals(obj, restoredObj);
}
Also used : Column(org.apache.ignite.internal.schema.Column) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Row(org.apache.ignite.internal.schema.row.Row) Test(org.junit.jupiter.api.Test)

Example 75 with Row

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

the class ColumnBindingTest method identityBindingWithConverter.

/**
 * Identity binding with converter.
 *
 * @throws Exception If failed.
 */
@Test
public void identityBindingWithConverter() throws Exception {
    final ColumnBinding binding = ColumnBinding.createIdentityBinding(new Column("val", BYTES, true).copy(0), TestSimpleObject.class, new SerializingConverter());
    final Pair<RowAssembler, Row> mocks = createMocks();
    final RowAssembler rowAssembler = mocks.getFirst();
    final Row row = mocks.getSecond();
    final TestSimpleObject obj = TestSimpleObject.randomObject(rnd);
    binding.write(rowAssembler, obj);
    Object restoredObj = binding.columnValue(row);
    assertEquals(obj, restoredObj);
}
Also used : TestSimpleObject(org.apache.ignite.internal.schema.testobjects.TestSimpleObject) Column(org.apache.ignite.internal.schema.Column) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) TestSimpleObject(org.apache.ignite.internal.schema.testobjects.TestSimpleObject) Row(org.apache.ignite.internal.schema.row.Row) Test(org.junit.jupiter.api.Test)

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