Search in sources :

Example 1 with TableDefinitionImpl

use of org.apache.ignite.internal.schema.definition.TableDefinitionImpl 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)

Example 2 with TableDefinitionImpl

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

the class TableValidatorImpl method validate.

/**
 * {@inheritDoc}
 */
@Override
public void validate(TableValidator annotation, ValidationContext<NamedListView<TableView>> ctx) {
    NamedListView<TableView> oldTables = ctx.getOldValue();
    NamedListView<TableView> newTables = ctx.getNewValue();
    for (String tableName : newTables.namedListKeys()) {
        TableView newTable = newTables.get(tableName);
        try {
            TableDefinitionImpl tbl = SchemaConfigurationConverter.convert(newTable);
            assert !tbl.keyColumns().isEmpty();
            assert !tbl.colocationColumns().isEmpty();
            TableDefinitionBuilderImpl.validateIndices(tbl.indices(), tbl.columns(), tbl.colocationColumns());
        } catch (IllegalArgumentException e) {
            ctx.addIssue(new ValidationIssue("Validator works success by key " + ctx.currentKey() + ". Found " + newTable.columns().size() + " columns"));
        }
        validateDataRegion(oldTables == null ? null : oldTables.get(tableName), newTable, ctx);
        validateNamedListKeys(newTable, ctx);
    }
}
Also used : TableDefinitionImpl(org.apache.ignite.internal.schema.definition.TableDefinitionImpl) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue) TableView(org.apache.ignite.configuration.schemas.table.TableView)

Aggregations

TableDefinitionImpl (org.apache.ignite.internal.schema.definition.TableDefinitionImpl)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 TableView (org.apache.ignite.configuration.schemas.table.TableView)1 ValidationIssue (org.apache.ignite.configuration.validation.ValidationIssue)1 ColumnDefinition (org.apache.ignite.schema.definition.ColumnDefinition)1 PrimaryKeyDefinition (org.apache.ignite.schema.definition.PrimaryKeyDefinition)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