use of org.locationtech.geowave.core.index.ByteArray in project geowave by locationtech.
the class StatisticsCache method getFieldStatistic.
@SuppressWarnings("unchecked")
public <V extends StatisticValue<R>, R> V getFieldStatistic(final StatisticType<V> statisticType, final String fieldName) {
if (statisticType == null || fieldName == null) {
return null;
}
ByteArray key = new ByteArray(Bytes.concat(statisticType.getBytes(), StatisticId.UNIQUE_ID_SEPARATOR, StringUtils.stringToBinary(fieldName)));
if (cache.containsKey(key)) {
return (V) cache.get(key);
}
V retVal = null;
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> statsIter = statisticsStore.getFieldStatistics(adapter, statisticType, fieldName, null)) {
if (statsIter.hasNext()) {
Statistic<V> stat = (Statistic<V>) statsIter.next();
V value = statisticsStore.getStatisticValue(stat, authorizations);
if (value != null) {
retVal = value;
}
}
}
cache.put(key, retVal);
return retVal;
}
use of org.locationtech.geowave.core.index.ByteArray in project geowave by locationtech.
the class CassandraOperations method getRows.
public Iterator<GeoWaveRow> getRows(final byte[][] dataIds, final short adapterId) {
PreparedStatement preparedRead;
final String tableName = DataIndexUtils.DATA_ID_INDEX.getName();
final String safeTableName = getCassandraSafeName(tableName);
synchronized (state.preparedRangeReadsPerTable) {
preparedRead = state.preparedRangeReadsPerTable.get(safeTableName);
if (preparedRead == null) {
final Select select = getSelect(safeTableName);
;
preparedRead = session.prepare(select.whereColumn(CassandraRow.CassandraField.GW_PARTITION_ID_KEY.getFieldName()).in(QueryBuilder.bindMarker(CassandraRow.CassandraField.GW_PARTITION_ID_KEY.getBindMarkerName())).whereColumn(CassandraRow.CassandraField.GW_ADAPTER_ID_KEY.getFieldName()).isEqualTo(QueryBuilder.bindMarker(CassandraRow.CassandraField.GW_ADAPTER_ID_KEY.getBindMarkerName())).build());
state.preparedRangeReadsPerTable.put(safeTableName, preparedRead);
}
}
final BoundStatementBuilder statement = preparedRead.boundStatementBuilder();
final ResultSet results = getSession().execute(statement.set(CassandraField.GW_ADAPTER_ID_KEY.getBindMarkerName(), adapterId, TypeCodecs.SMALLINT).set(CassandraField.GW_PARTITION_ID_KEY.getBindMarkerName(), Arrays.stream(dataIds).map(d -> ByteBuffer.wrap(d)).collect(Collectors.toList()), TypeCodecs.listOf(TypeCodecs.BLOB)).build());
final Map<ByteArray, GeoWaveRow> resultsMap = new HashMap<>();
results.forEach(r -> {
final byte[] d = r.getByteBuffer(CassandraField.GW_PARTITION_ID_KEY.getFieldName()).array();
final byte[] v = r.getByteBuffer(CassandraField.GW_VALUE_KEY.getFieldName()).array();
resultsMap.put(new ByteArray(d), DataIndexUtils.deserializeDataIndexRow(d, adapterId, v, options.isVisibilityEnabled()));
});
return Arrays.stream(dataIds).map(d -> resultsMap.get(new ByteArray(d))).filter(r -> r != null).iterator();
}
use of org.locationtech.geowave.core.index.ByteArray in project geowave by locationtech.
the class DynamoDBOperations method getResults.
private BatchGetItemResult getResults(final Map<String, KeysAndAttributes> requestItems, final short adapterId, final Map<ByteArray, GeoWaveRow> resultMap) {
final BatchGetItemRequest request = new BatchGetItemRequest(requestItems);
final BatchGetItemResult result = client.batchGetItem(request);
result.getResponses().values().forEach(results -> results.stream().forEach(objMap -> {
final byte[] dataId = objMap.get(DynamoDBRow.GW_PARTITION_ID_KEY).getB().array();
final AttributeValue valueAttr = objMap.get(DynamoDBRow.GW_VALUE_KEY);
final byte[] value = valueAttr == null ? null : valueAttr.getB().array();
final AttributeValue visAttr = objMap.get(DynamoDBRow.GW_VISIBILITY_KEY);
final byte[] vis = visAttr == null ? new byte[0] : visAttr.getB().array();
resultMap.put(new ByteArray(dataId), DataIndexUtils.deserializeDataIndexRow(dataId, adapterId, value, vis));
}));
return result;
}
use of org.locationtech.geowave.core.index.ByteArray in project geowave by locationtech.
the class DynamoDBOperations method getRowsFromDataIndex.
public Iterator<GeoWaveRow> getRowsFromDataIndex(final byte[][] dataIds, final short adapterId, final String typeName) {
final Map<ByteArray, GeoWaveRow> resultMap = new HashMap<>();
final Iterator<byte[]> dataIdIterator = Arrays.stream(dataIds).iterator();
while (dataIdIterator.hasNext()) {
// fill result map
final Collection<Map<String, AttributeValue>> dataIdsForRequest = new ArrayList<>();
int i = 0;
while (dataIdIterator.hasNext() && (i < MAX_ROWS_FOR_BATCHGETITEM)) {
dataIdsForRequest.add(Collections.singletonMap(DynamoDBRow.GW_PARTITION_ID_KEY, new AttributeValue().withB(ByteBuffer.wrap(dataIdIterator.next()))));
i++;
}
BatchGetItemResult result = getResults(Collections.singletonMap(typeName + "_" + getQualifiedTableName(DataIndexUtils.DATA_ID_INDEX.getName()), new KeysAndAttributes().withKeys(dataIdsForRequest)), adapterId, resultMap);
while (!result.getUnprocessedKeys().isEmpty()) {
result = getResults(result.getUnprocessedKeys(), adapterId, resultMap);
}
}
return Arrays.stream(dataIds).map(d -> resultMap.get(new ByteArray(d))).filter(r -> r != null).iterator();
}
use of org.locationtech.geowave.core.index.ByteArray in project geowave by locationtech.
the class BatchHandler method addStatement.
protected BatchStatementBuilder addStatement(final GeoWaveRow row, final BatchableStatement statement) {
final ByteArray partition = new ByteArray(row.getPartitionKey());
BatchStatementBuilder tokenBatch = batches.get(partition);
if (tokenBatch == null) {
tokenBatch = new BatchStatementBuilder(type);
batches.put(partition, tokenBatch);
}
synchronized (tokenBatch) {
tokenBatch.addStatement(statement);
}
return tokenBatch;
}
Aggregations