Search in sources :

Example 1 with AsyncKuduScanner

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)));
}
Also used : RowData(org.apache.flink.table.data.RowData) AsyncKuduScanner(org.apache.kudu.client.AsyncKuduScanner) Schema(org.apache.kudu.Schema) ColumnSchema(org.apache.kudu.ColumnSchema) Map(java.util.Map) RowResultIterator(org.apache.kudu.client.RowResultIterator)

Example 2 with AsyncKuduScanner

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));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AsyncKuduScanner(org.apache.kudu.client.AsyncKuduScanner) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RowConsumer(org.locationtech.geowave.core.store.util.RowConsumer) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CloseableIteratorWrapper(org.locationtech.geowave.core.store.CloseableIteratorWrapper)

Example 3 with AsyncKuduScanner

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);
}
Also used : AsyncKuduScanner(org.apache.kudu.client.AsyncKuduScanner) ArrayList(java.util.ArrayList) SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) AsyncKuduScannerBuilder(org.apache.kudu.client.AsyncKuduScanner.AsyncKuduScannerBuilder) KuduPredicate(org.apache.kudu.client.KuduPredicate) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange)

Aggregations

AsyncKuduScanner (org.apache.kudu.client.AsyncKuduScanner)3 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RowData (org.apache.flink.table.data.RowData)1 ColumnSchema (org.apache.kudu.ColumnSchema)1 Schema (org.apache.kudu.Schema)1 AsyncKuduScannerBuilder (org.apache.kudu.client.AsyncKuduScanner.AsyncKuduScannerBuilder)1 KuduPredicate (org.apache.kudu.client.KuduPredicate)1 RowResultIterator (org.apache.kudu.client.RowResultIterator)1 ByteArrayRange (org.locationtech.geowave.core.index.ByteArrayRange)1 SinglePartitionQueryRanges (org.locationtech.geowave.core.index.SinglePartitionQueryRanges)1 CloseableIteratorWrapper (org.locationtech.geowave.core.store.CloseableIteratorWrapper)1 RowConsumer (org.locationtech.geowave.core.store.util.RowConsumer)1