sashapolo commented on a change in pull request #468: URL: https://github.com/apache/ignite-3/pull/468#discussion_r766745047
########## File path: modules/storage-api/src/main/java/org/apache/ignite/internal/storage/index/SortedIndexDescriptor.java ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.storage.index; + +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toUnmodifiableList; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Stream; +import org.apache.ignite.configuration.NamedListView; +import org.apache.ignite.configuration.schemas.table.ColumnView; +import org.apache.ignite.configuration.schemas.table.IndexColumnView; +import org.apache.ignite.configuration.schemas.table.SortedIndexView; +import org.apache.ignite.configuration.schemas.table.TableIndexView; +import org.apache.ignite.configuration.schemas.table.TableView; +import org.apache.ignite.internal.schema.Column; +import org.apache.ignite.internal.schema.SchemaDescriptor; +import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter; +import org.apache.ignite.internal.schema.configuration.SchemaDescriptorConverter; +import org.apache.ignite.internal.storage.StorageException; +import org.apache.ignite.schema.definition.ColumnDefinition; + +/** + * Descriptor for creating a Sorted Index Storage. + * + * @see SortedIndexStorage + */ +public class SortedIndexDescriptor { + /** + * Descriptor of a Sorted Index column (column name and column sort order). + */ + public static class ColumnDescriptor { + private final Column column; + + private final boolean asc; + + private final boolean indexedColumn; + + ColumnDescriptor(Column column, boolean asc, boolean indexedColumn) { + this.column = column; + this.asc = asc; + this.indexedColumn = indexedColumn; + } + + /** + * Returns a column descriptor. + */ + public Column column() { + return column; + } + + /** + * Returns {@code true} if this column is sorted in ascending order or {@code false} otherwise. + */ + public boolean asc() { + return asc; + } + + /** + * Returns {@code true} if this column was explicitly marked as an indexed column or {@code false} if it is a part of a Primary Key + * appended for uniqueness. + */ + public boolean indexedColumn() { + return indexedColumn; + } + + @Override + public String toString() { + return "ColumnDescriptor{" + + "name=" + column.name() + + ", type=" + column.type().spec() + + ", asc=" + asc + + ", indexedColumn=" + indexedColumn + + '}'; + } + } + + private final String name; + + private final List<ColumnDescriptor> columns; + + private final SchemaDescriptor schemaDescriptor; + + /** + * Creates an Index Descriptor from a given Table Configuration. + * + * @param name index name. + * @param tableConfig table configuration. + */ + public SortedIndexDescriptor(String name, TableView tableConfig) { + this.name = name; + + TableIndexView indexConfig = tableConfig.indices().get(name); + + if (indexConfig == null) { + throw new StorageException(String.format("Index configuration for \"%s\" could not be found", name)); + } + + if (!(indexConfig instanceof SortedIndexView)) { + throw new StorageException(String.format( + "Index \"%s\" is not configured as a Sorted Index. Actual type: %s", + name, indexConfig.type() + )); + } + + // extract indexed column configurations from the table configuration + NamedListView<? extends IndexColumnView> indexColumns = ((SortedIndexView) indexConfig).columns(); + + Stream<String> indexColumnNames = indexColumns.namedListKeys().stream() Review comment: ok, I got it, nice catch -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
