ibessonov commented on code in PR #1172:
URL: https://github.com/apache/ignite-3/pull/1172#discussion_r989983565
##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/sorted/PageMemorySortedIndexStorage.java:
##########
@@ -120,26 +119,60 @@ public void remove(IndexRow row) {
@Override
public Cursor<IndexRow> scan(@Nullable BinaryTuplePrefix lowerBound,
@Nullable BinaryTuplePrefix upperBound, int flags) {
- Cursor<SortedIndexRow> cursor;
+ boolean includeLower = (flags & GREATER_OR_EQUAL) != 0;
+ boolean includeUpper = (flags & LESS_OR_EQUAL) != 0;
+
+ SortedIndexRowKey lower = createLowerBound(lowerBound, includeLower);
+
+ SortedIndexRowKey upper = createUpperBound(upperBound, includeUpper);
try {
- cursor = sortedIndexTree.find(
- toSortedIndexRowKey(lowerBound),
- toSortedIndexRowKey(upperBound),
- (flags & GREATER_OR_EQUAL) != 0,
- (flags & LESS_OR_EQUAL) != 0,
- null,
- null
- );
+ Cursor<SortedIndexRow> cursor = sortedIndexTree.find(lower, upper,
includeLower, includeUpper, null, null);
Review Comment:
Passing these flags is pointless I believe. Simple
`sortedIndexTree.find(lower, upper)` will give us the same result
##########
modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/impl/TestSortedIndexStorage.java:
##########
@@ -118,21 +114,31 @@ public Cursor<IndexRow> scan(
boolean includeLower = (flags & GREATER_OR_EQUAL) != 0;
boolean includeUpper = (flags & LESS_OR_EQUAL) != 0;
- Stream<Map.Entry<ByteBuffer, Set<RowId>>> data =
index.entrySet().stream();
-
- if (lowerBound != null) {
- ToIntFunction<ByteBuffer> lowerCmp = boundComparator(lowerBound,
includeLower ? 0 : -1);
-
- data = data.dropWhile(e -> lowerCmp.applyAsInt(e.getKey()) < 0);
+ if (!includeLower && lowerBound != null) {
+ setEqualityFlag(lowerBound);
}
- if (upperBound != null) {
- ToIntFunction<ByteBuffer> upperCmp = boundComparator(upperBound,
includeUpper ? 0 : 1);
+ if (includeUpper && upperBound != null) {
+ setEqualityFlag(upperBound);
+ }
- data = data.takeWhile(e -> upperCmp.applyAsInt(e.getKey()) <= 0);
+ SortedMap<ByteBuffer, Set<RowId>> data;
+
+ if (lowerBound == null && upperBound == null) {
+ data = index;
+ } else if (lowerBound == null) {
+ data = index.headMap(upperBound.byteBuffer());
+ } else if (upperBound == null) {
+ data = index.tailMap(lowerBound.byteBuffer());
+ } else {
+ try {
+ data = index.subMap(lowerBound.byteBuffer(),
upperBound.byteBuffer());
+ } catch (IllegalArgumentException e) {
Review Comment:
This is new for me, how can it happen?
--
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]