Search in sources :

Example 11 with SchemaDescriptor

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

the class SchemaDescriptorConverterTest method testComplexPrimaryKey.

/**
 * Convert table with complex primary key and check it.
 */
@Test
public void testComplexPrimaryKey() {
    TableDefinitionBuilder bldr = getBuilder(false, false);
    TableDefinition tblSchm = bldr.withPrimaryKey(SchemaBuilders.primaryKey().withColumns("INT8", "ID").build()).build();
    SchemaDescriptor tblDscr = SchemaDescriptorConverter.convert(1, tblSchm);
    assertEquals(2, tblDscr.keyColumns().length());
    assertEquals(2, tblDscr.colocationColumns().length);
    assertEquals(columns - 2, tblDscr.valueColumns().length());
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableDefinitionBuilder(org.apache.ignite.schema.definition.builder.TableDefinitionBuilder) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Test(org.junit.jupiter.api.Test)

Example 12 with SchemaDescriptor

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

the class SchemaDescriptorConverterTest method testComplexPrimaryKeyWithAffinity.

/**
 * Convert table with complex primary key with affinity column configured and check it.
 */
@Test
public void testComplexPrimaryKeyWithAffinity() {
    TableDefinitionBuilder bldr = getBuilder(false, false);
    TableDefinition tblSchm = bldr.withPrimaryKey(SchemaBuilders.primaryKey().withColumns("INT8", "ID").withColocationColumns("INT8").build()).build();
    SchemaDescriptor tblDscr = SchemaDescriptorConverter.convert(1, tblSchm);
    assertEquals(2, tblDscr.keyColumns().length());
    assertEquals(1, tblDscr.colocationColumns().length);
    assertEquals(columns - 2, tblDscr.valueColumns().length());
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableDefinitionBuilder(org.apache.ignite.schema.definition.builder.TableDefinitionBuilder) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Test(org.junit.jupiter.api.Test)

Example 13 with SchemaDescriptor

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

the class SchemaRegistryImplTest method testWrongSchemaVersionRegistration.

/**
 * Check registration of schema with wrong versions.
 */
@Test
public void testWrongSchemaVersionRegistration() {
    final SchemaDescriptor schemaV0 = new SchemaDescriptor(INITIAL_SCHEMA_VERSION, new Column[] { new Column("keyLongCol", INT64, false) }, new Column[] { new Column("valBytesCol", BYTES, true) });
    final SchemaDescriptor schemaV1 = new SchemaDescriptor(0, 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) });
    final SchemaRegistryImpl reg = new SchemaRegistryImpl(v -> null, () -> INITIAL_SCHEMA_VERSION);
    assertEquals(INITIAL_SCHEMA_VERSION, reg.lastSchemaVersion());
    assertNull(reg.schema());
    // Try to register schema with initial version.
    assertThrows(SchemaRegistryException.class, () -> reg.onSchemaRegistered(schemaV0));
    assertEquals(INITIAL_SCHEMA_VERSION, reg.lastSchemaVersion());
    assertNull(reg.schema());
    assertThrows(SchemaRegistryException.class, () -> reg.schema(INITIAL_SCHEMA_VERSION));
    // Try to register schema with version of 0-zero.
    assertThrows(SchemaRegistryException.class, () -> reg.onSchemaRegistered(schemaV1));
    assertEquals(INITIAL_SCHEMA_VERSION, reg.lastSchemaVersion());
    assertThrows(SchemaRegistryException.class, () -> reg.schema(INITIAL_SCHEMA_VERSION));
    assertThrows(SchemaRegistryException.class, () -> reg.schema(0));
    // Try to register schema with version of 2.
    assertThrows(SchemaRegistryException.class, () -> reg.onSchemaRegistered(schemaV2));
    assertEquals(INITIAL_SCHEMA_VERSION, reg.lastSchemaVersion());
    assertThrows(SchemaRegistryException.class, () -> reg.schema(INITIAL_SCHEMA_VERSION));
    assertThrows(SchemaRegistryException.class, () -> reg.schema(0));
    assertThrows(SchemaRegistryException.class, () -> reg.schema(1));
    assertThrows(SchemaRegistryException.class, () -> reg.schema(2));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Test(org.junit.jupiter.api.Test)

Example 14 with SchemaDescriptor

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

the class SchemaRegistryImplTest method testSchemaCleanup.

/**
 * Check schema cleanup.
 */
@Test
public void testSchemaCleanup() {
    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 SchemaRegistryImpl reg = new SchemaRegistryImpl(v -> null, () -> INITIAL_SCHEMA_VERSION);
    assertEquals(INITIAL_SCHEMA_VERSION, reg.lastSchemaVersion());
    // Fail to cleanup initial schema
    assertThrows(SchemaRegistryException.class, () -> reg.onSchemaDropped(INITIAL_SCHEMA_VERSION));
    assertThrows(SchemaRegistryException.class, () -> reg.onSchemaDropped(0));
    // Register schema with very first version.
    reg.onSchemaRegistered(schemaV1);
    assertEquals(1, reg.lastSchemaVersion());
    assertNotNull(reg.schema());
    assertNotNull(reg.schema(1));
    // Try to remove latest schema.
    assertThrows(SchemaRegistryException.class, () -> reg.onSchemaDropped(1));
    assertEquals(1, reg.lastSchemaVersion());
    assertNotNull(reg.schema());
    assertNotNull(reg.schema(1));
    // Register new schema with next version.
    reg.onSchemaRegistered(schemaV2);
    reg.onSchemaRegistered(schemaV3);
    assertEquals(3, reg.lastSchemaVersion());
    assertNotNull(reg.schema(1));
    assertNotNull(reg.schema(2));
    assertNotNull(reg.schema(3));
    // Remove outdated schema 1.
    reg.onSchemaDropped(1);
    assertEquals(3, reg.lastSchemaVersion());
    assertThrows(SchemaRegistryException.class, () -> reg.schema(1));
    assertNotNull(reg.schema(2));
    assertNotNull(reg.schema(3));
    // Remove non-existed schemas.
    reg.onSchemaDropped(1);
    assertEquals(3, reg.lastSchemaVersion());
    assertThrows(SchemaRegistryException.class, () -> reg.schema(1));
    assertNotNull(reg.schema(2));
    assertNotNull(reg.schema(3));
    // Register new schema with next version.
    reg.onSchemaRegistered(schemaV4);
    assertEquals(4, reg.lastSchemaVersion());
    assertNotNull(reg.schema(2));
    assertNotNull(reg.schema(3));
    assertNotNull(reg.schema(4));
    // Remove non-existed schemas.
    reg.onSchemaDropped(1);
    assertEquals(4, reg.lastSchemaVersion());
    assertSameSchema(schemaV4, reg.schema());
    assertSameSchema(schemaV2, reg.schema(2));
    assertSameSchema(schemaV3, reg.schema(3));
    assertSameSchema(schemaV4, reg.schema(4));
    // Out of order remove.
    assertThrows(SchemaRegistryException.class, () -> reg.onSchemaDropped(3));
    // Correct removal order.
    reg.onSchemaDropped(2);
    reg.onSchemaDropped(3);
    assertEquals(4, reg.lastSchemaVersion());
    assertThrows(SchemaRegistryException.class, () -> reg.schema(1));
    assertThrows(SchemaRegistryException.class, () -> reg.schema(2));
    assertThrows(SchemaRegistryException.class, () -> reg.schema(3));
    assertSameSchema(schemaV4, reg.schema());
    assertSameSchema(schemaV4, reg.schema(4));
    // Try to remove latest schema.
    assertThrows(SchemaRegistryException.class, () -> reg.onSchemaDropped(4));
    assertEquals(4, reg.lastSchemaVersion());
    assertSameSchema(schemaV4, reg.schema(4));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Test(org.junit.jupiter.api.Test)

Example 15 with SchemaDescriptor

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

the class SchemaRegistryImplTest method testSchemaWithHistoryCleanup.

/**
 * Check schema cleanup.
 */
@Test
public void testSchemaWithHistoryCleanup() {
    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) });
    Map<Integer, SchemaDescriptor> history = schemaHistory(schemaV2, schemaV3, schemaV4);
    final SchemaRegistryImpl reg = new SchemaRegistryImpl(4, history::get, () -> INITIAL_SCHEMA_VERSION);
    assertEquals(4, reg.lastSchemaVersion());
    assertSameSchema(schemaV4, reg.schema());
    assertThrows(SchemaRegistryException.class, () -> reg.schema(1));
    assertSameSchema(schemaV2, reg.schema(2));
    assertSameSchema(schemaV3, reg.schema(3));
    assertSameSchema(schemaV4, reg.schema(4));
    history.remove(1);
    reg.onSchemaDropped(1);
    assertEquals(4, reg.lastSchemaVersion());
    assertNotNull(reg.schema(2));
    assertNotNull(reg.schema(3));
    assertNotNull(reg.schema(4));
    history.remove(2);
    history.remove(3);
    reg.onSchemaDropped(2);
    reg.onSchemaDropped(3);
    assertEquals(4, reg.lastSchemaVersion());
    assertThrows(SchemaRegistryException.class, () -> reg.schema(2));
    assertThrows(SchemaRegistryException.class, () -> reg.schema(3));
    assertNotNull(reg.schema(4));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Test(org.junit.jupiter.api.Test)

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