use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.
the class SchemaConfigurationConverterTest method createRegistry.
/**
* Prepare configuration registry for test.
*
* @throws ExecutionException If failed.
* @throws InterruptedException If failed.
*/
@BeforeEach
public void createRegistry() throws ExecutionException, InterruptedException {
confRegistry = new ConfigurationRegistry(List.of(TablesConfiguration.KEY, DataStorageConfiguration.KEY), Map.of(TableValidator.class, Set.of(TableValidatorImpl.INSTANCE)), new TestConfigurationStorage(DISTRIBUTED), List.of(), List.of(HashIndexConfigurationSchema.class, SortedIndexConfigurationSchema.class, PartialIndexConfigurationSchema.class, RocksDbDataRegionConfigurationSchema.class));
confRegistry.start();
tblBuilder = SchemaBuilders.tableBuilder("SNAME", "TNAME").columns(SchemaBuilders.column("COL1", ColumnType.DOUBLE).build(), SchemaBuilders.column("COL2", ColumnType.DOUBLE).build(), SchemaBuilders.column("A", ColumnType.INT8).build(), SchemaBuilders.column("B", ColumnType.INT8).build(), SchemaBuilders.column("C", ColumnType.INT8).build()).withPrimaryKey("COL1");
TableDefinition tbl = tblBuilder.build();
confRegistry.getConfiguration(TablesConfiguration.KEY).change(ch -> SchemaConfigurationConverter.createTable(tbl, ch).changeTables(tblsCh -> tblsCh.createOrUpdate(tbl.canonicalName(), tblCh -> tblCh.changeReplicas(1)))).get();
}
use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.
the class SchemaConfigurationConverterTest method testPartialIndex.
/**
* Add/remove PartialIndex into configuration and read it back.
*/
@Test
public void testPartialIndex() throws Exception {
PartialIndexDefinitionBuilder builder = SchemaBuilders.partialIndex("TEST");
builder.addIndexColumn("A").done();
builder.withExpression("WHERE A > 0");
PartialIndexDefinition idx = builder.build();
getTbl().change(ch -> SchemaConfigurationConverter.addIndex(idx, ch)).get();
TableDefinition tbl = SchemaConfigurationConverter.convert(getTbl().value());
PartialIndexDefinition idx2 = (PartialIndexDefinition) getIdx(idx.name(), tbl.indices());
assertNotNull(idx2);
assertEquals("PARTIAL", idx2.type());
assertEquals(idx.columns().size(), idx2.columns().size());
}
use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.
the class SchemaConfigurationConverterTest method testUniqIndex.
/**
* Add/remove index on primary key into configuration and read it back.
*/
@Test
public void testUniqIndex() throws Exception {
SortedIndexDefinition idx = SchemaBuilders.sortedIndex("pk_sorted").addIndexColumn("COL1").desc().done().unique(true).build();
getTbl().change(ch -> SchemaConfigurationConverter.addIndex(idx, ch)).get();
TableDefinition tbl = SchemaConfigurationConverter.convert(getTbl().value());
SortedIndexDefinition idx2 = (SortedIndexDefinition) getIdx(idx.name(), tbl.indices());
assertNotNull(idx2);
assertEquals("PK_SORTED", idx2.name());
assertEquals("SORTED", idx2.type());
assertEquals(idx.columns().stream().map(IndexColumnDefinition::name).collect(Collectors.toList()), idx2.columns().stream().map(IndexColumnDefinition::name).collect(Collectors.toList()));
assertTrue(idx2.unique());
}
use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.
the class SchemaConfigurationConverterTest method testUniqueIndexDetection.
/**
* Detect an index containing affinity key as unique one.
*/
@Disabled("https://issues.apache.org/jira/browse/IGNITE-15483")
@Test
public void testUniqueIndexDetection() throws Exception {
SortedIndexDefinition idx = SchemaBuilders.sortedIndex("uniq_sorted").addIndexColumn("A").done().addIndexColumn("COL1").desc().done().build();
getTbl().change(ch -> SchemaConfigurationConverter.addIndex(idx, ch)).get();
TableDefinition tbl = SchemaConfigurationConverter.convert(getTbl().value());
SortedIndexDefinition idx2 = (SortedIndexDefinition) getIdx(idx.name(), tbl.indices());
assertNotNull(idx2);
assertEquals("uniq_sorted", idx2.name());
assertEquals("SORTED", idx2.type());
assertTrue(idx2.unique());
assertEquals(2, idx2.columns().size());
assertEquals("A", idx2.columns().get(0).name());
assertEquals("COL1", idx2.columns().get(1).name());
assertEquals(SortOrder.ASC, idx2.columns().get(0).sortOrder());
assertEquals(SortOrder.DESC, idx2.columns().get(1).sortOrder());
}
use of org.apache.ignite.schema.definition.TableDefinition 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());
}
Aggregations