Search in sources :

Example 1 with KuduRow

use of org.locationtech.geowave.datastore.kudu.KuduRow in project geowave by locationtech.

the class KuduRangeRead method executeScanner.

public Deferred<Object> executeScanner(final AsyncKuduScanner scanner, final Semaphore semaphore, final BlockingQueue<Object> resultQueue, final AtomicInteger queryCount, final AtomicBoolean isCanceled, final boolean visibilityEnabled, final Predicate<GeoWaveRow> filter, final GeoWaveRowIteratorTransformer<T> rowTransformer, final boolean rowMerging) {
    // Errback class
    class QueryErrback implements Callback<Deferred<Object>, Exception> {

        @Override
        public Deferred<Object> call(final Exception e) {
            LOGGER.warn("While scanning rows from kudu", e);
            checkFinalize(scanner, semaphore, resultQueue, queryCount);
            return Deferred.fromError(e);
        }
    }
    final QueryErrback errBack = new QueryErrback();
    // callback class
    class QueryCallback implements Callback<Deferred<Object>, RowResultIterator> {

        @Override
        public Deferred<Object> call(final RowResultIterator rs) {
            if ((rs == null) || isCanceled.get()) {
                checkFinalize(scanner, semaphore, resultQueue, queryCount);
                return Deferred.fromResult(null);
            }
            if (rs.getNumRows() > 0) {
                Stream<GeoWaveRow> tmpStream = Streams.stream(rs.iterator()).map(KuduRow::new);
                if (visibilityEnabled) {
                    tmpStream = tmpStream.filter(filter);
                }
                final Iterator<GeoWaveRow> tmpIterator = tmpStream.iterator();
                rowTransformer.apply(rowMerging ? new GeoWaveRowMergingIterator(tmpIterator) : tmpIterator).forEachRemaining(row -> {
                    try {
                        resultQueue.put(row);
                    } catch (final InterruptedException e) {
                        LOGGER.warn("interrupted while waiting to enqueue a kudu result", e);
                    }
                });
            }
            if (scanner.hasMoreRows()) {
                return scanner.nextRows().addCallbackDeferring(this).addErrback(errBack);
            }
            checkFinalize(scanner, semaphore, resultQueue, queryCount);
            return Deferred.fromResult(null);
        }
    }
    queryCount.incrementAndGet();
    return scanner.nextRows().addCallbackDeferring(new QueryCallback()).addErrback(errBack);
}
Also used : GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) Callback(com.stumbleupon.async.Callback) GeoWaveRowMergingIterator(org.locationtech.geowave.core.store.entities.GeoWaveRowMergingIterator) KuduRow(org.locationtech.geowave.datastore.kudu.KuduRow) RowResultIterator(org.apache.kudu.client.RowResultIterator)

Example 2 with KuduRow

use of org.locationtech.geowave.datastore.kudu.KuduRow in project geowave by locationtech.

the class KuduWriter method write.

@Override
public synchronized void write(final GeoWaveRow row) {
    final boolean isDataIndex = DataIndexUtils.isDataIndex(tableName);
    final boolean isVisibilityEnabled = operations.options.getStoreOptions().isVisibilityEnabled();
    try {
        final KuduTable table = operations.getTable(tableName);
        for (final GeoWaveValue value : row.getFieldValues()) {
            final Insert insert = table.newInsert();
            if (isDataIndex) {
                final KuduDataIndexRow kuduRow = new KuduDataIndexRow(row, value, isVisibilityEnabled);
                kuduRow.populatePartialRow(insert.getRow());
            } else {
                final KuduRow kuduRow = new KuduRow(row, value);
                kuduRow.populatePartialRow(insert.getRow());
            }
            session.apply(insert);
            if (session.getPendingErrors().getRowErrors().length > 0) {
                final RowError[] rowErrors = session.getPendingErrors().getRowErrors();
                for (int i = 0; i < rowErrors.length; i++) {
                    LOGGER.error("Encountered error while applying insert: {}", rowErrors[i]);
                }
            }
        }
    } catch (final KuduException e) {
        LOGGER.error("Encountered error while writing row", e);
    }
}
Also used : RowError(org.apache.kudu.client.RowError) KuduDataIndexRow(org.locationtech.geowave.datastore.kudu.KuduDataIndexRow) KuduTable(org.apache.kudu.client.KuduTable) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue) Insert(org.apache.kudu.client.Insert) KuduRow(org.locationtech.geowave.datastore.kudu.KuduRow) KuduException(org.apache.kudu.client.KuduException)

Example 3 with KuduRow

use of org.locationtech.geowave.datastore.kudu.KuduRow in project geowave by locationtech.

the class KuduDeleter method delete.

@Override
public void delete(final GeoWaveRow row) {
    try {
        final KuduTable table = operations.getTable(tableName);
        final Schema schema = table.getSchema();
        final List<KuduPredicate> preds = new ArrayList<>();
        final byte[] partitionKey = row.getPartitionKey();
        final short adapterId = row.getAdapterId();
        final byte[] sortKey = row.getSortKey();
        final byte[] dataId = row.getDataId();
        // deletion using predicates on the known columns.
        for (final GeoWaveValue value : row.getFieldValues()) {
            preds.add(KuduPredicate.newComparisonPredicate(schema.getColumn(KuduField.GW_PARTITION_ID_KEY.getFieldName()), KuduPredicate.ComparisonOp.EQUAL, partitionKey));
            preds.add(KuduPredicate.newComparisonPredicate(schema.getColumn(KuduField.GW_ADAPTER_ID_KEY.getFieldName()), KuduPredicate.ComparisonOp.EQUAL, adapterId));
            preds.add(KuduPredicate.newComparisonPredicate(schema.getColumn(KuduField.GW_SORT_KEY.getFieldName()), KuduPredicate.ComparisonOp.EQUAL, sortKey));
            preds.add(KuduPredicate.newComparisonPredicate(schema.getColumn(KuduField.GW_DATA_ID_KEY.getFieldName()), KuduPredicate.ComparisonOp.EQUAL, dataId));
            preds.add(KuduPredicate.newComparisonPredicate(schema.getColumn(KuduField.GW_FIELD_VISIBILITY_KEY.getFieldName()), KuduPredicate.ComparisonOp.EQUAL, value.getVisibility()));
            for (final Delete delete : operations.getDeletions(table, preds, KuduRow::new)) {
                final OperationResponse resp = session.apply(delete);
                if (resp.hasRowError()) {
                    LOGGER.error("Encountered error while deleting row: {}", resp.getRowError());
                }
            }
        }
    } catch (final KuduException e) {
        LOGGER.error("Encountered error while deleting row", e);
    }
}
Also used : Delete(org.apache.kudu.client.Delete) Schema(org.apache.kudu.Schema) ArrayList(java.util.ArrayList) KuduTable(org.apache.kudu.client.KuduTable) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue) OperationResponse(org.apache.kudu.client.OperationResponse) KuduPredicate(org.apache.kudu.client.KuduPredicate) KuduRow(org.locationtech.geowave.datastore.kudu.KuduRow) KuduException(org.apache.kudu.client.KuduException)

Aggregations

KuduRow (org.locationtech.geowave.datastore.kudu.KuduRow)3 KuduException (org.apache.kudu.client.KuduException)2 KuduTable (org.apache.kudu.client.KuduTable)2 GeoWaveValue (org.locationtech.geowave.core.store.entities.GeoWaveValue)2 Callback (com.stumbleupon.async.Callback)1 ArrayList (java.util.ArrayList)1 Schema (org.apache.kudu.Schema)1 Delete (org.apache.kudu.client.Delete)1 Insert (org.apache.kudu.client.Insert)1 KuduPredicate (org.apache.kudu.client.KuduPredicate)1 OperationResponse (org.apache.kudu.client.OperationResponse)1 RowError (org.apache.kudu.client.RowError)1 RowResultIterator (org.apache.kudu.client.RowResultIterator)1 GeoWaveRow (org.locationtech.geowave.core.store.entities.GeoWaveRow)1 GeoWaveRowMergingIterator (org.locationtech.geowave.core.store.entities.GeoWaveRowMergingIterator)1 KuduDataIndexRow (org.locationtech.geowave.datastore.kudu.KuduDataIndexRow)1