Search in sources :

Example 96 with Column

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

the class KvMarshallerTest method classWithWrongFieldType.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithWrongFieldType(MarshallerFactory factory) {
    Column[] keyCols = new Column[] { new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), false), new Column("shortCol".toUpperCase(), UUID, false) };
    Column[] valCols = new Column[] { new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("shortCol".toUpperCase(), UUID, true) };
    SchemaDescriptor schema = new SchemaDescriptor(1, keyCols, valCols);
    KvMarshaller<TestObjectWithAllTypes, TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class, TestObjectWithAllTypes.class);
    final TestObjectWithAllTypes key = TestObjectWithAllTypes.randomObject(rnd);
    final TestObjectWithAllTypes val = TestObjectWithAllTypes.randomObject(rnd);
    assertThrows(MarshallerException.class, () -> marshaller.marshal(key, val), "Failed to write field [name=shortCol]");
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 97 with Column

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

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

the class KvMarshallerTest method classWithoutKeyField.

/**
 * Try to create marshaller for class without field for key column.
 */
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithoutKeyField(MarshallerFactory factory) {
    Column[] keyCols = new Column[] { new Column("id".toUpperCase(), INT64, false), new Column("id2".toUpperCase(), INT64, false) };
    Column[] valCols = new Column[] { new Column("primitiveDoubleCol", DOUBLE, false) };
    SchemaDescriptor schema = new SchemaDescriptor(1, keyCols, valCols);
    assertThrows(IllegalArgumentException.class, () -> factory.create(schema, TestKeyObject.class, TestObjectWithAllTypes.class), "No field found for column id2");
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 99 with Column

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

the class KvMarshallerTest method classWithNoDefaultConstructor.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithNoDefaultConstructor(MarshallerFactory factory) {
    Column[] cols = new Column[] { new Column("primLongCol", INT64, false) };
    SchemaDescriptor schema = new SchemaDescriptor(1, cols, cols);
    final Object key = TestObjectWithNoDefaultConstructor.randomObject(rnd);
    final Object val = TestObjectWithNoDefaultConstructor.randomObject(rnd);
    assertThrows(IllegalArgumentException.class, () -> factory.create(schema, key.getClass(), val.getClass()));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 100 with Column

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

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