Search in sources :

Example 1 with AsyncKuduScannerBuilder

use of org.apache.kudu.client.AsyncKuduScanner.AsyncKuduScannerBuilder 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

ArrayList (java.util.ArrayList)1 AsyncKuduScanner (org.apache.kudu.client.AsyncKuduScanner)1 AsyncKuduScannerBuilder (org.apache.kudu.client.AsyncKuduScanner.AsyncKuduScannerBuilder)1 KuduPredicate (org.apache.kudu.client.KuduPredicate)1 ByteArrayRange (org.locationtech.geowave.core.index.ByteArrayRange)1 SinglePartitionQueryRanges (org.locationtech.geowave.core.index.SinglePartitionQueryRanges)1