use of org.apache.kudu.client.AsyncKuduScanner in project chunjun by DTStack.
the class KuduLruTableFunction method handleAsyncInvoke.
@Override
public void handleAsyncInvoke(CompletableFuture<Collection<RowData>> future, Object... keys) throws Exception {
String key = buildCacheKey(keys);
if (StringUtils.isBlank(key)) {
return;
}
Schema schema = kuduTable.getSchema();
// scannerBuilder 设置为null重新加载过滤条件,然后connKudu重新赋值
scannerBuilder = buildAsyncKuduScannerBuilder(schema, keys);
List<Map<String, Object>> cacheContent = Lists.newArrayList();
AsyncKuduScanner asyncKuduScanner = scannerBuilder.build();
List<RowData> rowList = Lists.newArrayList();
// 谓词
Deferred<RowResultIterator> iteratorDeferred = asyncKuduScanner.nextRows();
iteratorDeferred.addCallback(new GetListRowCB(cacheContent, rowList, asyncKuduScanner, future, buildCacheKey(keys)));
}
use of org.apache.kudu.client.AsyncKuduScanner in project geowave by locationtech.
the class KuduRangeRead method executeQueryAsync.
public CloseableIterator<T> executeQueryAsync(final List<AsyncKuduScanner> scanners) {
final BlockingQueue<Object> results = new LinkedBlockingQueue<>(MAX_BOUNDED_READS_ENQUEUED);
final AtomicBoolean isCanceled = new AtomicBoolean(false);
new Thread(() -> {
final AtomicInteger queryCount = new AtomicInteger(1);
for (final AsyncKuduScanner scanner : scanners) {
try {
readSemaphore.acquire();
executeScanner(scanner, readSemaphore, results, queryCount, isCanceled, visibilityEnabled, filter, rowTransformer, rowMerging);
} catch (final InterruptedException e) {
LOGGER.warn("Exception while executing query", e);
readSemaphore.release();
}
}
// then decrement
if (queryCount.decrementAndGet() <= 0) {
// and if there are no queries, there may not have been any statements submitted
try {
results.put(RowConsumer.POISON);
} catch (final InterruptedException e) {
LOGGER.error("Interrupted while finishing blocking queue, this may result in deadlock!");
}
}
}, "Kudu Query Executor").start();
return new CloseableIteratorWrapper<T>(() -> isCanceled.set(true), new RowConsumer(results));
}
use of org.apache.kudu.client.AsyncKuduScanner in project geowave by locationtech.
the class KuduRangeRead method results.
public CloseableIterator<T> results() {
final List<AsyncKuduScanner> scanners = new ArrayList<>();
final KuduPredicate adapterIdPred = KuduPredicate.newInListPredicate(schema.getColumn(KuduField.GW_ADAPTER_ID_KEY.getFieldName()), Arrays.asList(ArrayUtils.toObject(adapterIds)));
if ((ranges != null) && !ranges.isEmpty()) {
for (final SinglePartitionQueryRanges r : ranges) {
byte[] partitionKey = r.getPartitionKey();
if (partitionKey == null) {
partitionKey = new byte[0];
}
final KuduPredicate partitionPred = KuduPredicate.newComparisonPredicate(schema.getColumn(KuduField.GW_PARTITION_ID_KEY.getFieldName()), ComparisonOp.EQUAL, partitionKey);
for (final ByteArrayRange range : r.getSortKeyRanges()) {
final byte[] start = range.getStart() != null ? range.getStart() : new byte[0];
final byte[] end = range.getEnd() != null ? range.getEndAsNextPrefix() : new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
final KuduPredicate lowerPred = KuduPredicate.newComparisonPredicate(schema.getColumn(KuduField.GW_SORT_KEY.getFieldName()), ComparisonOp.GREATER_EQUAL, start);
final KuduPredicate upperPred = KuduPredicate.newComparisonPredicate(schema.getColumn(KuduField.GW_SORT_KEY.getFieldName()), ComparisonOp.LESS, end);
final AsyncKuduScannerBuilder scannerBuilder = operations.getAsyncScannerBuilder(table);
final AsyncKuduScanner scanner = scannerBuilder.addPredicate(adapterIdPred).addPredicate(partitionPred).addPredicate(lowerPred).addPredicate(upperPred).build();
scanners.add(scanner);
}
}
} else {
final AsyncKuduScannerBuilder scannerBuilder = operations.getAsyncScannerBuilder(table);
final AsyncKuduScanner scanner = scannerBuilder.addPredicate(adapterIdPred).build();
scanners.add(scanner);
}
return executeQueryAsync(scanners);
}
Aggregations