Search in sources :

Example 1 with AbstractSchemaSerializer

use of org.apache.ignite.internal.schema.marshaller.schema.AbstractSchemaSerializer 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());
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) AbstractSchemaSerializer(org.apache.ignite.internal.schema.marshaller.schema.AbstractSchemaSerializer) Column(org.apache.ignite.internal.schema.Column) BitSet(java.util.BitSet) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 2 with AbstractSchemaSerializer

use of org.apache.ignite.internal.schema.marshaller.schema.AbstractSchemaSerializer 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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) AbstractSchemaSerializer(org.apache.ignite.internal.schema.marshaller.schema.AbstractSchemaSerializer) Column(org.apache.ignite.internal.schema.Column) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 3 with AbstractSchemaSerializer

use of org.apache.ignite.internal.schema.marshaller.schema.AbstractSchemaSerializer 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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) AbstractSchemaSerializer(org.apache.ignite.internal.schema.marshaller.schema.AbstractSchemaSerializer) Column(org.apache.ignite.internal.schema.Column) ColumnMapper(org.apache.ignite.internal.schema.mapping.ColumnMapper) Test(org.junit.jupiter.api.Test)

Example 4 with AbstractSchemaSerializer

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

the class AbstractSerializerTest method schemaSerializeTest.

/**
 * (de)Serialize schema test.
 */
@Test
public void schemaSerializeTest() {
    AbstractSchemaSerializer assembler = SchemaSerializerImpl.INSTANCE;
    SchemaDescriptor desc = new SchemaDescriptor(100500, new Column[] { new Column("A", NativeTypes.INT8, false), new Column("B", NativeTypes.INT16, false), new Column("C", NativeTypes.INT32, false), new Column("D", NativeTypes.INT64, false), new Column("E", NativeTypes.UUID, false), new Column("F", NativeTypes.FLOAT, false), new Column("G", NativeTypes.DOUBLE, false), new Column("H", NativeTypes.DATE, false) }, new Column[] { new Column("A1", NativeTypes.stringOf(128), false), new Column("B1", NativeTypes.numberOf(255), false), new Column("C1", NativeTypes.decimalOf(128, 64), false), new Column("D1", NativeTypes.bitmaskOf(256), false), new Column("E1", NativeTypes.datetime(8), false), new Column("F1", NativeTypes.time(8), false), new Column("G1", NativeTypes.timestamp(8), true) });
    byte[] serialize = assembler.serialize(desc);
    SchemaDescriptor deserialize = assembler.deserialize(serialize);
    assertEquals(desc.version(), deserialize.version());
    assertArrayEquals(desc.keyColumns().columns(), deserialize.keyColumns().columns());
    assertArrayEquals(desc.valueColumns().columns(), deserialize.valueColumns().columns());
    assertArrayEquals(desc.colocationColumns(), deserialize.colocationColumns());
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) AbstractSchemaSerializer(org.apache.ignite.internal.schema.marshaller.schema.AbstractSchemaSerializer) Column(org.apache.ignite.internal.schema.Column) Test(org.junit.jupiter.api.Test)

Aggregations

Column (org.apache.ignite.internal.schema.Column)4 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)4 AbstractSchemaSerializer (org.apache.ignite.internal.schema.marshaller.schema.AbstractSchemaSerializer)4 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 UUID (java.util.UUID)1 ColumnMapper (org.apache.ignite.internal.schema.mapping.ColumnMapper)1