use of org.apache.ignite.internal.schema.mapping.ColumnMapper 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.mapping.ColumnMapper 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);
}
use of org.apache.ignite.internal.schema.mapping.ColumnMapper in project ignite-3 by apache.
the class SchemaRegistryImpl method resolveMapping.
/**
* ResolveMapping.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*
* @param curSchema Target schema.
* @param rowSchema Row schema.
* @return Column mapper for target schema.
*/
ColumnMapper resolveMapping(SchemaDescriptor curSchema, SchemaDescriptor rowSchema) {
assert curSchema.version() > rowSchema.version();
if (curSchema.version() == rowSchema.version() + 1) {
return curSchema.columnMapping();
}
final long mappingKey = (((long) curSchema.version()) << 32) | (rowSchema.version());
ColumnMapper mapping;
if ((mapping = mappingCache.get(mappingKey)) != null) {
return mapping;
}
mapping = schema(rowSchema.version() + 1).columnMapping();
for (int i = rowSchema.version() + 2; i <= curSchema.version(); i++) {
mapping = ColumnMapping.mergeMapping(mapping, schema(i));
}
mappingCache.putIfAbsent(mappingKey, mapping);
return mapping;
}
Aggregations