use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class KvMarshallerTest method classWithPrivateConstructor.
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithPrivateConstructor(MarshallerFactory factory) throws MarshallerException {
Column[] cols = new Column[] { new Column("primLongCol".toUpperCase(), INT64, false), new Column("primIntCol".toUpperCase(), INT32, false) };
SchemaDescriptor schema = new SchemaDescriptor(1, cols, cols);
KvMarshaller<TestObjectWithPrivateConstructor, TestObjectWithPrivateConstructor> marshaller = factory.create(schema, TestObjectWithPrivateConstructor.class, TestObjectWithPrivateConstructor.class);
final TestObjectWithPrivateConstructor key = TestObjectWithPrivateConstructor.randomObject(rnd);
final TestObjectWithPrivateConstructor val = TestObjectWithPrivateConstructor.randomObject(rnd);
BinaryRow row = marshaller.marshal(key, val);
Object key1 = marshaller.unmarshalKey(new Row(schema, row));
Object val1 = marshaller.unmarshalValue(new Row(schema, row));
assertTrue(key.getClass().isInstance(key1));
assertTrue(val.getClass().isInstance(val1));
assertEquals(key, key);
assertEquals(val, val1);
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class AbstractSerializerTest method defaultValueSerializeTest.
/**
* (de)Serialize default value test.
*/
@Test
public void defaultValueSerializeTest() {
AbstractSchemaSerializer assembler = SchemaSerializerImpl.INSTANCE;
SchemaDescriptor desc = new SchemaDescriptor(100500, new Column[] { new Column("A", NativeTypes.INT8, false, () -> (byte) 1), new Column("B", NativeTypes.INT16, false, () -> (short) 1), new Column("C", NativeTypes.INT32, false, () -> 1), new Column("D", NativeTypes.INT64, false, () -> 1L), new Column("E", NativeTypes.UUID, false, () -> new UUID(12, 34)), new Column("F", NativeTypes.FLOAT, false, () -> 1.0f), new Column("G", NativeTypes.DOUBLE, false, () -> 1.0d), new Column("H", NativeTypes.DATE, false) }, new Column[] { new Column("A1", NativeTypes.stringOf(128), false, () -> "test"), new Column("B1", NativeTypes.numberOf(255), false, () -> BigInteger.TEN), new Column("C1", NativeTypes.decimalOf(128, 64), false, () -> BigDecimal.TEN), new Column("D1", NativeTypes.bitmaskOf(256), false, BitSet::new) });
byte[] serialize = assembler.serialize(desc);
SchemaDescriptor deserialize = assembler.deserialize(serialize);
// key columns
assertEquals(deserialize.column("A").defaultValue(), (byte) 1);
assertEquals(deserialize.column("B").defaultValue(), (short) 1);
assertEquals(deserialize.column("C").defaultValue(), 1);
assertEquals(deserialize.column("D").defaultValue(), 1L);
assertEquals(deserialize.column("E").defaultValue(), new UUID(12, 34));
assertEquals(deserialize.column("F").defaultValue(), 1.0f);
assertEquals(deserialize.column("G").defaultValue(), 1.0d);
assertNull(deserialize.column("H").defaultValue());
// value columns
assertEquals(deserialize.column("A1").defaultValue(), "test");
assertEquals(deserialize.column("B1").defaultValue(), BigInteger.TEN);
assertEquals(deserialize.column("C1").defaultValue(), BigDecimal.TEN);
assertEquals(deserialize.column("D1").defaultValue(), new BitSet());
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class AbstractSerializerTest method columnOrderSerializeTest.
/**
* (de)Serialize schema test.
*/
@Test
public void columnOrderSerializeTest() {
AbstractSchemaSerializer assembler = SchemaSerializerImpl.INSTANCE;
Column[] keyCols = { new Column(0, "A", NativeTypes.UUID, false), new Column(1, "B", NativeTypes.INT64, false), new Column(2, "C", NativeTypes.INT8, false) };
Column[] valCols = { new Column(3, "A1", NativeTypes.stringOf(128), false), new Column(4, "B1", NativeTypes.INT64, false) };
SchemaDescriptor desc = new SchemaDescriptor(100500, keyCols, valCols);
byte[] serialize = assembler.serialize(desc);
SchemaDescriptor deserialize = assembler.deserialize(serialize);
assertEquals(desc.version(), deserialize.version());
ArrayList<Column> columns = new ArrayList<>();
Collections.addAll(columns, keyCols);
Collections.addAll(columns, valCols);
for (int i = 0; i < columns.size(); i++) {
Column col = deserialize.column(i);
assertEquals(columns.get(col.columnOrder()), col);
}
assertArrayEquals(columns.stream().map(Column::name).toArray(String[]::new), desc.columnNames().toArray(String[]::new));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class AbstractSerializerTest method columnMappingSerializeTest.
/**
* (de)Serialize column mapping test.
*/
@Test
public void columnMappingSerializeTest() {
final AbstractSchemaSerializer assembler = SchemaSerializerImpl.INSTANCE;
SchemaDescriptor desc = new SchemaDescriptor(100500, new Column[] { new Column("A", NativeTypes.INT8, false, () -> (byte) 1) }, new Column[] { new Column("A1", NativeTypes.stringOf(128), false, () -> "test"), new Column("B1", NativeTypes.numberOf(255), false, () -> BigInteger.TEN) });
ColumnMapper mapper = ColumnMapping.createMapper(desc);
mapper.add(0, 1);
Column c1 = new Column("C1", NativeTypes.stringOf(128), false, () -> "brandNewColumn").copy(2);
mapper.add(c1);
desc.columnMapping(mapper);
byte[] serialize = assembler.serialize(desc);
SchemaDescriptor deserialize = assembler.deserialize(serialize);
ColumnMapper mapper1 = deserialize.columnMapping();
assertEquals(1, mapper1.map(0));
assertEquals(c1, mapper1.mappedColumn(2));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class SortedIndexDescriptor method createSchemaDescriptor.
/**
* Creates a {@link SchemaDescriptor} from a list of index key columns.
*/
private static SchemaDescriptor createSchemaDescriptor(List<ColumnView> indexKeyColumnViews) {
Column[] keyColumns = new Column[indexKeyColumnViews.size()];
for (int i = 0; i < indexKeyColumnViews.size(); ++i) {
ColumnView columnView = indexKeyColumnViews.get(i);
ColumnDefinition columnDefinition = SchemaConfigurationConverter.convert(columnView);
keyColumns[i] = SchemaDescriptorConverter.convert(i, columnDefinition);
}
return new SchemaDescriptor(0, keyColumns, new Column[0]);
}
Aggregations