Search in sources :

Example 6 with Column

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

the class RecordMarshallerTest method classWithPrivateConstructor.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithPrivateConstructor(MarshallerFactory factory) throws MarshallerException, IllegalAccessException {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("primLongCol".toUpperCase(), INT64, false) }, new Column[] { new Column("primIntCol".toUpperCase(), INT32, false) });
    RecordMarshaller<TestObjectWithPrivateConstructor> marshaller = factory.create(schema, TestObjectWithPrivateConstructor.class);
    final TestObjectWithPrivateConstructor rec = TestObjectWithPrivateConstructor.randomObject(rnd);
    BinaryRow row = marshaller.marshal(rec);
    TestObjectWithPrivateConstructor restoredRec = marshaller.unmarshal(new Row(schema, row));
    assertDeepEquals(TestObjectWithPrivateConstructor.class, rec, restoredRec);
}
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)

Example 7 with Column

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

the class RecordMarshallerValidationsTest method testReadOnly.

/**
 * Check ability to read into truncated class, but not write it.
 */
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void testReadOnly(MarshallerFactory factory) throws MarshallerException {
    Column[] valCols = new Column[] { new Column("fbyte1".toUpperCase(), INT32, false), new Column("fbyte2".toUpperCase(), INT32, false) };
    SchemaDescriptor schema = new SchemaDescriptor(1, KEY_COLS, valCols);
    final FullRecClass rec = new FullRecClass(1, 1, 2);
    RecordMarshaller<FullRecClass> marshallerFull = factory.create(schema, FullRecClass.class);
    BinaryRow row = marshallerFull.marshal(rec);
    RecordMarshaller<TruncatedRecClass> marshaller = factory.create(schema, TruncatedRecClass.class);
    TruncatedRecClass restoredRec = marshaller.unmarshal(new Row(schema, row));
    assertEquals(rec.id, restoredRec.id);
    assertEquals(rec.fbyte1, restoredRec.fbyte1);
    assertThrows(MarshallerException.class, () -> marshaller.marshal(restoredRec));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with Column

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

the class RecordMarshallerValidationsTest method testColsWithNullable.

/**
 * Check nullable flag is taken into account if there is no field in specified class to marshall from.
 */
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void testColsWithNullable(MarshallerFactory factory) throws MarshallerException {
    Column[] valCols = new Column[] { new Column("fbyte1".toUpperCase(), INT32, false), new Column("fbyte2".toUpperCase(), INT32, true) };
    SchemaDescriptor schema = new SchemaDescriptor(1, KEY_COLS, valCols);
    final TruncatedRecClass rec = new TruncatedRecClass(1, 1);
    RecordMarshaller<TruncatedRecClass> marshaller = factory.create(schema, TruncatedRecClass.class);
    BinaryRow row = marshaller.marshal(rec);
    TruncatedRecClass restoredRec = marshaller.unmarshal(new Row(schema, row));
    assertTrue(rec.getClass().isInstance(restoredRec));
    assertEquals(rec, restoredRec);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with Column

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

the class RecordMarshallerValidationsTest method testColsWithDefaultValue.

/**
 * Check default value is taken into account if there is no field in specified class to marshall from.
 */
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void testColsWithDefaultValue(MarshallerFactory factory) throws MarshallerException {
    Column[] valCols = new Column[] { new Column("fbyte1".toUpperCase(), INT32, false), new Column("fbyte2".toUpperCase(), INT32, false, () -> 0x42) };
    SchemaDescriptor schema = new SchemaDescriptor(1, KEY_COLS, valCols);
    final TruncatedRecClass rec = new TruncatedRecClass(1, 1);
    RecordMarshaller<TruncatedRecClass> marshaller = factory.create(schema, TruncatedRecClass.class);
    BinaryRow row = marshaller.marshal(rec);
    TruncatedRecClass restoredRec = marshaller.unmarshal(new Row(schema, row));
    assertTrue(rec.getClass().isInstance(restoredRec));
    assertEquals(rec, restoredRec);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with Column

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

the class ColumnBindingTest method nullableFieldsBinding.

/**
 * Nullable fields binding.
 *
 * @throws Exception If failed.
 */
@Test
public void nullableFieldsBinding() throws Exception {
    Column[] cols = new Column[] { new Column("intCol", INT32, true), new Column("longCol", INT64, true), new Column("stringCol", STRING, true), new Column("bytesCol", BYTES, true) };
    final Pair<RowAssembler, Row> mocks = createMocks();
    final RowAssembler rowAssembler = mocks.getFirst();
    final Row row = mocks.getSecond();
    final TestSimpleObject obj = TestSimpleObject.randomObject(rnd);
    for (int i = 0; i < cols.length; i++) {
        ColumnBinding.createFieldBinding(cols[i].copy(i), TestSimpleObject.class, cols[i].name(), null).write(rowAssembler, obj);
    }
    final TestSimpleObject restoredObj = new TestSimpleObject();
    for (int i = 0; i < cols.length; i++) {
        ColumnBinding.createFieldBinding(cols[i].copy(i), TestSimpleObject.class, cols[i].name(), null).read(row, restoredObj);
    }
    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) Row(org.apache.ignite.internal.schema.row.Row) Test(org.junit.jupiter.api.Test)

Aggregations

Column (org.apache.ignite.internal.schema.Column)131 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)78 Test (org.junit.jupiter.api.Test)44 Row (org.apache.ignite.internal.schema.row.Row)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)31 Tuple (org.apache.ignite.table.Tuple)27 MethodSource (org.junit.jupiter.params.provider.MethodSource)27 SchemaException (org.apache.ignite.internal.schema.SchemaException)22 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)20 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)11 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)11 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)10 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)10 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)10 Arrays (java.util.Arrays)7 NotNull (org.jetbrains.annotations.NotNull)7 List (java.util.List)6 Random (java.util.Random)6 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)6 BigDecimal (java.math.BigDecimal)5