Search in sources :

Example 1 with PrimaryKeyDefinition

use of org.apache.ignite.schema.definition.PrimaryKeyDefinition in project ignite-3 by apache.

the class PrimaryKeyDefinitionDefinitionBuilderTest method testPrimaryKeyWithColocationColumns.

/**
 * Test primary key parameters.
 */
@Test
public void testPrimaryKeyWithColocationColumns() {
    PrimaryKeyDefinitionBuilder builder = SchemaBuilders.primaryKey();
    builder.withColumns("A", "B", "C").withColocationColumns("B").build();
    PrimaryKeyDefinition idx = builder.build();
    assertEquals(3, idx.columns().size());
    assertEquals(1, idx.colocationColumns().size());
    assertTrue(idx.columns().containsAll(List.of("A", "B", "C")));
    assertTrue(idx.colocationColumns().contains("B"));
    assertFalse(idx.colocationColumns().contains("A"));
    assertFalse(idx.colocationColumns().contains("C"));
}
Also used : PrimaryKeyDefinition(org.apache.ignite.schema.definition.PrimaryKeyDefinition) PrimaryKeyDefinitionBuilder(org.apache.ignite.schema.definition.builder.PrimaryKeyDefinitionBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with PrimaryKeyDefinition

use of org.apache.ignite.schema.definition.PrimaryKeyDefinition in project ignite-3 by apache.

the class PrimaryKeyDefinitionDefinitionBuilderTest method testPrimaryKey.

/**
 * Test primary key parameters.
 */
@Test
public void testPrimaryKey() {
    PrimaryKeyDefinitionBuilder builder = SchemaBuilders.primaryKey();
    builder.withColumns("A", "B", "C").build();
    PrimaryKeyDefinition idx = builder.build();
    assertEquals(3, idx.columns().size());
    assertEquals(3, idx.colocationColumns().size());
    assertTrue(idx.columns().containsAll(List.of("A", "B", "C")));
    assertTrue(idx.colocationColumns().containsAll(List.of("A", "B", "C")));
}
Also used : PrimaryKeyDefinition(org.apache.ignite.schema.definition.PrimaryKeyDefinition) PrimaryKeyDefinitionBuilder(org.apache.ignite.schema.definition.builder.PrimaryKeyDefinitionBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with PrimaryKeyDefinition

use of org.apache.ignite.schema.definition.PrimaryKeyDefinition in project ignite-3 by apache.

the class SchemaConfigurationConverter method convert.

/**
 * Convert table configuration view to table schema.
 *
 * @param tblView TableView to convert.
 * @return Table schema.
 */
public static TableDefinitionImpl convert(TableView tblView) {
    String canonicalName = tblView.name();
    int sepPos = canonicalName.indexOf('.');
    String schemaName = canonicalName.substring(0, sepPos);
    String tableName = canonicalName.substring(sepPos + 1);
    NamedListView<? extends ColumnView> colsView = tblView.columns();
    var columns = new LinkedHashMap<String, ColumnDefinition>(capacity(colsView.size()));
    for (String key : colsView.namedListKeys()) {
        ColumnView colView = colsView.get(key);
        if (colView != null) {
            ColumnDefinition definition = convert(colView);
            columns.put(definition.name(), definition);
        }
    }
    NamedListView<? extends TableIndexView> idxsView = tblView.indices();
    var indices = new HashMap<String, IndexDefinition>(capacity(idxsView.size()));
    for (String key : idxsView.namedListKeys()) {
        IndexDefinition definition = convert(idxsView.get(key));
        indices.put(definition.name(), definition);
    }
    PrimaryKeyDefinition primaryKey = convert(tblView.primaryKey());
    return new TableDefinitionImpl(schemaName, tableName, columns, primaryKey, indices);
}
Also used : TableDefinitionImpl(org.apache.ignite.internal.schema.definition.TableDefinitionImpl) HashIndexDefinition(org.apache.ignite.schema.definition.index.HashIndexDefinition) SortedIndexDefinition(org.apache.ignite.schema.definition.index.SortedIndexDefinition) IndexDefinition(org.apache.ignite.schema.definition.index.IndexDefinition) PartialIndexDefinition(org.apache.ignite.schema.definition.index.PartialIndexDefinition) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PrimaryKeyDefinition(org.apache.ignite.schema.definition.PrimaryKeyDefinition) ColumnView(org.apache.ignite.configuration.schemas.table.ColumnView) IndexColumnView(org.apache.ignite.configuration.schemas.table.IndexColumnView) LinkedHashMap(java.util.LinkedHashMap) IndexColumnDefinition(org.apache.ignite.schema.definition.index.IndexColumnDefinition) SortedIndexColumnDefinition(org.apache.ignite.schema.definition.index.SortedIndexColumnDefinition) ColumnDefinition(org.apache.ignite.schema.definition.ColumnDefinition)

Aggregations

PrimaryKeyDefinition (org.apache.ignite.schema.definition.PrimaryKeyDefinition)3 PrimaryKeyDefinitionBuilder (org.apache.ignite.schema.definition.builder.PrimaryKeyDefinitionBuilder)2 Test (org.junit.jupiter.api.Test)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ColumnView (org.apache.ignite.configuration.schemas.table.ColumnView)1 IndexColumnView (org.apache.ignite.configuration.schemas.table.IndexColumnView)1 TableDefinitionImpl (org.apache.ignite.internal.schema.definition.TableDefinitionImpl)1 ColumnDefinition (org.apache.ignite.schema.definition.ColumnDefinition)1 HashIndexDefinition (org.apache.ignite.schema.definition.index.HashIndexDefinition)1 IndexColumnDefinition (org.apache.ignite.schema.definition.index.IndexColumnDefinition)1 IndexDefinition (org.apache.ignite.schema.definition.index.IndexDefinition)1 PartialIndexDefinition (org.apache.ignite.schema.definition.index.PartialIndexDefinition)1 SortedIndexColumnDefinition (org.apache.ignite.schema.definition.index.SortedIndexColumnDefinition)1 SortedIndexDefinition (org.apache.ignite.schema.definition.index.SortedIndexDefinition)1