jhnmora000 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_r280293088
########## 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: Hi Kevin. To be frank with you I am not an expert in Cassandra so I based this implementation on this stackoverflow [response](https://stackoverflow.com/a/34475402) . I will try the approach you mention and report back to you. ---------------------------------------------------------------- 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