[ 
https://issues.apache.org/jira/browse/GORA-444?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16394565#comment-16394565
 ] 

Carlos Muñoz edited comment on GORA-444 at 3/12/18 3:12 AM:
------------------------------------------------------------

Hi [~lewismc],

I have been playing with Apache Gora as a preparation for my GoSC application 
in GORA-535 and I would like to tackle this issue because it is closely related 
to backends development. This is what I found so far.

The implementation of a size() function in the Result API would be 
straightforward in most of the backends because either they already have 
internal size variables or they use lists/sets to store results. These backend 
are:
|*Backend*|*Results list/size variable*|*Size() implementation*|
|[Aerospike|https://github.com/apache/gora/blob/master/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java]|List<AerospikeResultRecord>
 resultRecords;|resultRecords.size();|
|[Cassandra|https://github.com/apache/gora/blob/master/gora-cassandra/src/main/java/org/apache/gora/cassandra/query/CassandraResultSet.java]|int
 size|size;|
|[CouchDB|https://github.com/apache/gora/blob/master/gora-couchdb/src/main/java/org/apache/gora/couchdb/query/CouchDBResult.java]|List<Map>
 result;|result.size();|
|[DynamoDB|https://github.com/apache/gora/blob/master/gora-dynamodb/src/main/java/org/apache/gora/dynamodb/query/DynamoDBResult.java]|List<T>
 dynamoDBResultSet;|dynamoDBResultSet.size();|
|[Infinispan|https://github.com/apache/gora/blob/master/gora-infinispan/src/main/java/org/apache/gora/infinispan/query/InfinispanResult.java]|List<T>
 list;|size(); //already implemented|
|[JCache|https://github.com/apache/gora/blob/master/gora-jcache/src/main/java/org/apache/gora/jcache/query/JCacheResult.java]|NavigableSet<K>
 cacheKeySet;|cacheKeySet.size();|
|[MongoDB|https://github.com/apache/gora/blob/master/gora-mongodb/src/main/java/org/apache/gora/mongodb/query/MongoDBResult.java]|int
 size;|size;|
|[OrientDB|https://github.com/apache/gora/blob/master/gora-orientdb/src/main/java/org/apache/gora/orientdb/query/OrientDBResult.java]|int
 size;|size;|
|[Solr|https://github.com/apache/gora/blob/master/gora-solr/src/main/java/org/apache/gora/solr/query/SolrResult.java]|SolrDocumentList
 list;|list.size();|
|[Avro|https://github.com/apache/gora/blob/master/gora-core/src/main/java/org/apache/gora/avro/query/DataFileAvroResult.java]|long
 start;
 long end;|end-start;|

Other internal implementations:
|*Backend*|*Results list/size variable*|*Size() implementation*|
|[Mock|https://github.com/apache/gora/blob/master/gora-core/src/test/java/org/apache/gora/mock/store/MockDataStore.java]
 *Test|…|return 0;|
|[Mem|https://github.com/apache/gora/blob/master/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java]|NavigableMap<K,
 T> map;|return map.size();|

However, other backends rely on Scanners implementations which cannot provide 
size()-like functions due performance reasons. These backends are:
|*Backend*|*Data*|
|[Accumulo|https://github.com/apache/gora/blob/master/gora-accumulo/src/main/java/org/apache/gora/accumulo/query/AccumuloResult.java]|RowIterator
 iterator;|
|[HBase|https://github.com/apache/gora/blob/master/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseGetResult.java]|Result
 result;|
|[HBase|https://github.com/apache/gora/blob/master/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseScannerResult.java]|ResultScanner
 scanner;|
|[Avro|https://github.com/apache/gora/blob/master/gora-core/src/main/java/org/apache/gora/avro/query/AvroResult.java]|DatumReader<T>
 reader;|

For thoses backends we could use one of the following strategies:
 * Return a constant value such 0 or -1 (approach used by getProgress() 
implementation).
 * Throw an exception to indicate that the operation is not supported.
 * Use a duplicated Scanner just for counting how many next() could be 
performed (I know it is a very bad idea).


was (Author: carlosrmng):
Hi [~lewismc],

I have been playing with Apache Gora as a preparation for my GoSC application 
in GORA-535 and I would like to tackle this issue because it is closely related 
to backends development. This is what I found so far.

The implementation of a size() function in the Result API would be 
straightforward in most of the backends because either they already have 
internal size variables or they use lists/sets to store results. These backend 
are:
|*Backend*|*Results list/size variable*|*Size() implementation*|
|[Aerospike|https://github.com/apache/gora/blob/master/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java]|List<AerospikeResultRecord>
 resultRecords;|resultRecords.size();|
|[Cassandra|https://github.com/apache/gora/blob/master/gora-cassandra/src/main/java/org/apache/gora/cassandra/query/CassandraResultSet.java]|int
 size|size;|
|[CouchDB|https://github.com/apache/gora/blob/master/gora-couchdb/src/main/java/org/apache/gora/couchdb/query/CouchDBResult.java]|List<Map>
 result;|result.size();|
|[DynamoDB|https://github.com/apache/gora/blob/master/gora-dynamodb/src/main/java/org/apache/gora/dynamodb/query/DynamoDBResult.java]|List<T>
 dynamoDBResultSet;|dynamoDBResultSet.size();|
|[Infinispan|https://github.com/apache/gora/blob/master/gora-infinispan/src/main/java/org/apache/gora/infinispan/query/InfinispanResult.java]|List<T>
 list;|size(); //already implemented|
|[JCache|https://github.com/apache/gora/blob/master/gora-jcache/src/main/java/org/apache/gora/jcache/query/JCacheResult.java]|NavigableSet<K>
 cacheKeySet;|cacheKeySet.size();|
|[MongoDB|https://github.com/apache/gora/blob/master/gora-mongodb/src/main/java/org/apache/gora/mongodb/query/MongoDBResult.java]|int
 size;|size;|
|[OrientDB|https://github.com/apache/gora/blob/master/gora-orientdb/src/main/java/org/apache/gora/orientdb/query/OrientDBResult.java]|int
 size;|size;|
|[Solr|https://github.com/apache/gora/blob/master/gora-solr/src/main/java/org/apache/gora/solr/query/SolrResult.java]|SolrDocumentList
 list;|list.size();|
|[Avro|https://github.com/apache/gora/blob/master/gora-core/src/main/java/org/apache/gora/avro/query/DataFileAvroResult.java]|long
 start;
 long end;|end-start;|

Other internal implementations:
|*Backend*|*Results list/size variable*|*Size() implementation*|
|[Mock|https://github.com/apache/gora/blob/master/gora-core/src/test/java/org/apache/gora/mock/store/MockDataStore.java]
 *Test|…|return 0;|
|[Mem|https://github.com/apache/gora/blob/master/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java]|NavigableMap<K,
 T> map;|return map.size();|

However, other backends rely on Scanners implementations which cannot provide 
size()-like functions for performance reasons. These backends are:
|*Backend*|*Data*|
|[Accumulo|https://github.com/apache/gora/blob/master/gora-accumulo/src/main/java/org/apache/gora/accumulo/query/AccumuloResult.java]|RowIterator
 iterator;|
|[HBase|https://github.com/apache/gora/blob/master/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseGetResult.java]|Result
 result;|
|[HBase|https://github.com/apache/gora/blob/master/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseScannerResult.java]|ResultScanner
 scanner;|
|[Avro|https://github.com/apache/gora/blob/master/gora-core/src/main/java/org/apache/gora/avro/query/AvroResult.java]|DatumReader<T>
 reader;|

For thoses backends we could use one of the following strategies:
 * Return a constant value such 0 or -1 (approach used by getProgress() 
implementation).
 * Throw an exception to indicate that the operation is not supported.
 * Use a duplicated Scanner just for counting how many next() could be 
performed (I know it is a very bad idea).

> Add #size() to Result API
> -------------------------
>
>                 Key: GORA-444
>                 URL: https://issues.apache.org/jira/browse/GORA-444
>             Project: Apache Gora
>          Issue Type: New Feature
>          Components: gora-core
>            Reporter: Lewis John McGibbney
>            Priority: Minor
>             Fix For: 0.9
>
>
> Right now we iterate through results by doing 
> {code}
> while (results.next()) {
>    ...
> }
> {code}
> It is a pain to always require a counter of sorts and would be much more 
> intuitive to provide a simple #size() method.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to