korlov42 commented on a change in pull request #8490: URL: https://github.com/apache/ignite/pull/8490#discussion_r567406515
########## File path: modules/core/src/main/java/org/apache/ignite/cache/query/index/Index.java ########## @@ -0,0 +1,83 @@ +/* + * 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.cache.query.index; + +import java.util.UUID; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; +import org.jetbrains.annotations.Nullable; + +/** + * Basic interface for Ignite indexes. + */ +public interface Index { + /** + * Unique ID. + */ + public UUID id(); + + /** + * Index name. + */ + public String name(); + + /** + * Checks whether index handles specified cache row. + * + * @param row Cache row. + * @return Whether index handles specified cache row + */ + public boolean belongsToIndex(CacheDataRow row) throws IgniteCheckedException; Review comment: Personally I'd prefer to rename it to 'indexesRow' or something like this, because right now it sounds like 'Index belongs to index' and row is passed as param. ########## File path: modules/core/src/main/java/org/apache/ignite/cache/query/index/Index.java ########## @@ -0,0 +1,83 @@ +/* + * 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.cache.query.index; + +import java.util.UUID; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; +import org.jetbrains.annotations.Nullable; + +/** + * Basic interface for Ignite indexes. + */ +public interface Index { + /** + * Unique ID. + */ + public UUID id(); + + /** + * Index name. + */ + public String name(); + + /** + * Checks whether index handles specified cache row. + * + * @param row Cache row. + * @return Whether index handles specified cache row + */ + public boolean belongsToIndex(CacheDataRow row) throws IgniteCheckedException; + + /** + * Callback that runs when the underlying cache is updated. + * + * @param oldRow Cache row that was replaced with newRow. + * @param newRow Cache row that was stored. + * @param prevRowAvailable Whether oldRow available. + */ + public void onUpdate(@Nullable CacheDataRow oldRow, @Nullable CacheDataRow newRow, boolean prevRowAvailable) + throws IgniteCheckedException; + + /** + * Put cache row to index. + * + * @return {@code True} if replaced existing row. + */ + public boolean putx(CacheDataRow row) throws IgniteCheckedException; Review comment: why you decided to add a '-x' suffix to method name? Currently `InlineIndexImpl` has two `putx` methods and no 'put'. I'd prefer to name it just `put` ########## File path: modules/core/src/main/java/org/apache/ignite/cache/query/index/sorted/SortedIndex.java ########## @@ -0,0 +1,94 @@ +/* + * 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.cache.query.index.sorted; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.query.index.Index; +import org.apache.ignite.internal.cache.query.index.sorted.inline.io.IndexSearchRow; +import org.apache.ignite.internal.util.lang.GridCursor; +import org.apache.ignite.spi.indexing.IndexingQueryFilter; +import org.jetbrains.annotations.Nullable; + +/** + * Interface for sorted Ignite indexes. + */ +public interface SortedIndex extends Index { + /** + * Finds index rows by specified range in specifed tree segment. Range can be bound or unbound. + * + * @param lower Nullable lower bound. + * @param upper Nullable upper bound. + * @param segment Number of tree segment to find. + * @return Cursor of found index rows. + */ + public GridCursor<IndexSearchRow> find(@Nullable IndexKey lower, @Nullable IndexKey upper, int segment) throws IgniteCheckedException; + + /** + * Finds index rows by specified range in specifed tree segment with cache filtering. Range can be bound or unbound. + * + * @param lower Nullable lower bound. + * @param upper Nullable upper bound. + * @param segment Number of tree segment to find. + * @param filter Cache entry filter. + * @return Cursor of found index rows. + */ + public GridCursor<IndexSearchRow> find(IndexKey lower, IndexKey upper, int segment, IndexingQueryFilter filter) + throws IgniteCheckedException; + + /** + * Finds first or last index row for specified tree segment and cache filter. + * + * @param firstOrLast if {@code true} then return first index row or otherwise last row. + * @param segment Number of tree segment to find. + * @param filter Cache entry filter. + * @return Cursor of found index rows. + */ + public GridCursor<IndexSearchRow> findFirstOrLast(boolean firstOrLast, int segment, IndexingQueryFilter filter) + throws IgniteCheckedException; + + /** + * Counts index rows in specified tree segment. + * + * @param segment Number of tree segment to find. + * @return count of index rows for specified segment. + */ + public long count(int segment) throws IgniteCheckedException; + + /** + * Counts index rows in specified tree segment with cache filter. + * + * @param segment Number of tree segment to find. + * @param filter Cache entry filter. + * @return count of index rows for specified segment. + */ + public long count(int segment, IndexingQueryFilter filter) throws IgniteCheckedException; + + /** + * Counts index rows for all segments. + * + * @return total count of index rows. + */ + public long totalCount() throws IgniteCheckedException; + + /** + * Returns amount of index tree segments. + * + * @return amount of index tree segments. + */ + public int segmentsCount(); Review comment: actually segments has nothing common with a generic sorted index, thus it would be better to introduce one more abstraction like SegmentedIndex ########## File path: modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexKeyDefinition.java ########## @@ -0,0 +1,65 @@ +/* + * 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.cache.query.index.sorted; + +import org.apache.ignite.cache.query.index.sorted.Order; + +/** + * Defines a signle index key. + */ +public class IndexKeyDefinition { + /** Index key name. */ + private final String name; + + /** Index key type. @see IndexKeyTypes. */ Review comment: please format this like a proper javadoc link ########## File path: modules/core/src/main/java/org/apache/ignite/cache/query/index/sorted/Order.java ########## @@ -0,0 +1,49 @@ +/* + * 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.cache.query.index.sorted; + +/** + * Represents ordering of rows within sorted index. + */ +public class Order { + /** */ + private NullsOrder nullsOrder; + + /** */ + private SortOrder sortOrder; Review comment: let's make these fields final ########## File path: modules/core/src/main/java/org/apache/ignite/cache/query/index/SingleCursor.java ########## @@ -0,0 +1,52 @@ +/* + * 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.cache.query.index; + +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.util.lang.GridCursor; + +/** + * Cursor that holds single value only. + * @param <T> class of value to return. + */ +public class SingleCursor<T> implements GridCursor<T> { + /** Value to return */ + private final T val; + + /** Counter ot check wherther value is already got. */ + private final AtomicInteger currIdx = new AtomicInteger(-1); + + /** */ + public SingleCursor(T val) { + this.val = val; + } + + /** {@inheritDoc} */ + @Override public boolean next() { + return currIdx.incrementAndGet() == 0; + } + + /** {@inheritDoc} */ + @Override public T get() throws IgniteCheckedException { + if (currIdx.get() <= 0) Review comment: This should be strong equality, otherwise it violates the "single value" contract. ########## File path: modules/core/src/main/java/org/apache/ignite/cache/query/index/IndexName.java ########## @@ -0,0 +1,92 @@ +/* + * 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.cache.query.index; + +import java.io.Serializable; +import org.jetbrains.annotations.Nullable; + +/** + * Represents list of names that fully describes index domain (schema, cache, table, index). + */ +public class IndexName implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** Schema name of {@code null} if index is not related to SQL schema. */ + private final @Nullable String schemaName; + + /** Schema name of {@code null} if index is not related to SQL table. */ + private final @Nullable String tableName; + + /** Cache name. */ + private final String cacheName; + + /** Index name. */ + private final String idxName; + + /** */ + public IndexName(String cacheName, @Nullable String schemaName, @Nullable String tableName, String idxName) { + this.cacheName = cacheName; + this.schemaName = schemaName; + this.tableName = tableName; + this.idxName = idxName; + } + + /** + * @return FQDN index name. + */ + public String fqdnIdxName() { Review comment: let's rename it to `fullName` ########## File path: modules/core/src/main/java/org/apache/ignite/cache/query/index/sorted/SortedIndex.java ########## @@ -0,0 +1,94 @@ +/* + * 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.cache.query.index.sorted; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.query.index.Index; +import org.apache.ignite.internal.cache.query.index.sorted.inline.io.IndexSearchRow; +import org.apache.ignite.internal.util.lang.GridCursor; +import org.apache.ignite.spi.indexing.IndexingQueryFilter; +import org.jetbrains.annotations.Nullable; + +/** + * Interface for sorted Ignite indexes. + */ +public interface SortedIndex extends Index { + /** + * Finds index rows by specified range in specifed tree segment. Range can be bound or unbound. + * + * @param lower Nullable lower bound. + * @param upper Nullable upper bound. + * @param segment Number of tree segment to find. + * @return Cursor of found index rows. + */ + public GridCursor<IndexSearchRow> find(@Nullable IndexKey lower, @Nullable IndexKey upper, int segment) throws IgniteCheckedException; + + /** + * Finds index rows by specified range in specifed tree segment with cache filtering. Range can be bound or unbound. + * + * @param lower Nullable lower bound. + * @param upper Nullable upper bound. + * @param segment Number of tree segment to find. + * @param filter Cache entry filter. + * @return Cursor of found index rows. + */ + public GridCursor<IndexSearchRow> find(IndexKey lower, IndexKey upper, int segment, IndexingQueryFilter filter) + throws IgniteCheckedException; + + /** + * Finds first or last index row for specified tree segment and cache filter. + * + * @param firstOrLast if {@code true} then return first index row or otherwise last row. + * @param segment Number of tree segment to find. + * @param filter Cache entry filter. + * @return Cursor of found index rows. + */ + public GridCursor<IndexSearchRow> findFirstOrLast(boolean firstOrLast, int segment, IndexingQueryFilter filter) Review comment: let's split it on two separate methods ########## File path: modules/core/src/main/java/org/apache/ignite/cache/query/index/IndexName.java ########## @@ -0,0 +1,92 @@ +/* + * 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.cache.query.index; + +import java.io.Serializable; +import org.jetbrains.annotations.Nullable; + +/** + * Represents list of names that fully describes index domain (schema, cache, table, index). + */ +public class IndexName implements Serializable { Review comment: Looks kinda cumbersome. Actually a tuple (schemaName, indexName) describes an index uniquely. Table name has nothing common with indexName. And for non-SQL indexes a cache name could be used for schemaName ########## File path: modules/core/src/main/java/org/apache/ignite/cache/query/index/sorted/IndexKey.java ########## @@ -0,0 +1,36 @@ +/* + * 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.cache.query.index.sorted; + +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; +import org.jetbrains.annotations.Nullable; + +/** + * Represents a complex index key. + */ +public interface IndexKey { Review comment: The purpose of this entity is unclear to me. Right now it's just a straitforward replacement of H2's SearchRow, but then it should not have a link to CacheDataRow ########## File path: modules/core/src/main/java/org/apache/ignite/cache/query/index/AbstractIndex.java ########## @@ -15,25 +15,31 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.query.h2.database.inlinecolumn; +package org.apache.ignite.cache.query.index; -import org.h2.table.Column; -import org.h2.value.Value; -import org.h2.value.ValueStringIgnoreCase; +import java.util.concurrent.atomic.AtomicBoolean; + +import static java.lang.Boolean.FALSE; +import static java.lang.Boolean.TRUE; /** - * Inline index column implementation for inlining strings ignore case. + * Abstract class for all Index implementations. */ -public class StringIgnoreCaseInlineIndexColumn extends StringInlineIndexColumn { +public abstract class AbstractIndex implements Index { Review comment: Don't think we need this abstraction right now because only one index implementation extends this. ########## File path: modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexValueCursor.java ########## @@ -0,0 +1,67 @@ +/* + * 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.cache.query.index.sorted; + +import java.util.function.Function; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.cache.query.index.sorted.inline.io.IndexSearchRow; +import org.apache.ignite.internal.util.lang.GridCursor; + +/** + * Cursor over index values. + * + * @param <V> class represents of value stored in an index. + */ +public class IndexValueCursor<V> implements GridCursor<V> { + /** + * Empty cursor implementation. + */ + public static final GridCursor EMPTY = new GridCursor() { + /** {@inheritDoc} */ + @Override public boolean next() { + return false; + } + + /** {@inheritDoc} */ + @Override public Object get() { + return null; Review comment: it's better to throw exception here ########## File path: modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/SortedIndexSchema.java ########## @@ -15,25 +15,40 @@ * limitations under the License. */ -package org.apache.ignite.internal.processors.query.h2.database.inlinecolumn; +package org.apache.ignite.internal.cache.query.index.sorted; -import org.h2.table.Column; -import org.h2.value.Value; -import org.h2.value.ValueStringFixed; +import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; /** - * Inline index column implementation for inlining strings of fixed length. + * Schema for sorted index. */ -public class FixedStringInlineIndexColumn extends StringInlineIndexColumn { +public interface SortedIndexSchema { /** - * @param col Column. + * Describe all index keys. */ - public FixedStringInlineIndexColumn(Column col, boolean useOptimizedCompare) { - super(col, Value.STRING_FIXED, useOptimizedCompare, false); - } + public IndexKeyDefinition[] getKeyDefinitions(); Review comment: IndexKeyDefinition array should be part of IndexDefinition. Other fields have nothing common with scheme of a sorted index ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
