use of org.locationtech.geowave.core.store.CloseableIteratorWrapper in project geowave by locationtech.
the class AccumuloOperations method getDataIndexResults.
public CloseableIterator<GeoWaveRow> getDataIndexResults(final short adapterId, final String... additionalAuthorizations) {
final byte[] family = StringUtils.stringToBinary(ByteArrayUtils.shortToString(adapterId));
// to have backwards compatibility before 1.8.0 we can assume BaseScanner is autocloseable
final Scanner scanner;
try {
scanner = createScanner(DataIndexUtils.DATA_ID_INDEX.getName(), additionalAuthorizations);
scanner.setRange(new Range());
scanner.fetchColumnFamily(new Text(family));
return new CloseableIteratorWrapper(new Closeable() {
@Override
public void close() throws IOException {
scanner.close();
}
}, Streams.stream(scanner).map(entry -> DataIndexUtils.deserializeDataIndexRow(entry.getKey().getRow().getBytes(), adapterId, entry.getValue().get(), false)).iterator());
} catch (final TableNotFoundException e) {
LOGGER.error("unable to find data index table", e);
}
return new CloseableIterator.Empty<>();
}
use of org.locationtech.geowave.core.store.CloseableIteratorWrapper in project geowave by locationtech.
the class AccumuloUtils method getIterator.
private static CloseableIterator<Entry<Key, Value>> getIterator(final Connector connector, final String namespace, final Index index) throws AccumuloException, AccumuloSecurityException, IOException, TableNotFoundException {
CloseableIterator<Entry<Key, Value>> iterator = null;
final AccumuloOptions options = new AccumuloOptions();
final AccumuloOperations operations = new AccumuloOperations(connector, namespace, new AccumuloOptions());
final IndexStore indexStore = new IndexStoreImpl(operations, options);
final PersistentAdapterStore adapterStore = new AdapterStoreImpl(operations, options);
final AdapterIndexMappingStore mappingStore = new AdapterIndexMappingStoreImpl(operations, options);
if (indexStore.indexExists(index.getName())) {
final ScannerBase scanner = operations.createBatchScanner(index.getName());
((BatchScanner) scanner).setRanges(AccumuloUtils.byteArrayRangesToAccumuloRanges(null));
final IteratorSetting iteratorSettings = new IteratorSetting(10, "GEOWAVE_WHOLE_ROW_ITERATOR", WholeRowIterator.class);
scanner.addScanIterator(iteratorSettings);
final Iterator<Entry<Key, Value>> it = new IteratorWrapper(adapterStore, mappingStore, index, scanner.iterator(), new QueryFilter[] { new DedupeFilter() });
iterator = new CloseableIteratorWrapper<>(new ScannerClosableWrapper(scanner), it);
}
return iterator;
}
use of org.locationtech.geowave.core.store.CloseableIteratorWrapper in project geowave by locationtech.
the class CassandraReader method wrapResults.
@SuppressWarnings("unchecked")
private CloseableIterator<T> wrapResults(final CloseableIterator<CassandraRow> results, final RangeReaderParams<T> readerParams) {
final Set<String> authorizations = Sets.newHashSet(readerParams.getAdditionalAuthorizations());
final Iterator<GeoWaveRow> iterator = (Iterator) Streams.stream(results).filter(new ClientVisibilityFilter(authorizations)).iterator();
return new CloseableIteratorWrapper<>(results, rowTransformer.apply(DataStoreUtils.isMergingIteratorRequired(readerParams, visibilityEnabled) ? new GeoWaveRowMergingIterator(iterator) : iterator));
}
use of org.locationtech.geowave.core.store.CloseableIteratorWrapper in project geowave by locationtech.
the class BatchedRangeRead method executeQueryAsync.
public CloseableIterator<T> executeQueryAsync(final Statement... statements) {
// first create a list of asynchronous query executions
final List<CompletionStage<AsyncResultSet>> futures = Lists.newArrayListWithExpectedSize(statements.length);
final BlockingQueue<Object> results = new LinkedBlockingQueue<>(MAX_BOUNDED_READS_ENQUEUED);
new Thread(new Runnable() {
@Override
public void run() {
// set it to 1 to make sure all queries are submitted in
// the loop
final AtomicInteger queryCount = new AtomicInteger(1);
for (final Statement s : statements) {
try {
readSemaphore.acquire();
final CompletionStage<AsyncResultSet> f = operations.getSession().executeAsync(s);
synchronized (futures) {
futures.add(f);
}
queryCount.incrementAndGet();
f.whenCompleteAsync((result, t) -> {
if (result != null) {
try {
final Iterator<GeoWaveRow> iterator = (Iterator) Streams.stream(ResultSets.newInstance(result)).map(row -> new CassandraRow(row)).filter(filter).iterator();
rowTransformer.apply(rowMerging ? new GeoWaveRowMergingIterator(iterator) : iterator).forEachRemaining(row -> {
try {
results.put(row);
} catch (final InterruptedException e) {
LOGGER.warn("interrupted while waiting to enqueue a cassandra result", e);
}
});
} finally {
checkFinalize(queryCount, results, readSemaphore);
}
} else if (t != null) {
checkFinalize(queryCount, results, readSemaphore);
// can do logging or start counting errors.
if (!(t instanceof CancellationException)) {
LOGGER.error("Failure from async query", t);
throw new RuntimeException(t);
}
}
});
} catch (final InterruptedException e) {
LOGGER.warn("Exception while executing query", e);
readSemaphore.release();
}
}
// then decrement
if (queryCount.decrementAndGet() <= 0) {
// statements submitted
try {
results.put(RowConsumer.POISON);
} catch (final InterruptedException e) {
LOGGER.error("Interrupted while finishing blocking queue, this may result in deadlock!");
}
}
}
}, "Cassandra Query Executor").start();
return new CloseableIteratorWrapper<T>(new Closeable() {
@Override
public void close() throws IOException {
synchronized (futures) {
for (final CompletionStage<AsyncResultSet> f : futures) {
f.toCompletableFuture().cancel(true);
}
}
}
}, new RowConsumer(results));
}
use of org.locationtech.geowave.core.store.CloseableIteratorWrapper in project geowave by locationtech.
the class FileSystemReader method createIterator.
private CloseableIterator<T> createIterator(final FileSystemClient client, final RangeReaderParams<T> readerParams, final GeoWaveRowIteratorTransformer<T> rowTransformer, final Collection<SinglePartitionQueryRanges> ranges, final Set<String> authorizations, final boolean async) {
final Iterator<CloseableIterator> it = Arrays.stream(ArrayUtils.toObject(readerParams.getAdapterIds())).map(adapterId -> new FileSystemQueryExecution(client, adapterId, readerParams.getInternalAdapterStore().getTypeName(adapterId), readerParams.getIndex().getName(), client.getFormat(), rowTransformer, ranges, new ClientVisibilityFilter(authorizations), DataStoreUtils.isMergingIteratorRequired(readerParams, client.isVisibilityEnabled()), async, FileSystemUtils.isGroupByRowAndIsSortByTime(readerParams, adapterId), FileSystemUtils.isSortByKeyRequired(readerParams)).results()).iterator();
final CloseableIterator<T>[] itArray = Iterators.toArray(it, CloseableIterator.class);
return new CloseableIteratorWrapper<>(new Closeable() {
AtomicBoolean closed = new AtomicBoolean(false);
@Override
public void close() throws IOException {
if (!closed.getAndSet(true)) {
Arrays.stream(itArray).forEach(it -> it.close());
}
}
}, Iterators.concat(itArray));
}
Aggregations