use of com.datastax.driver.core.ResultSet in project stargate-core by tuplejump.
the class IndexTestBase method countResults.
protected int countResults(String tName, String where, boolean hasWhr, boolean log) {
long before = System.nanoTime();
String select = "select * from ";
String query = select + tName + (hasWhr ? (" where " + where) : "") + " ";
ResultSet result = getSession().execute(query);
long after = System.nanoTime();
double taken = (after - before) / 1000000;
if (log)
logger.warn("Search for -" + query + " - results -");
int count1 = printResultSet(log, result);
System.out.println("Search query[" + query + "] in [" + taken + "] ms - count [" + count1 + "]");
return count1;
}
use of com.datastax.driver.core.ResultSet in project stargate-core by tuplejump.
the class IndexTestBase method countSGResults.
protected int countSGResults(String magicCol, String tName, String where, boolean hasWhr, boolean log) {
long before = System.nanoTime();
String select = "select * from ";
String query = select + tName + (hasWhr ? (" where " + where) : "") + " ";
ResultSet result = getSession().execute(query);
long after = System.nanoTime();
double taken = (after - before) / 1000000;
if (log)
logger.warn("Search for -" + query + " - results -");
int count1 = printResultSet(log, result);
System.out.println("Search query[" + query + "] in [" + taken + "] ms - count [" + count1 + "]");
return count1;
}
use of com.datastax.driver.core.ResultSet in project YCSB by brianfrankcooper.
the class CassandraCQLClient method scan.
/**
* Perform a range scan for a set of records in the database. Each field/value
* pair from the result will be stored in a HashMap.
*
* Cassandra CQL uses "token" method for range scan which doesn't always yield
* intuitive results.
*
* @param table
* The name of the table
* @param startkey
* The record key of the first record to read.
* @param recordcount
* The number of records to read
* @param fields
* The list of fields to read, or null for all of them
* @param result
* A Vector of HashMaps, where each HashMap is a set field/value
* pairs for one record
* @return Zero on success, a non-zero error code on error
*/
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
try {
Statement stmt;
Select.Builder selectBuilder;
if (fields == null) {
selectBuilder = QueryBuilder.select().all();
} else {
selectBuilder = QueryBuilder.select();
for (String col : fields) {
((Select.Selection) selectBuilder).column(col);
}
}
stmt = selectBuilder.from(table);
// The statement builder is not setup right for tokens.
// So, we need to build it manually.
String initialStmt = stmt.toString();
StringBuilder scanStmt = new StringBuilder();
scanStmt.append(initialStmt.substring(0, initialStmt.length() - 1));
scanStmt.append(" WHERE ");
scanStmt.append(QueryBuilder.token(YCSB_KEY));
scanStmt.append(" >= ");
scanStmt.append("token('");
scanStmt.append(startkey);
scanStmt.append("')");
scanStmt.append(" LIMIT ");
scanStmt.append(recordcount);
stmt = new SimpleStatement(scanStmt.toString());
stmt.setConsistencyLevel(readConsistencyLevel);
if (debug) {
System.out.println(stmt.toString());
}
if (trace) {
stmt.enableTracing();
}
ResultSet rs = session.execute(stmt);
HashMap<String, ByteIterator> tuple;
while (!rs.isExhausted()) {
Row row = rs.one();
tuple = new HashMap<String, ByteIterator>();
ColumnDefinitions cd = row.getColumnDefinitions();
for (ColumnDefinitions.Definition def : cd) {
ByteBuffer val = row.getBytesUnsafe(def.getName());
if (val != null) {
tuple.put(def.getName(), new ByteArrayByteIterator(val.array()));
} else {
tuple.put(def.getName(), null);
}
}
result.add(tuple);
}
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error scanning with startkey: " + startkey);
return Status.ERROR;
}
}
use of com.datastax.driver.core.ResultSet in project GNS by MobilityFirst.
the class CassandraRecords method contains.
@Override
public boolean contains(String tableName, String guid) {
CollectionSpec spec = getCollectionSpec(tableName);
if (spec != null) {
String query = "SELECT " + CSI(spec.getPrimaryKey()) + " FROM " + CSI(tableName) + " WHERE " + CSI(spec.getPrimaryKey()) + " = '" + guid + "';";
DatabaseConfig.getLogger().log(Level.FINER, "Executing query {0}", query);
ResultSet results = session.execute(query);
return !results.isExhausted();
} else {
DatabaseConfig.getLogger().log(Level.SEVERE, "CASSANDRA DB: No table named: {0}", tableName);
return false;
}
}
use of com.datastax.driver.core.ResultSet in project GNS by MobilityFirst.
the class CassandraRecords method removeEntireRecord.
@Override
public void removeEntireRecord(String tableName, String guid) {
CollectionSpec spec = getCollectionSpec(tableName);
if (spec != null) {
String query = "DELETE FROM " + CSI(tableName) + " WHERE " + CSI(spec.getPrimaryKey()) + " = '" + guid + "';";
DatabaseConfig.getLogger().log(Level.FINER, "Executing query {0}", query);
ResultSet results = session.execute(query);
} else {
DatabaseConfig.getLogger().log(Level.SEVERE, "CASSANDRA DB: No table named: {0}", tableName);
}
}
Aggregations