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);
}
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);
}
}
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);
}
}
Aggregations