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_r280293499
########## 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: As per the explanation by @carlosrmng, I also think this is okay :) Now only I noticed you used count in queries. ---------------------------------------------------------------- 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