Search in sources :

Example 21 with SchemaDescriptor

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);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) TestObjectWithPrivateConstructor(org.apache.ignite.internal.schema.testobjects.TestObjectWithPrivateConstructor) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 22 with SchemaDescriptor

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());
}
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 23 with SchemaDescriptor

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));
}
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 24 with SchemaDescriptor

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));
}
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 25 with SchemaDescriptor

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]);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) ColumnView(org.apache.ignite.configuration.schemas.table.ColumnView) IndexColumnView(org.apache.ignite.configuration.schemas.table.IndexColumnView) ColumnDefinition(org.apache.ignite.schema.definition.ColumnDefinition)

Aggregations

SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)105 Column (org.apache.ignite.internal.schema.Column)78 Test (org.junit.jupiter.api.Test)48 Tuple (org.apache.ignite.table.Tuple)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 Row (org.apache.ignite.internal.schema.row.Row)32 MethodSource (org.junit.jupiter.params.provider.MethodSource)30 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)22 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)11 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)11 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)10 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)10 List (java.util.List)9 ArrayList (java.util.ArrayList)8 NotNull (org.jetbrains.annotations.NotNull)8 UUID (java.util.UUID)7 Collectors (java.util.stream.Collectors)7 TableImpl (org.apache.ignite.internal.table.TableImpl)7 Random (java.util.Random)6 Map (java.util.Map)5