Search in sources :

Example 11 with Row

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

the class UpgradingRowAdapterTest method validateRow.

private void validateRow(List<Object> values, SchemaRegistryImpl schemaRegistry, ByteBufferRow binaryRow) {
    Row row = schemaRegistry.resolve(binaryRow);
    SchemaDescriptor schema = row.schema();
    for (int i = 0; i < values.size(); i++) {
        Column col = schema.column(i);
        NativeTypeSpec type = col.type().spec();
        if (type == NativeTypeSpec.BYTES) {
            assertArrayEquals((byte[]) values.get(i), (byte[]) NativeTypeSpec.BYTES.objectValue(row, col.schemaIndex()), "Failed for column: " + col);
        } else {
            assertEquals(values.get(i), type.objectValue(row, col.schemaIndex()), "Failed for column: " + col);
        }
    }
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow)

Example 12 with Row

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

the class KvMarshallerTest method pojoWithFieldsOfAllTypes.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void pojoWithFieldsOfAllTypes(MarshallerFactory factory) throws MarshallerException {
    SchemaDescriptor schema = new SchemaDescriptor(1, columnsAllTypes(false), columnsAllTypes(true));
    final TestObjectWithAllTypes key = TestObjectWithAllTypes.randomKey(rnd);
    final TestObjectWithAllTypes val = TestObjectWithAllTypes.randomObject(rnd);
    KvMarshaller<TestObjectWithAllTypes, TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class, TestObjectWithAllTypes.class);
    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));
    assertEquals(key, restoredKey);
    assertEquals(val, restoredVal);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) 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 13 with Row

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

the class KvMarshallerTest method columnNameMapping.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void columnNameMapping(MarshallerFactory factory) throws MarshallerException {
    Assumptions.assumeFalse(factory instanceof AsmMarshallerGenerator, "Generated marshaller doesn't support column mapping, yet.");
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("key".toUpperCase(), INT64, false) }, new Column[] { new Column("col1".toUpperCase(), INT64, false), new Column("col2".toUpperCase(), INT64, true), new Column("col3".toUpperCase(), STRING, false) });
    Mapper<TestKeyObject> keyMapper = Mapper.builder(TestKeyObject.class).map("id", "key").build();
    Mapper<TestObject> valMapper = Mapper.builder(TestObject.class).map("longCol", "col1").map("stringCol", "col3").build();
    KvMarshaller<TestKeyObject, TestObject> marshaller = factory.create(schema, keyMapper, valMapper);
    final TestKeyObject key = TestKeyObject.randomObject(rnd);
    final TestObject val = TestObject.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));
    val.longCol2 = null;
    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 14 with Row

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

the class KvMarshallerTest method pojoMapping.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void pojoMapping(MarshallerFactory factory) throws MarshallerException, IOException {
    Assumptions.assumeFalse(factory instanceof AsmMarshallerGenerator, "Generated marshaller doesn't support column mapping.");
    final SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("key", INT64, false) }, new Column[] { new Column("val", BYTES, true) });
    final TestPojo pojo = new TestPojo(42);
    final byte[] serializedPojo = serializeObject(pojo);
    final KvMarshaller<Long, TestPojo> marshaller1 = factory.create(schema, Mapper.of(Long.class, "\"key\""), Mapper.of(TestPojo.class, "\"val\"", new SerializingConverter<>()));
    final KvMarshaller<Long, byte[]> marshaller2 = factory.create(schema, Mapper.of(Long.class, "\"key\""), Mapper.of(byte[].class, "\"val\""));
    final KvMarshaller<Long, TestPojoWrapper> marshaller3 = factory.create(schema, Mapper.of(Long.class, "\"key\""), Mapper.builder(TestPojoWrapper.class).map("pojoField", "\"val\"", new SerializingConverter<>()).build());
    final KvMarshaller<Long, TestPojoWrapper> marshaller4 = factory.create(schema, Mapper.of(Long.class, "\"key\""), Mapper.builder(TestPojoWrapper.class).map("rawField", "\"val\"").build());
    BinaryRow row = marshaller1.marshal(1L, pojo);
    BinaryRow row2 = marshaller2.marshal(1L, serializedPojo);
    BinaryRow row3 = marshaller3.marshal(1L, new TestPojoWrapper(pojo));
    BinaryRow row4 = marshaller4.marshal(1L, new TestPojoWrapper(serializedPojo));
    // Verify all rows are equivalent.
    assertArrayEquals(row.bytes(), row2.bytes());
    assertArrayEquals(row.bytes(), row3.bytes());
    assertArrayEquals(row.bytes(), row4.bytes());
    // Check key.
    assertEquals(1L, marshaller1.unmarshalKey(new Row(schema, row)));
    assertEquals(1L, marshaller2.unmarshalKey(new Row(schema, row)));
    assertEquals(1L, marshaller3.unmarshalKey(new Row(schema, row)));
    assertEquals(1L, marshaller4.unmarshalKey(new Row(schema, row)));
    // Check values.
    assertEquals(pojo, marshaller1.unmarshalValue(new Row(schema, row)));
    assertArrayEquals(serializedPojo, marshaller2.unmarshalValue(new Row(schema, row)));
    assertEquals(new TestPojoWrapper(pojo), marshaller3.unmarshalValue(new Row(schema, row)));
    assertEquals(new TestPojoWrapper(serializedPojo), marshaller4.unmarshalValue(new Row(schema, row)));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Column(org.apache.ignite.internal.schema.Column) AsmMarshallerGenerator(org.apache.ignite.internal.schema.marshaller.asm.AsmMarshallerGenerator) SerializingConverter(org.apache.ignite.internal.schema.marshaller.reflection.SerializingConverter) 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 15 with Row

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

the class KvMarshallerTest method classWithPrivateConstructor.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithPrivateConstructor(MarshallerFactory factory) throws MarshallerException {
    Column[] cols = new Column[] { new Column("primLongCol".toUpperCase(), INT64, false), new Column("primIntCol".toUpperCase(), INT32, false) };
    SchemaDescriptor schema = new SchemaDescriptor(1, cols, cols);
    KvMarshaller<TestObjectWithPrivateConstructor, TestObjectWithPrivateConstructor> marshaller = factory.create(schema, TestObjectWithPrivateConstructor.class, TestObjectWithPrivateConstructor.class);
    final TestObjectWithPrivateConstructor key = TestObjectWithPrivateConstructor.randomObject(rnd);
    final TestObjectWithPrivateConstructor val = TestObjectWithPrivateConstructor.randomObject(rnd);
    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));
    assertEquals(key, key);
    assertEquals(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) TestObjectWithPrivateConstructor(org.apache.ignite.internal.schema.testobjects.TestObjectWithPrivateConstructor) 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