use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class SchemaRegistryImplTest method testInitialSchemaWithTailHistory.
/**
* Check schema registration with history tail.
*/
@Test
public void testInitialSchemaWithTailHistory() {
final SchemaDescriptor schemaV1 = new SchemaDescriptor(1, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true) });
final SchemaDescriptor schemaV2 = new SchemaDescriptor(2, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true), new Column("valStringCol", STRING, true) });
final SchemaDescriptor schemaV3 = new SchemaDescriptor(3, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valStringCol", STRING, true) });
final SchemaDescriptor schemaV4 = new SchemaDescriptor(4, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true), new Column("valStringCol", STRING, true) });
final SchemaDescriptor schemaV5 = new SchemaDescriptor(5, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valStringCol", STRING, true) });
Map<Integer, SchemaDescriptor> history = schemaHistory(schemaV2, schemaV3);
final SchemaRegistryImpl reg = new SchemaRegistryImpl(3, history::get, () -> INITIAL_SCHEMA_VERSION);
assertEquals(3, reg.lastSchemaVersion());
assertSameSchema(schemaV3, reg.schema());
assertThrows(SchemaRegistryException.class, () -> reg.schema(1));
assertSameSchema(schemaV2, reg.schema(2));
assertSameSchema(schemaV3, reg.schema(3));
// Register schema with duplicate version.
assertThrows(SchemaRegistrationConflictException.class, () -> reg.onSchemaRegistered(schemaV2));
assertEquals(3, reg.lastSchemaVersion());
assertSameSchema(schemaV3, reg.schema());
// Register schema with out-of-order version.
assertThrows(SchemaRegistryException.class, () -> reg.onSchemaRegistered(schemaV5));
assertEquals(3, reg.lastSchemaVersion());
assertSameSchema(schemaV3, reg.schema());
// Register schema with outdated version.
assertThrows(SchemaRegistrationConflictException.class, () -> reg.onSchemaRegistered(schemaV1));
assertEquals(3, reg.lastSchemaVersion());
assertSameSchema(schemaV3, reg.schema());
assertThrows(SchemaRegistryException.class, () -> reg.schema(1));
assertSameSchema(schemaV2, reg.schema(2));
assertSameSchema(schemaV3, reg.schema(3));
// Register schema with next version.
reg.onSchemaRegistered(schemaV4);
assertEquals(4, reg.lastSchemaVersion());
assertSameSchema(schemaV4, reg.schema());
assertSameSchema(schemaV2, reg.schema(2));
assertSameSchema(schemaV3, reg.schema(3));
assertSameSchema(schemaV4, reg.schema(4));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor 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.SchemaDescriptor in project ignite-3 by apache.
the class SchemaDescriptorConverterTest method testColumnOrder.
/**
* Convert table with complex primary key and check it.
*/
@Test
public void testColumnOrder() {
ColumnDefinition[] cols = { SchemaBuilders.column("ID", ColumnType.UUID).build(), SchemaBuilders.column("STRING", ColumnType.string()).build(), SchemaBuilders.column("INT32", ColumnType.INT32).build(), SchemaBuilders.column("INT64", ColumnType.INT64).build(), SchemaBuilders.column("DOUBLE", ColumnType.DOUBLE).build(), SchemaBuilders.column("UUID", ColumnType.UUID).build(), SchemaBuilders.column("INT16", ColumnType.INT16).build(), SchemaBuilders.column("BITMASK_FS10", ColumnType.bitmaskOf(10)).build() };
TableDefinition tblSchm = SchemaBuilders.tableBuilder("SCHEMA", "TABLE").columns(cols).withPrimaryKey(SchemaBuilders.primaryKey().withColumns("INT32", "ID").withColocationColumns("INT32").build()).build();
SchemaDescriptor tblDscr = SchemaDescriptorConverter.convert(1, tblSchm);
for (int i = 0; i < cols.length; i++) {
Column col = tblDscr.column(i);
assertEquals(col.name(), cols[col.columnOrder()].name());
}
assertArrayEquals(Arrays.stream(cols).map(ColumnDefinition::name).toArray(String[]::new), tblDscr.columnNames().toArray(String[]::new));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class SchemaDescriptorConverterTest method testConvert.
/**
* Test set of columns.
*
* @param nullable Nullable flag.
*/
private void testConvert(boolean nullable) {
TableDefinition tblSchm = getBuilder(nullable, true).build();
SchemaDescriptor tblDscr = SchemaDescriptorConverter.convert(1, tblSchm);
assertEquals(1, tblDscr.keyColumns().length());
testCol(tblDscr.keyColumns(), "ID", NativeTypeSpec.UUID, false);
assertEquals(columns - 1, tblDscr.valueColumns().length());
testCol(tblDscr.valueColumns(), "INT8", NativeTypeSpec.INT8, nullable);
testCol(tblDscr.valueColumns(), "INT16", NativeTypeSpec.INT16, nullable);
testCol(tblDscr.valueColumns(), "INT32", NativeTypeSpec.INT32, nullable);
testCol(tblDscr.valueColumns(), "INT64", NativeTypeSpec.INT64, nullable);
testCol(tblDscr.valueColumns(), "FLOAT", NativeTypeSpec.FLOAT, nullable);
testCol(tblDscr.valueColumns(), "DOUBLE", NativeTypeSpec.DOUBLE, nullable);
testCol(tblDscr.valueColumns(), "UUID", NativeTypeSpec.UUID, nullable);
testCol(tblDscr.valueColumns(), "STRING", NativeTypeSpec.STRING, nullable);
testCol(tblDscr.valueColumns(), "STRING_FS10", NativeTypeSpec.STRING, nullable);
testCol(tblDscr.valueColumns(), "BLOB", NativeTypeSpec.BYTES, nullable);
testCol(tblDscr.valueColumns(), "DECIMAL", NativeTypeSpec.DECIMAL, nullable);
testCol(tblDscr.valueColumns(), "NUMBER", NativeTypeSpec.NUMBER, nullable);
testCol(tblDscr.valueColumns(), "DECIMAL", NativeTypeSpec.DECIMAL, nullable);
testCol(tblDscr.valueColumns(), "BITMASK_FS10", NativeTypeSpec.BITMASK, nullable);
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class RecordMarshallerTest method classWithWrongFieldType.
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithWrongFieldType(MarshallerFactory factory) {
SchemaDescriptor schema = new SchemaDescriptor(1, keyColumns(), new Column[] { new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("shortCol".toUpperCase(), UUID, true) });
RecordMarshaller<TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class);
final TestObjectWithAllTypes rec = TestObjectWithAllTypes.randomObject(rnd);
assertThrows(MarshallerException.class, () -> marshaller.marshal(rec), "Failed to write field [name=shortCol]");
}
Aggregations