Search in sources :

Example 56 with BinaryRow

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

the class RecordMarshallerValidationsTest method truncatedKey.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void truncatedKey(MarshallerFactory factory) throws MarshallerException {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("k1".toUpperCase(), INT32, false), new Column("k2".toUpperCase(), INT32, false) }, new Column[] { new Column("v1".toUpperCase(), STRING, false) });
    RecordMarshaller<TestK1K2V1> marshallerFull = factory.create(schema, TestK1K2V1.class);
    TestK1K2V1 fullRec = new TestK1K2V1(1, 1, "v1");
    BinaryRow row = marshallerFull.marshal(fullRec);
    Object restoredRec = marshallerFull.unmarshal(new Row(schema, row));
    assertTrue(fullRec.getClass().isInstance(restoredRec));
    assertThrows(IllegalArgumentException.class, () -> factory.create(schema, TestK2V1.class), "No field found for column k1");
}
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 57 with BinaryRow

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

the class SchemaRegistryImpl method resolveInternal.

/**
 * Resolves a schema for row.
 * The method is optimal when the latest schema is already gotten.
 *
 * @param row       Binary row.
 * @param curSchema The latest available local schema.
 * @return Schema-aware rows.
 */
@Nullable
private Row resolveInternal(BinaryRow row, SchemaDescriptor curSchema) {
    if (row == null) {
        return null;
    }
    final SchemaDescriptor rowSchema = schema(row.schemaVersion());
    if (curSchema.version() == rowSchema.version()) {
        return new Row(rowSchema, row);
    }
    ColumnMapper mapping = resolveMapping(curSchema, rowSchema);
    return new UpgradingRowAdapter(curSchema, rowSchema, row, mapping);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ColumnMapper(org.apache.ignite.internal.schema.mapping.ColumnMapper) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

BinaryRow (org.apache.ignite.internal.schema.BinaryRow)57 Row (org.apache.ignite.internal.schema.row.Row)34 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 MethodSource (org.junit.jupiter.params.provider.MethodSource)19 Column (org.apache.ignite.internal.schema.Column)18 ArrayList (java.util.ArrayList)13 NotNull (org.jetbrains.annotations.NotNull)11 IgniteException (org.apache.ignite.lang.IgniteException)10 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)9 CountDownLatch (java.util.concurrent.CountDownLatch)6 Subscription (java.util.concurrent.Flow.Subscription)6 Test (org.junit.jupiter.api.Test)5 Map (java.util.Map)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)4 HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 Flow (java.util.concurrent.Flow)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3