use of org.apache.ignite.configuration.schemas.table.ColumnView 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]);
}
use of org.apache.ignite.configuration.schemas.table.ColumnView 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);
}
use of org.apache.ignite.configuration.schemas.table.ColumnView in project ignite-3 by apache.
the class SchemaUtils method columnMapper.
/**
* Prepares column mapper.
*
* @param oldDesc Old schema descriptor.
* @param oldTbl Old table configuration.
* @param newDesc New schema descriptor.
* @param newTbl New table configuration.
* @return Column mapper.
*/
public static ColumnMapper columnMapper(SchemaDescriptor oldDesc, TableView oldTbl, SchemaDescriptor newDesc, TableChange newTbl) {
ColumnMapper mapper = null;
NamedListView<? extends ColumnView> newTblColumns = newTbl.columns();
NamedListView<? extends ColumnView> oldTblColumns = oldTbl.columns();
// because removed keys are simply replaced with nulls
assert newTblColumns.size() >= oldTblColumns.size();
for (int i = 0; i < newTblColumns.size(); ++i) {
ColumnView newColView = newTblColumns.get(i);
// new value can be null if a column has been deleted
if (newColView == null) {
continue;
}
if (i < oldTblColumns.size()) {
ColumnView oldColView = oldTblColumns.get(i);
Column newCol = newDesc.column(newColView.name());
Column oldCol = oldDesc.column(oldColView.name());
if (newCol.schemaIndex() == oldCol.schemaIndex()) {
continue;
}
if (mapper == null) {
mapper = ColumnMapping.createMapper(newDesc);
}
mapper.add(newCol.schemaIndex(), oldCol.schemaIndex());
} else {
// if the new Named List is larger than the old one, it can only mean that a new column has been added
Column newCol = newDesc.column(newColView.name());
assert !newDesc.isKeyColumn(newCol.schemaIndex());
if (mapper == null) {
mapper = ColumnMapping.createMapper(newDesc);
}
mapper.add(newCol);
}
}
// since newTblColumns comes from a TableChange, it will contain nulls for removed columns
Optional<Column> droppedKeyCol = newTblColumns.namedListKeys().stream().filter(k -> newTblColumns.get(k) == null).map(oldDesc::column).filter(c -> oldDesc.isKeyColumn(c.schemaIndex())).findAny();
// TODO: configuration validators.
assert droppedKeyCol.isEmpty() : IgniteStringFormatter.format("Dropping of key column is forbidden: [schemaVer={}, col={}]", newDesc.version(), droppedKeyCol.get());
return mapper == null ? ColumnMapping.identityMapping() : mapper;
}
use of org.apache.ignite.configuration.schemas.table.ColumnView in project ignite-3 by apache.
the class TableValidatorImpl method validateNamedListKeys.
/**
* Checks that columns and indices are stored under their names in the corresponding Named Lists, i.e. their Named List keys and names
* are the same.
*
* @param table Table configuration view.
* @param ctx Validation context.
*/
private static void validateNamedListKeys(TableView table, ValidationContext<NamedListView<TableView>> ctx) {
NamedListView<? extends ColumnView> columns = table.columns();
for (String key : columns.namedListKeys()) {
ColumnView column = columns.get(key);
if (!column.name().equals(key)) {
var issue = new ValidationIssue(String.format("Column name \"%s\" does not match its Named List key: \"%s\"", column.name(), key));
ctx.addIssue(issue);
}
}
NamedListView<? extends TableIndexView> indices = table.indices();
for (String key : indices.namedListKeys()) {
TableIndexView index = indices.get(key);
if (!index.name().equals(key)) {
var issue = new ValidationIssue(String.format("Index name \"%s\" does not match its Named List key: \"%s\"", index.name(), key));
ctx.addIssue(issue);
}
}
}
Aggregations