Search in sources :

Example 21 with ResultSet

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;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet)

Example 22 with ResultSet

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;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet)

Example 23 with ResultSet

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;
    }
}
Also used : ColumnDefinitions(com.datastax.driver.core.ColumnDefinitions) SimpleStatement(com.datastax.driver.core.SimpleStatement) Statement(com.datastax.driver.core.Statement) SimpleStatement(com.datastax.driver.core.SimpleStatement) ByteBuffer(java.nio.ByteBuffer) DBException(com.yahoo.ycsb.DBException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) Select(com.datastax.driver.core.querybuilder.Select) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row)

Example 24 with ResultSet

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;
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet)

Example 25 with ResultSet

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);
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet)

Aggregations

ResultSet (com.datastax.driver.core.ResultSet)64 Row (com.datastax.driver.core.Row)35 Test (org.junit.Test)25 BoundStatement (com.datastax.driver.core.BoundStatement)11 Session (com.datastax.driver.core.Session)10 ArrayList (java.util.ArrayList)9 Cluster (com.datastax.driver.core.Cluster)8 Statement (com.datastax.driver.core.Statement)7 PreparedStatement (com.datastax.driver.core.PreparedStatement)5 List (java.util.List)5 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)4 Select (com.datastax.driver.core.querybuilder.Select)4 TypeHint (org.apache.flink.api.common.typeinfo.TypeHint)4 BatchStatement (com.datastax.driver.core.BatchStatement)3 RegularStatement (com.datastax.driver.core.RegularStatement)3 Update (com.datastax.driver.core.querybuilder.Update)3 ImmutableList (com.google.common.collect.ImmutableList)3 IgniteException (org.apache.ignite.IgniteException)3 RandomSleeper (org.apache.ignite.cache.store.cassandra.common.RandomSleeper)3 ColumnDefinitions (com.datastax.driver.core.ColumnDefinitions)2