You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/12/08 14:31:11 UTC

[GitHub] [ignite-3] tledkov-gridgain commented on a change in pull request #468: IGNITE-15885 Implement RocksDB-based Sorted Index Storage

tledkov-gridgain commented on a change in pull request #468:
URL: https://github.com/apache/ignite-3/pull/468#discussion_r764917141



##########
File path: modules/storage-api/src/main/java/org/apache/ignite/internal/storage/index/SortedIndexStorage.java
##########
@@ -0,0 +1,66 @@
+/*
+ * 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 org.apache.ignite.internal.storage.SearchRow;
+import org.apache.ignite.internal.util.Cursor;
+
+/**
+ * Storage for a Sorted Index.
+ *
+ * <p>This storage serves as a sorted mapping from a subset of a table's columns (a.k.a. index columns) to a {@link SearchRow}
+ * from a {@link org.apache.ignite.internal.storage.PartitionStorage} from the same table.
+ *
+ * @see org.apache.ignite.schema.definition.index.SortedIndexDefinition
+ */
+public interface SortedIndexStorage extends AutoCloseable {
+    /**
+     * Returns a factory for creating index keys for this storage.
+     */
+    IndexKeyFactory indexKeyFactory();
+
+    /**
+     * Returns the Index Descriptor of this storage.
+     */
+    SortedIndexDescriptor indexDescriptor();
+
+    /**
+     * Adds the given index key and {@link SearchRow} to the index.
+     *
+     * <p>Putting a new value under the same key will overwrite the previous associated value.
+     */
+    void put(IndexKey key, SearchRow value);
+
+    /**
+     * Removes the given key from the index.
+     *
+     * <p>Removing a non-existent key is a no-op.
+     */
+    void remove(IndexKey key);
+
+    /**
+     * Returns a range of index values between the lower bound (inclusive) and the upper bound (inclusive).
+     */
+    // TODO: add options https://issues.apache.org/jira/browse/IGNITE-16059
+    Cursor<SearchRow> range(IndexKeyPrefix lowerBound, IndexKeyPrefix upperBound);

Review comment:
       @AMashenkov i'm OK with proposal while we don't use value of the Rocks DB for sorted storage.
   We have to change the interface in the future.

##########
File path: modules/storage-api/src/main/java/org/apache/ignite/internal/storage/index/SortedIndexDescriptor.java
##########
@@ -0,0 +1,162 @@
+/*
+ * 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 java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+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.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;
+
+        ColumnDescriptor(Column column, boolean asc) {
+            this.column = column;
+            this.asc = asc;
+        }
+
+        public Column column() {
+            return column;
+        }
+
+        public boolean asc() {
+            return asc;
+        }
+    }
+
+    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;
+
+        SortedIndexView indexConfig = (SortedIndexView) 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 = indexConfig.columns();
+
+        Stream<String> indexColumnNames = indexColumns.namedListKeys().stream()
+                .map(indexColumns::get)
+                .map(IndexColumnView::name);
+
+        // append the primary key to guarantee index key uniqueness
+        Stream<String> primaryKeyColumnNames = Arrays.stream(tableConfig.primaryKey().columns());
+
+        List<ColumnView> indexKeyColumnViews = Stream.concat(indexColumnNames, primaryKeyColumnNames)
+                .distinct() // remove Primary Key columns if they are already present in the index definition

Review comment:
       Should we use ordered stream here to preserve order of the columns? 




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org