use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.
the class UpgradingRowAdapterTest method testVariousColumnTypes.
@Test
public void testVariousColumnTypes() {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("keyUuidCol", NativeTypes.UUID, false) }, new Column[] { new Column("valByteCol", INT8, true), new Column("valShortCol", INT16, true), new Column("valIntCol", INT32, true), new Column("valLongCol", INT64, true), new Column("valFloatCol", FLOAT, true), new Column("valDoubleCol", DOUBLE, true), new Column("valDateCol", DATE, true), new Column("valTimeCol", time(), true), new Column("valDateTimeCol", datetime(), true), new Column("valTimeStampCol", timestamp(), true), new Column("valBitmask1Col", NativeTypes.bitmaskOf(22), true), new Column("valBytesCol", BYTES, false), new Column("valStringCol", STRING, false), new Column("valNumberCol", NativeTypes.numberOf(20), false), new Column("valDecimalCol", NativeTypes.decimalOf(25, 5), false) });
SchemaDescriptor schema2 = new SchemaDescriptor(2, new Column[] { new Column("keyUuidCol", NativeTypes.UUID, false) }, new Column[] { new Column("added", INT8, true), new Column("valByteCol", INT8, true), new Column("valShortCol", INT16, true), new Column("valIntCol", INT32, true), new Column("valLongCol", INT64, true), new Column("valFloatCol", FLOAT, true), new Column("valDoubleCol", DOUBLE, true), new Column("valDateCol", DATE, true), new Column("valTimeCol", time(), true), new Column("valDateTimeCol", datetime(), true), new Column("valTimeStampCol", timestamp(), true), new Column("valBitmask1Col", NativeTypes.bitmaskOf(22), true), new Column("valBytesCol", BYTES, false), new Column("valStringCol", STRING, false), new Column("valNumberCol", NativeTypes.numberOf(20), false), new Column("valDecimalCol", NativeTypes.decimalOf(25, 5), false) });
int addedColumnIndex = schema2.column("added").schemaIndex();
schema2.columnMapping(new ColumnMapper() {
@Override
public ColumnMapper add(@NotNull Column col) {
return null;
}
@Override
public ColumnMapper add(int from, int to) {
return null;
}
@Override
public int map(int idx) {
return idx < addedColumnIndex ? idx : idx == addedColumnIndex ? -1 : idx - 1;
}
@Override
public Column mappedColumn(int idx) {
return idx == addedColumnIndex ? schema2.column(idx) : null;
}
});
List<Object> values = generateRowValues(schema);
ByteBufferRow row = new ByteBufferRow(serializeValuesToRow(schema, values));
// Validate row.
validateRow(values, new SchemaRegistryImpl(1, v -> v == 1 ? schema : schema2, () -> INITIAL_SCHEMA_VERSION), row);
// Validate upgraded row.
values.add(addedColumnIndex, null);
validateRow(values, new SchemaRegistryImpl(2, v -> v == 1 ? schema : schema2, () -> INITIAL_SCHEMA_VERSION), row);
}
use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.
the class RecordMarshallerTest method classLoader.
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classLoader(MarshallerFactory factory) throws MarshallerException, IllegalAccessException {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(new DynamicClassLoader(getClass().getClassLoader()));
Column[] keyCols = new Column[] { new Column("key".toUpperCase(), INT64, false) };
Column[] valCols = new Column[] { new Column("col0".toUpperCase(), INT64, false), new Column("col1".toUpperCase(), INT64, false), new Column("col2".toUpperCase(), INT64, false) };
SchemaDescriptor schema = new SchemaDescriptor(1, keyCols, valCols);
final Class<Object> recClass = (Class<Object>) createGeneratedObjectClass();
final ObjectFactory<Object> objFactory = new ObjectFactory<>(recClass);
RecordMarshaller<Object> marshaller = factory.create(schema, recClass);
Object rec = objFactory.create();
BinaryRow row = marshaller.marshal(rec);
Object restoredRec = marshaller.unmarshal(new Row(schema, row));
assertDeepEquals(recClass, rec, restoredRec);
} finally {
Thread.currentThread().setContextClassLoader(loader);
}
}
use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.
the class RecordMarshallerTest method complexType.
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void complexType(MarshallerFactory factory) throws MarshallerException {
SchemaDescriptor schema = new SchemaDescriptor(1, keyColumns(), valueColumnsAllTypes());
final TestObjectWithAllTypes rec = TestObjectWithAllTypes.randomObject(rnd);
RecordMarshaller<TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class);
BinaryRow row = marshaller.marshal(rec);
TestObjectWithAllTypes restoredRec = marshaller.unmarshal(new Row(schema, row));
assertTrue(rec.getClass().isInstance(restoredRec));
assertEquals(rec, restoredRec);
}
use of org.apache.ignite.internal.schema.row.Row 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");
}
use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.
the class ColumnBindingTest method wrongIdentityBinding.
/**
* Wrong identity binding.
*/
@Test
public void wrongIdentityBinding() {
// Incompatible types.
final ColumnBinding binding = ColumnBinding.createIdentityBinding(new Column("val", UUID, true).copy(0), java.util.UUID.class, null);
assertThrows(MarshallerException.class, () -> binding.value("Some string"));
final Pair<RowAssembler, Row> mocks = createMocks();
assertThrows(MarshallerException.class, () -> binding.write(mocks.getFirst(), "Other string"));
// Implicit serialization is not supported yet.
assertThrows(IllegalArgumentException.class, () -> ColumnBinding.createIdentityBinding(new Column("val", BYTES, true).copy(0), TestSimpleObject.class, null));
}
Aggregations