Java Code Examples for com.datastax.driver.core.Row#getLong()
The following examples show how to use
com.datastax.driver.core.Row#getLong() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AggregateDaoImpl.java From glowroot with Apache License 2.0 | 6 votes |
private ListenableFuture<?> rollupOverallSummaryFromRows(RollupParams rollup, AggregateQuery query, Iterable<Row> rows) throws Exception { double totalDurationNanos = 0; long transactionCount = 0; for (Row row : rows) { totalDurationNanos += row.getDouble(0); transactionCount += row.getLong(1); } BoundStatement boundStatement = getInsertOverallPS(summaryTable, rollup.rollupLevel()).bind(); int i = 0; boundStatement.setString(i++, rollup.agentRollupId()); boundStatement.setString(i++, query.transactionType()); boundStatement.setTimestamp(i++, new Date(query.to())); boundStatement.setDouble(i++, totalDurationNanos); boundStatement.setLong(i++, transactionCount); boundStatement.setInt(i++, rollup.adjustedTTL().generalTTL()); return session.writeAsync(boundStatement); }
Example 2
Source File: AggregateDaoImpl.java From glowroot with Apache License 2.0 | 6 votes |
private ListenableFuture<?> rollupServiceCallsFromRows(RollupParams rollup, AggregateQuery query, Iterable<Row> rows) throws Exception { ServiceCallCollector collector = new ServiceCallCollector(rollup.maxServiceCallAggregatesPerTransactionAggregate()); for (Row row : rows) { int i = 0; String serviceCallType = checkNotNull(row.getString(i++)); String serviceCallText = checkNotNull(row.getString(i++)); double totalDurationNanos = row.getDouble(i++); long executionCount = row.getLong(i++); collector.mergeServiceCall(serviceCallType, serviceCallText, totalDurationNanos, executionCount); } return insertServiceCalls(collector.getSortedAndTruncatedServiceCalls(), rollup.rollupLevel(), rollup.agentRollupId(), query.transactionType(), query.transactionName(), query.to(), rollup.adjustedTTL()); }
Example 3
Source File: VideoUtil.java From arcusplatform with Apache License 2.0 | 6 votes |
public static void recUpdateRecording(ResultSet results, VideoRecording recording) throws Exception { for (Row row : results) { double ts = row.getDouble(0); long bo = row.getLong(1); ByteBuffer bl = row.getBytes(2); if (ts == VideoConstants.REC_TS_END) { if (bo == RecordingTableField.DURATION.bo()) { recording.duration = todouble(bl); } else if (bo == RecordingTableField.SIZE.bo()) { recording.size = tolong(bl); } else { logger.warn("unknown end metadata for recording: {}", bo); } } else { recording.iframes.add(new VideoIFrame(ts,bo,tolong(bl))); } } }
Example 4
Source File: AggregateDaoImpl.java From glowroot with Apache License 2.0 | 6 votes |
@Override public void mergeQueriesInto(String agentRollupId, AggregateQuery query, QueryCollector collector) throws Exception { ResultSet results = executeQuery(agentRollupId, query, queryTable); long captureTime = Long.MIN_VALUE; for (Row row : results) { int i = 0; captureTime = Math.max(captureTime, checkNotNull(row.getTimestamp(i++)).getTime()); String queryType = checkNotNull(row.getString(i++)); String truncatedText = checkNotNull(row.getString(i++)); // full_query_text_sha1 cannot be null since it is used in clustering key String fullTextSha1 = Strings.emptyToNull(row.getString(i++)); double totalDurationNanos = row.getDouble(i++); long executionCount = row.getLong(i++); boolean hasTotalRows = !row.isNull(i); long totalRows = row.getLong(i++); collector.mergeQuery(queryType, truncatedText, fullTextSha1, totalDurationNanos, executionCount, hasTotalRows, totalRows); collector.updateLastCaptureTime(captureTime); } }
Example 5
Source File: ResultImpl.java From scalardb with Apache License 2.0 | 6 votes |
private static Value convert(Row row, String name, DataType.Name type) throws UnsupportedTypeException { switch (type) { case BOOLEAN: return new BooleanValue(name, row.getBool(name)); case INT: return new IntValue(name, row.getInt(name)); case BIGINT: return new BigIntValue(name, row.getLong(name)); case FLOAT: return new FloatValue(name, row.getFloat(name)); case DOUBLE: return new DoubleValue(name, row.getDouble(name)); case TEXT: // for backwards compatibility case VARCHAR: return new TextValue(name, row.getString(name)); case BLOB: ByteBuffer buffer = row.getBytes(name); return new BlobValue(name, buffer == null ? null : buffer.array()); default: throw new UnsupportedTypeException(type.toString()); } }
Example 6
Source File: HttpPrimeQueryIntegrationTest.java From simulacron with Apache License 2.0 | 6 votes |
@Test public void testQueryPrimeSimple() throws Exception { RequestPrime prime = HttpTestUtil.createSimplePrimedQuery("Select * FROM TABLE2"); HttpTestResponse response = server.prime(prime); assertNotNull(response); RequestPrime responseQuery = om.readValue(response.body, RequestPrime.class); assertThat(responseQuery).isEqualTo(prime); String contactPoint = HttpTestUtil.getContactPointString(server.getCluster(), 0); ResultSet set = HttpTestUtil.makeNativeQuery("Select * FROM TABLE2", contactPoint); List<Row> results = set.all(); assertThat(1).isEqualTo(results.size()); Row row1 = results.get(0); String column1 = row1.getString("column1"); assertThat(column1).isEqualTo("column1"); Long column2 = row1.getLong("column2"); assertThat(column2).isEqualTo(new Long(2)); }
Example 7
Source File: AggregateDaoImpl.java From glowroot with Apache License 2.0 | 6 votes |
private ListenableFuture<?> rollupErrorSummaryFromRows(RollupParams rollup, AggregateQuery query, Iterable<Row> rows) throws Exception { long errorCount = 0; long transactionCount = 0; for (Row row : rows) { errorCount += row.getLong(0); transactionCount += row.getLong(1); } BoundStatement boundStatement = getInsertOverallPS(errorSummaryTable, rollup.rollupLevel()).bind(); int i = 0; boundStatement.setString(i++, rollup.agentRollupId()); boundStatement.setString(i++, query.transactionType()); boundStatement.setTimestamp(i++, new Date(query.to())); boundStatement.setLong(i++, errorCount); boundStatement.setLong(i++, transactionCount); boundStatement.setInt(i++, rollup.adjustedTTL().generalTTL()); return session.writeAsync(boundStatement); }
Example 8
Source File: AggregateDaoImpl.java From glowroot with Apache License 2.0 | 6 votes |
@Override public List<ThroughputAggregate> readThroughputAggregates(String agentRollupId, AggregateQuery query) throws Exception { ResultSet results = executeQuery(agentRollupId, query, throughputTable); List<ThroughputAggregate> throughputAggregates = new ArrayList<>(); for (Row row : results) { int i = 0; long captureTime = checkNotNull(row.getTimestamp(i++)).getTime(); long transactionCount = row.getLong(i++); boolean hasErrorCount = !row.isNull(i); long errorCount = row.getLong(i++); throughputAggregates.add(ImmutableThroughputAggregate.builder() .captureTime(captureTime) .transactionCount(transactionCount) .errorCount(hasErrorCount ? errorCount : null) .build()); } return throughputAggregates; }
Example 9
Source File: AggregateDaoImpl.java From glowroot with Apache License 2.0 | 5 votes |
@Override public void mergeOverallSummaryInto(String agentRollupId, SummaryQuery query, OverallSummaryCollector collector) throws Exception { // currently have to do aggregation client-site (don't want to require Cassandra 2.2 yet) ResultSet results = executeQuery(agentRollupId, query, summaryTable); for (Row row : results) { int i = 0; // results are ordered by capture time so Math.max() is not needed here long captureTime = checkNotNull(row.getTimestamp(i++)).getTime(); double totalDurationNanos = row.getDouble(i++); long transactionCount = row.getLong(i++); collector.mergeSummary(totalDurationNanos, transactionCount, captureTime); } }
Example 10
Source File: AggregateDaoImpl.java From glowroot with Apache License 2.0 | 5 votes |
@Override public void mergeOverallErrorSummaryInto(String agentRollupId, SummaryQuery query, OverallErrorSummaryCollector collector) throws Exception { // currently have to do aggregation client-site (don't want to require Cassandra 2.2 yet) ResultSet results = executeQuery(agentRollupId, query, errorSummaryTable); for (Row row : results) { int i = 0; // results are ordered by capture time so Math.max() is not needed here long captureTime = checkNotNull(row.getTimestamp(i++)).getTime(); long errorCount = row.getLong(i++); long transactionCount = row.getLong(i++); collector.mergeErrorSummary(errorCount, transactionCount, captureTime); } }
Example 11
Source File: CassandraOperatorTest.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
public long getNumOfEventsInStore() { String countQuery = "SELECT count(*) from " + TABLE_NAME + ";"; ResultSet resultSetCount = session.execute(countQuery); for (Row row: resultSetCount) { return row.getLong(0); } return 0; }
Example 12
Source File: CassandraAttachmentDAOV2.java From james-project with Apache License 2.0 | 5 votes |
private static DAOAttachment fromRow(Row row, BlobId.Factory blobIfFactory) { return new DAOAttachment( AttachmentId.from(row.getString(ID)), blobIfFactory.from(row.getString(BLOB_ID)), ContentType.of(row.getString(TYPE)), row.getLong(SIZE)); }
Example 13
Source File: CassandraBaseTimeseriesDao.java From iotplatform with Apache License 2.0 | 5 votes |
private TsKvEntry convertResultToTsKvEntry(String key, Row row) { if (row != null) { long ts = row.getLong(ModelConstants.TS_COLUMN); return new BasicTsKvEntry(ts, toKvEntry(row, key)); } else { return new BasicTsKvEntry(System.currentTimeMillis(), new StringDataEntry(key, null)); } }
Example 14
Source File: AggregateDaoImpl.java From glowroot with Apache License 2.0 | 5 votes |
private static String mergeRowIntoSummaries(Row row, Map<String, MutableSummary> summaries) { int i = 0; String transactionName = checkNotNull(row.getString(i++)); MutableSummary summary = summaries.get(transactionName); if (summary == null) { summary = new MutableSummary(); summaries.put(transactionName, summary); } summary.totalDurationNanos += row.getDouble(i++); summary.transactionCount += row.getLong(i++); return transactionName; }
Example 15
Source File: QueueSerializationImpl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public DatabaseQueue getQueue(String name) { logger.trace( "getQueue " + name ); Clause queueNameClause = QueryBuilder.eq(COLUMN_QUEUE_NAME, name); Statement query = QueryBuilder.select().all().from(TABLE_QUEUES) .where(queueNameClause); Row row = cassandraClient.getApplicationSession().execute(query).one(); if(row == null){ return null; } final String queueName = row.getString(COLUMN_QUEUE_NAME); final String regions = row.getString(COLUMN_REGIONS); final String defaultDestinations = row.getString(COLUMN_DEFAULT_DESTINATIONS); final long defaultDelayMs = row.getLong(COLUMN_DEFAULT_DELAY_MS); final int retryCount = row.getInt(COLUMN_RETRY_COUNT); final int handlingTimeoutSec = row.getInt(COLUMN_HANDLING_TIMEOUT_SEC); final String deadLetterQueue = row.getString(COLUMN_DEAD_LETTER_QUEUE); return new DatabaseQueue( queueName, regions, defaultDestinations, defaultDelayMs, retryCount, handlingTimeoutSec, deadLetterQueue); }
Example 16
Source File: CassandraTables.java From hugegraph with Apache License 2.0 | 5 votes |
public long getCounter(CassandraSessionPool.Session session, HugeType type) { Clause where = formatEQ(HugeKeys.SCHEMA_TYPE, type.name()); Select select = QueryBuilder.select(formatKey(HugeKeys.ID)) .from(TABLE); select.where(where); Row row = session.execute(select).one(); if (row == null) { return 0L; } else { return row.getLong(formatKey(HugeKeys.ID)); } }
Example 17
Source File: SyntheticResultDaoImpl.java From glowroot with Apache License 2.0 | 4 votes |
@Override public List<SyntheticResult> readSyntheticResults(String agentRollupId, String syntheticMonitorId, long from, long to, int rollupLevel) throws Exception { BoundStatement boundStatement = readResultPS.get(rollupLevel).bind(); int i = 0; boundStatement.setString(i++, agentRollupId); boundStatement.setString(i++, syntheticMonitorId); boundStatement.setTimestamp(i++, new Date(from)); boundStatement.setTimestamp(i++, new Date(to)); ResultSet results = session.read(boundStatement); List<SyntheticResult> syntheticResults = new ArrayList<>(); for (Row row : results) { i = 0; long captureTime = checkNotNull(row.getTimestamp(i++)).getTime(); double totalDurationNanos = row.getDouble(i++); long executionCount = row.getLong(i++); ByteBuffer errorIntervalsBytes = row.getBytes(i++); List<ErrorInterval> errorIntervals = new ArrayList<>(); if (errorIntervalsBytes != null) { List<Stored.ErrorInterval> storedErrorIntervals = Messages .parseDelimitedFrom(errorIntervalsBytes, Stored.ErrorInterval.parser()); for (Stored.ErrorInterval storedErrorInterval : storedErrorIntervals) { errorIntervals.add(ImmutableErrorInterval.builder() .from(storedErrorInterval.getFrom()) .to(storedErrorInterval.getTo()) .count(storedErrorInterval.getCount()) .message(storedErrorInterval.getMessage()) .doNotMergeToTheLeft(storedErrorInterval.getDoNotMergeToTheLeft()) .doNotMergeToTheRight(storedErrorInterval.getDoNotMergeToTheRight()) .build()); } } syntheticResults.add(ImmutableSyntheticResult.builder() .captureTime(captureTime) .totalDurationNanos(totalDurationNanos) .executionCount(executionCount) .addAllErrorIntervals(errorIntervals) .build()); } return syntheticResults; }
Example 18
Source File: AbstractCassandraProcessor.java From localization_nifi with Apache License 2.0 | 4 votes |
protected static Object getCassandraObject(Row row, int i, DataType dataType) { if (dataType.equals(DataType.blob())) { return row.getBytes(i); } else if (dataType.equals(DataType.varint()) || dataType.equals(DataType.decimal())) { // Avro can't handle BigDecimal and BigInteger as numbers - it will throw an // AvroRuntimeException such as: "Unknown datum type: java.math.BigDecimal: 38" return row.getObject(i).toString(); } else if (dataType.equals(DataType.cboolean())) { return row.getBool(i); } else if (dataType.equals(DataType.cint())) { return row.getInt(i); } else if (dataType.equals(DataType.bigint()) || dataType.equals(DataType.counter())) { return row.getLong(i); } else if (dataType.equals(DataType.ascii()) || dataType.equals(DataType.text()) || dataType.equals(DataType.varchar())) { return row.getString(i); } else if (dataType.equals(DataType.cfloat())) { return row.getFloat(i); } else if (dataType.equals(DataType.cdouble())) { return row.getDouble(i); } else if (dataType.equals(DataType.timestamp())) { return row.getTimestamp(i); } else if (dataType.equals(DataType.date())) { return row.getDate(i); } else if (dataType.equals(DataType.time())) { return row.getTime(i); } else if (dataType.isCollection()) { List<DataType> typeArguments = dataType.getTypeArguments(); if (typeArguments == null || typeArguments.size() == 0) { throw new IllegalArgumentException("Column[" + i + "] " + dataType.getName() + " is a collection but no type arguments were specified!"); } // Get the first type argument, to be used for lists and sets (and the first in a map) DataType firstArg = typeArguments.get(0); TypeCodec firstCodec = codecRegistry.codecFor(firstArg); if (dataType.equals(DataType.set(firstArg))) { return row.getSet(i, firstCodec.getJavaType()); } else if (dataType.equals(DataType.list(firstArg))) { return row.getList(i, firstCodec.getJavaType()); } else { // Must be an n-arg collection like map DataType secondArg = typeArguments.get(1); TypeCodec secondCodec = codecRegistry.codecFor(secondArg); if (dataType.equals(DataType.map(firstArg, secondArg))) { return row.getMap(i, firstCodec.getJavaType(), secondCodec.getJavaType()); } } } else { // The different types that we support are numbers (int, long, double, float), // as well as boolean values and Strings. Since Avro doesn't provide // timestamp types, we want to convert those to Strings. So we will cast anything other // than numbers or booleans to strings by using the toString() method. return row.getObject(i).toString(); } return null; }
Example 19
Source File: AbstractPlaceRecordingIndexV2Table.java From arcusplatform with Apache License 2.0 | 4 votes |
public VideoRecordingSize materializeVideoRecordingSize(Row row) { return new VideoRecordingSize(row.getUUID(COL_RECORDINGID), row.getLong(COL_SIZE), isFavoriteTable()); }
Example 20
Source File: QueueMessageSerializationImpl.java From usergrid with Apache License 2.0 | 4 votes |
@Override public DatabaseQueueMessage loadMessage( final String queueName, final String region, final Long shardIdOrNull, final DatabaseQueueMessage.Type type, final UUID queueMessageId ) { if ( queueMessageId == null ) { return null; } logger.trace("loadMessage {}", queueMessageId); final long shardId; if ( shardIdOrNull == null ) { Shard.Type shardType = DatabaseQueueMessage.Type.DEFAULT.equals( type ) ? Shard.Type.DEFAULT : Shard.Type.INFLIGHT; Shard shard = shardStrategy.selectShard( queueName, region, shardType, queueMessageId ); shardId = shard.getShardId(); } else { shardId = shardIdOrNull; } Clause queueNameClause = QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ); Clause regionClause = QueryBuilder.eq( COLUMN_REGION, region ); Clause shardIdClause = QueryBuilder.eq( COLUMN_SHARD_ID, shardId ); Clause queueMessageIdClause = QueryBuilder.eq( COLUMN_QUEUE_MESSAGE_ID, queueMessageId); Statement select = QueryBuilder.select().from(getTableName( type )) .where(queueNameClause) .and(regionClause) .and(shardIdClause) .and(queueMessageIdClause); Row row = cassandraClient.getQueueMessageSession().execute(select).one(); if (row == null) { return null; } return new DatabaseQueueMessage( row.getUUID( COLUMN_MESSAGE_ID), type, row.getString( COLUMN_QUEUE_NAME), row.getString( COLUMN_REGION), row.getLong( COLUMN_SHARD_ID), row.getLong( COLUMN_QUEUED_AT), row.getLong( COLUMN_INFLIGHT_AT), row.getUUID( COLUMN_QUEUE_MESSAGE_ID) ); }