Search in sources :

Example 11 with Row

use of com.datastax.driver.core.Row in project newts by OpenNMS.

the class CassandraSearcher method searchForIds.

/**
     * Returns the set of resource ids that match the given
     * term query.
     */
private Set<String> searchForIds(Context context, TermQuery query, ConsistencyLevel readConsistency) {
    Set<String> ids = Sets.newTreeSet();
    BoundStatement bindStatement = m_searchStatement.bind();
    bindStatement.setString(Schema.C_TERMS_CONTEXT, context.getId());
    bindStatement.setString(Schema.C_TERMS_FIELD, query.getTerm().getField(Constants.DEFAULT_TERM_FIELD));
    bindStatement.setString(Schema.C_TERMS_VALUE, query.getTerm().getValue());
    bindStatement.setConsistencyLevel(readConsistency);
    for (Row row : m_session.execute(bindStatement)) {
        ids.add(row.getString(Constants.Schema.C_TERMS_RESOURCE));
    }
    return ids;
}
Also used : Row(com.datastax.driver.core.Row) BoundStatement(com.datastax.driver.core.BoundStatement)

Example 12 with Row

use of com.datastax.driver.core.Row in project javaee7-samples by javaee-samples.

the class PersonSessionBean method getPersons.

public List<Person> getPersons() {
    List<Person> persons = new ArrayList<>();
    ResultSet results = session.execute(selectAllPersons.bind());
    for (Row row : results) {
        persons.add(new Person(row.getString("name"), row.getInt("age")));
    }
    return persons;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row)

Example 13 with Row

use of com.datastax.driver.core.Row in project zipkin by openzipkin.

the class CassandraSpanStore method getSpanNames.

@Override
public ListenableFuture<List<String>> getSpanNames(String serviceName) {
    if (serviceName == null || serviceName.isEmpty())
        return EMPTY_LIST;
    serviceName = checkNotNull(serviceName, "serviceName").toLowerCase();
    int bucket = 0;
    try {
        BoundStatement bound = CassandraUtil.bindWithName(selectSpanNames, "select-span-names").setString("service_name", serviceName).setInt("bucket", bucket).setInt("limit_", 1000);
        return transform(session.executeAsync(bound), new Function<ResultSet, List<String>>() {

            @Override
            public List<String> apply(ResultSet input) {
                Set<String> spanNames = new HashSet<>();
                for (Row row : input) {
                    spanNames.add(row.getString("span_name"));
                }
                return Ordering.natural().sortedCopy(spanNames);
            }
        });
    } catch (RuntimeException ex) {
        return immediateFailedFuture(ex);
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ContiguousSet(com.google.common.collect.ContiguousSet) HashSet(java.util.HashSet) ResultSet(com.datastax.driver.core.ResultSet) ResultSet(com.datastax.driver.core.ResultSet) Futures.allAsList(com.google.common.util.concurrent.Futures.allAsList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Row(com.datastax.driver.core.Row) BoundStatement(com.datastax.driver.core.BoundStatement)

Example 14 with Row

use of com.datastax.driver.core.Row in project zipkin by openzipkin.

the class CassandraSpanStore method getSpansByTraceIds.

/**
   * Get the available trace information from the storage system. Spans in trace should be sorted by
   * the first annotation timestamp in that span. First event should be first in the spans list. <p>
   * The return list will contain only spans that have been found, thus the return list may not
   * match the provided list of ids.
   */
ListenableFuture<List<Span>> getSpansByTraceIds(Set<Long> traceIds, int limit) {
    checkNotNull(traceIds, "traceIds");
    if (traceIds.isEmpty()) {
        return immediateFuture(Collections.<Span>emptyList());
    }
    try {
        BoundStatement bound = CassandraUtil.bindWithName(selectTraces, "select-traces").setSet("trace_id", traceIds).setInt("limit_", limit);
        bound.setFetchSize(Integer.MAX_VALUE);
        return transform(session.executeAsync(bound), new Function<ResultSet, List<Span>>() {

            @Override
            public List<Span> apply(ResultSet input) {
                List<Span> result = new ArrayList<>(input.getAvailableWithoutFetching());
                for (Row row : input) {
                    result.add(Codec.THRIFT.readSpan(row.getBytes("span")));
                }
                return result;
            }
        });
    } catch (RuntimeException ex) {
        return immediateFailedFuture(ex);
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Futures.allAsList(com.google.common.util.concurrent.Futures.allAsList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Row(com.datastax.driver.core.Row) BoundStatement(com.datastax.driver.core.BoundStatement)

Example 15 with Row

use of com.datastax.driver.core.Row in project zipkin by openzipkin.

the class CassandraSpanStore method getTraceIdsByAnnotation.

ListenableFuture<Map<Long, Long>> getTraceIdsByAnnotation(String annotationKey, long endTs, long lookback, int limit) {
    long startTs = endTs - lookback;
    try {
        BoundStatement bound = CassandraUtil.bindWithName(selectTraceIdsByAnnotation, "select-trace-ids-by-annotation").setBytes("annotation", CassandraUtil.toByteBuffer(annotationKey)).setSet("bucket", buckets).setBytesUnsafe("start_ts", timestampCodec.serialize(startTs)).setBytesUnsafe("end_ts", timestampCodec.serialize(endTs)).setInt("limit_", limit);
        bound.setFetchSize(Integer.MAX_VALUE);
        return transform(session.executeAsync(bound), new Function<ResultSet, Map<Long, Long>>() {

            @Override
            public Map<Long, Long> apply(ResultSet input) {
                Map<Long, Long> traceIdsToTimestamps = new LinkedHashMap<>();
                for (Row row : input) {
                    traceIdsToTimestamps.put(row.getLong("trace_id"), timestampCodec.deserialize(row, "ts"));
                }
                return traceIdsToTimestamps;
            }
        });
    } catch (CharacterCodingException | RuntimeException ex) {
        return immediateFailedFuture(ex);
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) CharacterCodingException(java.nio.charset.CharacterCodingException) BoundStatement(com.datastax.driver.core.BoundStatement) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Row (com.datastax.driver.core.Row)59 ResultSet (com.datastax.driver.core.ResultSet)35 Test (org.junit.Test)23 Session (com.datastax.driver.core.Session)10 ArrayList (java.util.ArrayList)10 BoundStatement (com.datastax.driver.core.BoundStatement)9 Cluster (com.datastax.driver.core.Cluster)9 Statement (com.datastax.driver.core.Statement)7 List (java.util.List)6 ImmutableList (com.google.common.collect.ImmutableList)5 HashSet (java.util.HashSet)5 PreparedStatement (com.datastax.driver.core.PreparedStatement)4 Select (com.datastax.driver.core.querybuilder.Select)4 ByteBuffer (java.nio.ByteBuffer)4 BatchStatement (com.datastax.driver.core.BatchStatement)3 Update (com.datastax.driver.core.querybuilder.Update)3 HashMap (java.util.HashMap)3 ProtocolVersion (org.apache.cassandra.transport.ProtocolVersion)3 TypeHint (org.apache.flink.api.common.typeinfo.TypeHint)3 ColumnDefinitions (com.datastax.driver.core.ColumnDefinitions)2