@Test public void testReadSingleColumn() throws Exception { insertRow(); final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>(); final Set<String> fields = Sets.newHashSet("field1"); final Status status = client.read(TABLE, DEFAULT_ROW_KEY, fields, result); assertThat(status, is(Status.OK)); assertThat(result.entrySet(), hasSize(1)); final Map<String, String> strResult = StringByteIterator.getStringMap(result); assertThat(strResult, hasEntry("field1", "value2")); }
@Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { PreparedStatement stmt = (fields == null) ? readAllStmt.get() : readStmts.get(fields); if (stmt == null) { Select.Builder selectBuilder; if (fields == null) { selectBuilder = QueryBuilder.select().all(); } else { selectBuilder = QueryBuilder.select(); for (String col : fields) { ((Select.Selection) selectBuilder).column(col); } } stmt = session.prepare(selectBuilder.from(table) .where(QueryBuilder.eq(YCSB_KEY, QueryBuilder.bindMarker())) .limit(1)); stmt.setConsistencyLevel(readConsistencyLevel); if (trace) { stmt.enableTracing(); } PreparedStatement prevStmt = (fields == null) ? readAllStmt.getAndSet(stmt) : readStmts.putIfAbsent(new HashSet(fields), stmt); if (prevStmt != null) { stmt = prevStmt; } } logger.debug(stmt.getQueryString()); logger.debug("key = {}", key); ResultSet rs = session.execute(stmt.bind(key)); if (rs.isExhausted()) { return Status.NOT_FOUND; } Row row = rs.one(); ColumnDefinitions cd = row.getColumnDefinitions(); for (ColumnDefinitions.Definition def : cd) { ByteBuffer val = row.getBytesUnsafe(def.getName()); if (val != null) { result.put(def.getName(), new ByteArrayByteIterator(val.array())); } else { result.put(def.getName(), null); } } return Status.OK; } catch (Exception e) { logger.error(MessageFormatter.format("Error reading key: {}", key).getMessage(), e); return Status.ERROR; } }
CassandraCQLClient extends DB { @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { PreparedStatement stmt = (fields == null) ? readAllStmt.get() : readStmts.get(fields); if (stmt == null) { Select.Builder selectBuilder; if (fields == null) { selectBuilder = QueryBuilder.select().all(); } else { selectBuilder = QueryBuilder.select(); for (String col : fields) { ((Select.Selection) selectBuilder).column(col); } } stmt = session.prepare(selectBuilder.from(table) .where(QueryBuilder.eq(YCSB_KEY, QueryBuilder.bindMarker())) .limit(1)); stmt.setConsistencyLevel(readConsistencyLevel); if (trace) { stmt.enableTracing(); } PreparedStatement prevStmt = (fields == null) ? readAllStmt.getAndSet(stmt) : readStmts.putIfAbsent(new HashSet(fields), stmt); if (prevStmt != null) { stmt = prevStmt; } } logger.debug(stmt.getQueryString()); logger.debug("key = {}", key); ResultSet rs = session.execute(stmt.bind(key)); if (rs.isExhausted()) { return Status.NOT_FOUND; } Row row = rs.one(); ColumnDefinitions cd = row.getColumnDefinitions(); for (ColumnDefinitions.Definition def : cd) { ByteBuffer val = row.getBytesUnsafe(def.getName()); if (val != null) { result.put(def.getName(), new ByteArrayByteIterator(val.array())); } else { result.put(def.getName(), null); } } return Status.OK; } catch (Exception e) { logger.error(MessageFormatter.format("Error reading key: {}", key).getMessage(), e); return Status.ERROR; } } }
CassandraCQLClient extends DB { @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { PreparedStatement stmt = (fields == null) ? readAllStmt.get() : readStmts.get(fields); if (stmt == null) { Select.Builder selectBuilder; if (fields == null) { selectBuilder = QueryBuilder.select().all(); } else { selectBuilder = QueryBuilder.select(); for (String col : fields) { ((Select.Selection) selectBuilder).column(col); } } stmt = session.prepare(selectBuilder.from(table) .where(QueryBuilder.eq(YCSB_KEY, QueryBuilder.bindMarker())) .limit(1)); stmt.setConsistencyLevel(readConsistencyLevel); if (trace) { stmt.enableTracing(); } PreparedStatement prevStmt = (fields == null) ? readAllStmt.getAndSet(stmt) : readStmts.putIfAbsent(new HashSet(fields), stmt); if (prevStmt != null) { stmt = prevStmt; } } logger.debug(stmt.getQueryString()); logger.debug("key = {}", key); ResultSet rs = session.execute(stmt.bind(key)); if (rs.isExhausted()) { return Status.NOT_FOUND; } Row row = rs.one(); ColumnDefinitions cd = row.getColumnDefinitions(); for (ColumnDefinitions.Definition def : cd) { ByteBuffer val = row.getBytesUnsafe(def.getName()); if (val != null) { result.put(def.getName(), new ByteArrayByteIterator(val.array())); } else { result.put(def.getName(), null); } } return Status.OK; } catch (Exception e) { logger.error(MessageFormatter.format("Error reading key: {}", key).getMessage(), e); return Status.ERROR; } }  }
CassandraCQLClient extends DB { @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { PreparedStatement stmt = (fields == null) ? readAllStmt.get() : readStmts.get(fields); if (stmt == null) { Select.Builder selectBuilder; if (fields == null) { selectBuilder = QueryBuilder.select().all(); } else { selectBuilder = QueryBuilder.select(); for (String col : fields) { ((Select.Selection) selectBuilder).column(col); } } stmt = session.prepare(selectBuilder.from(table) .where(QueryBuilder.eq(YCSB_KEY, QueryBuilder.bindMarker())) .limit(1)); stmt.setConsistencyLevel(readConsistencyLevel); if (trace) { stmt.enableTracing(); } PreparedStatement prevStmt = (fields == null) ? readAllStmt.getAndSet(stmt) : readStmts.putIfAbsent(new HashSet(fields), stmt); if (prevStmt != null) { stmt = prevStmt; } } logger.debug(stmt.getQueryString()); logger.debug("key = {}", key); ResultSet rs = session.execute(stmt.bind(key)); if (rs.isExhausted()) { return Status.NOT_FOUND; } Row row = rs.one(); ColumnDefinitions cd = row.getColumnDefinitions(); for (ColumnDefinitions.Definition def : cd) { ByteBuffer val = row.getBytesUnsafe(def.getName()); if (val != null) { result.put(def.getName(), new ByteArrayByteIterator(val.array())); } else { result.put(def.getName(), null); } } return Status.OK; } catch (Exception e) { logger.error(MessageFormatter.format("Error reading key: {}", key).getMessage(), e); return Status.ERROR; } }  @Override void init(); @Override void cleanup(); @Override Status read(String table, String key, Set<String> fields,
      Map<String, ByteIterator> result); @Override Status scan(String table, String startkey, int recordcount,
      Set<String> fields, Vector<HashMap<String, ByteIterator>> result); @Override Status update(String table, String key, Map<String, ByteIterator> values); @Override Status insert(String table, String key, Map<String, ByteIterator> values); @Override Status delete(String table, String key); }
CassandraCQLClient extends DB { @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { PreparedStatement stmt = (fields == null) ? readAllStmt.get() : readStmts.get(fields); if (stmt == null) { Select.Builder selectBuilder; if (fields == null) { selectBuilder = QueryBuilder.select().all(); } else { selectBuilder = QueryBuilder.select(); for (String col : fields) { ((Select.Selection) selectBuilder).column(col); } } stmt = session.prepare(selectBuilder.from(table) .where(QueryBuilder.eq(YCSB_KEY, QueryBuilder.bindMarker())) .limit(1)); stmt.setConsistencyLevel(readConsistencyLevel); if (trace) { stmt.enableTracing(); } PreparedStatement prevStmt = (fields == null) ? readAllStmt.getAndSet(stmt) : readStmts.putIfAbsent(new HashSet(fields), stmt); if (prevStmt != null) { stmt = prevStmt; } } logger.debug(stmt.getQueryString()); logger.debug("key = {}", key); ResultSet rs = session.execute(stmt.bind(key)); if (rs.isExhausted()) { return Status.NOT_FOUND; } Row row = rs.one(); ColumnDefinitions cd = row.getColumnDefinitions(); for (ColumnDefinitions.Definition def : cd) { ByteBuffer val = row.getBytesUnsafe(def.getName()); if (val != null) { result.put(def.getName(), new ByteArrayByteIterator(val.array())); } else { result.put(def.getName(), null); } } return Status.OK; } catch (Exception e) { logger.error(MessageFormatter.format("Error reading key: {}", key).getMessage(), e); return Status.ERROR; } }  @Override void init(); @Override void cleanup(); @Override Status read(String table, String key, Set<String> fields,
      Map<String, ByteIterator> result); @Override Status scan(String table, String startkey, int recordcount,
      Set<String> fields, Vector<HashMap<String, ByteIterator>> result); @Override Status update(String table, String key, Map<String, ByteIterator> values); @Override Status insert(String table, String key, Map<String, ByteIterator> values); @Override Status delete(String table, String key); static final String YCSB_KEY; static final String KEYSPACE_PROPERTY; static final String KEYSPACE_PROPERTY_DEFAULT; static final String USERNAME_PROPERTY; static final String PASSWORD_PROPERTY; static final String HOSTS_PROPERTY; static final String PORT_PROPERTY; static final String PORT_PROPERTY_DEFAULT; static final String READ_CONSISTENCY_LEVEL_PROPERTY; static final String READ_CONSISTENCY_LEVEL_PROPERTY_DEFAULT; static final String WRITE_CONSISTENCY_LEVEL_PROPERTY; static final String WRITE_CONSISTENCY_LEVEL_PROPERTY_DEFAULT; static final String MAX_CONNECTIONS_PROPERTY; static final String CORE_CONNECTIONS_PROPERTY; static final String CONNECT_TIMEOUT_MILLIS_PROPERTY; static final String READ_TIMEOUT_MILLIS_PROPERTY; static final String TRACING_PROPERTY; static final String TRACING_PROPERTY_DEFAULT; static final String USE_SSL_CONNECTION; }