sanpwc commented on a change in pull request #121:
URL: https://github.com/apache/ignite-3/pull/121#discussion_r634122540



##########
File path: 
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/watch/KeyCriterion.java
##########
@@ -91,20 +109,106 @@ public RangeCriterion(Key from, Key to) {
         }
 
         /** {@inheritDoc} */
-        @Override public IgniteBiTuple<Key, Key> toRange() {
-            return new IgniteBiTuple<>(from, to);
+        @Override public boolean contains(Key key) {
+            return key.compareTo(from) >= 0 && key.compareTo(to) < 0;
+        }
+
+        /**
+         * Calculate range representation for prefix criterion
+         * as {@code (prefixKey, nextKey(prefixKey)) }.
+         *
+         * @param prefixKey prefix.
+         * @return calculated range
+         */
+        public static RangeCriterion fromPrefixKey(Key prefixKey) {
+            return new RangeCriterion(prefixKey, nextKey(prefixKey));
         }
 
         /** {@inheritDoc} */
-        @Override public boolean contains(Key key) {
-            return key.compareTo(from) >= 0 && key.compareTo(to) < 0;
+        @Override protected Optional<KeyCriterion> doUnion(KeyCriterion 
keyCriterion) {
+            Key from;
+            Key to;
+
+            if (keyCriterion instanceof ExactCriterion) {
+                from = ((ExactCriterion)keyCriterion).key;
+                to = nextKey(from);
+            }
+            else if (keyCriterion instanceof CollectionCriterion) {
+                from = 
Collections.min(((CollectionCriterion)keyCriterion).keys);
+                to = 
nextKey(Collections.max(((CollectionCriterion)keyCriterion).keys));
+            }
+            else if (keyCriterion instanceof RangeCriterion) {
+                from = ((RangeCriterion)keyCriterion).from;
+                to = ((RangeCriterion)keyCriterion).to;
+            }
+            else
+                return Optional.empty();

Review comment:
       As was mentioned above
   > be honest I don't like an idea of union ordering. Let's make it 
associative.
   I think we should rewrite doUnion() logic in order not to return empty 
result.




-- 
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]


Reply via email to