cuent commented on a change in pull request #186: [GORA-527] Implement a data 
store for redis
URL: https://github.com/apache/gora/pull/186#discussion_r316485046
 
 

 ##########
 File path: 
gora-redis/src/main/java/org/apache/gora/redis/query/RedisResult.java
 ##########
 @@ -0,0 +1,111 @@
+/**
+ * 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.gora.redis.query;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import org.apache.gora.persistency.impl.PersistentBase;
+import org.apache.gora.query.Query;
+import org.apache.gora.query.impl.ResultBase;
+import org.apache.gora.redis.store.RedisStore;
+import org.apache.gora.store.DataStore;
+
+/**
+ * Redis specific implementation of the {@link org.apache.gora.query.Result}
+ * interface.
+ */
+public class RedisResult<K, T extends PersistentBase> extends ResultBase<K, T> 
{
+
+  private Iterator<String> range;
+  private final int size;
+
+  /**
+   * Gets the data store used
+   *
+   * @return
+   */
+  @Override
+  public RedisStore<K, T> getDataStore() {
+    return (RedisStore<K, T>) super.getDataStore();
+  }
+
+  /**
+   * @param dataStore
+   * @param query
+   * @param rg
+   */
+  public RedisResult(DataStore<K, T> dataStore, Query<K, T> query, 
Collection<String> rg) {//, Scanner scanner) {
+    super(dataStore, query);
+    this.size = rg.size();
+    this.range = rg.iterator();
+  }
+
+  /**
+   * Gets the items reading progress
+   *
+   * @return
+   * @throws java.io.IOException
+   */
+  @Override
+  public float getProgress() throws IOException {
+    if (this.limit != -1) {
+      return (float) this.offset / (float) this.limit;
+    } else {
+      return 0;
+    }
+  }
+
+  @Override
+  public void close() throws IOException {
+  }
+
+  /**
+   * Gets the next item
+   *
+   * @return
+   * @throws java.io.IOException
+   */
+  @Override
+  protected boolean nextInner() throws IOException {
+    if (range == null) {
+      return false;
+    }
+    boolean next = range.hasNext();
+    if (next) {
+      String nextkey = range.next();
+      key = (K) nextkey;
 
 Review comment:
   Redis mainly supports two types of search by rank (Necessary for the 
implementation of queries in Gora).
   
   Details: https://redis.io/topics/indexes
   
   1) Lexicographical indexes
   Using LexSortedSet that only supports searches by String ranges
   
   2) Simple numerical indexes with sorted sets
   Using ScoredSortedList, search using a numeric score.
   
   
   For simplicity, only support for the first type of index was added.
   But to improve the code support for the second was added.
   Under the following rules:
   
   If the class of the Gora Key is of some type of numerical data (Long, Int, 
...) the type of indexes 2) is used.
   If the Gora Key class is of another type (String or other) the keys are cast 
as String and index 1) is used.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to