djkevincr commented on a change in pull request #156: GORA 411 - Add 
exists(key) to DataStore interface
URL: https://github.com/apache/gora/pull/156#discussion_r279664478
 
 

 ##########
 File path: 
gora-cassandra/src/main/java/org/apache/gora/cassandra/serializers/AvroSerializer.java
 ##########
 @@ -466,4 +466,25 @@ public Result execute(DataStore dataStore, Query query) 
throws GoraException {
     }
   }
 
+  @Override
+  public boolean exists(Object key) throws GoraException {
+    try {
+      ArrayList<String> cassandraKeys = new ArrayList<>();
+      ArrayList<Object> cassandraValues = new ArrayList<>();
+      AvroCassandraUtils.processKeys(mapping, key, cassandraKeys, 
cassandraValues);
+      String cqlQuery = CassandraQueryFactory.getCheckExistsQuery(mapping, 
cassandraKeys);
+      SimpleStatement statement = new SimpleStatement(cqlQuery, 
cassandraValues.toArray());
+      if (readConsistencyLevel != null) {
+        
statement.setConsistencyLevel(ConsistencyLevel.valueOf(readConsistencyLevel));
+      }
+      ResultSet resultSet = client.getSession().execute(statement);
+      Iterator<Row> iterator = resultSet.iterator();
+      Row next = iterator.next();
+      long aInt = next.getLong(0);
 
 Review comment:
   Isn't it enough to check whether row is null or not to check the existence 
of key?  
   ```long aInt = next.getLong(0); 
   ```
   Can you explain purpose behind retrieving this long value? 

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