Aggregators aggregators = ServerAggregators.deserialize(
scan.getAttribute(GroupedAggregateRegionObserver.AGGREGATORS), c.getEnvironment().getConfiguration());
Aggregator[] rowAggregators = aggregators.getAggregators();
boolean hasMore;
boolean hasAny = false;
MultiKeyValueTuple result = new MultiKeyValueTuple();
if (logger.isInfoEnabled()) {
logger.info("Starting ungrouped coprocessor scan " + scan);
}
long rowCount = 0;
MultiVersionConsistencyControl.setThreadReadPoint(innerScanner.getMvccReadPoint());
region.startRegionOperation();
try {
do {
List<KeyValue> results = new ArrayList<KeyValue>();
// Results are potentially returned even when the return value of s.next is false
// since this is an indication of whether or not there are more values after the
// ones returned
hasMore = innerScanner.nextRaw(results, null);
if (!results.isEmpty()) {
rowCount++;
result.setKeyValues(results);
try {
if (isDelete) {
@SuppressWarnings("deprecation") // FIXME: Remove when unintentionally deprecated method is fixed (HBASE-7870).
// FIXME: the version of the Delete constructor without the lock args was introduced
// in 0.94.4, thus if we try to use it here we can no longer use the 0.94.2 version
// of the client.
Delete delete = new Delete(results.get(0).getRow(),ts,null);
mutations.add(new Pair<Mutation,Integer>(delete,null));
} else if (isUpsert) {
Arrays.fill(values, null);
int i = 0;
List<PColumn> projectedColumns = projectedTable.getColumns();
for (; i < projectedTable.getPKColumns().size(); i++) {
Expression expression = selectExpressions.get(i);
if (expression.evaluate(result, ptr)) {
values[i] = ptr.copyBytes();
// If ColumnModifier from expression in SELECT doesn't match the
// column being projected into then invert the bits.
if (expression.getColumnModifier() != projectedColumns.get(i).getColumnModifier()) {
ColumnModifier.SORT_DESC.apply(values[i], 0, values[i], 0, values[i].length);
}
}
}
projectedTable.newKey(ptr, values);
PRow row = projectedTable.newRow(ts, ptr);
for (; i < projectedColumns.size(); i++) {
Expression expression = selectExpressions.get(i);
if (expression.evaluate(result, ptr)) {
PColumn column = projectedColumns.get(i);
byte[] bytes = ptr.copyBytes();
Object value = expression.getDataType().toObject(bytes, column.getColumnModifier());
// If ColumnModifier from expression in SELECT doesn't match the
// column being projected into then invert the bits.
if (expression.getColumnModifier() != column.getColumnModifier()) {
ColumnModifier.SORT_DESC.apply(bytes, 0, bytes, 0, bytes.length);
}
// We are guaranteed that the two column will have the same type.
if (!column.getDataType().isSizeCompatible(column.getDataType(),
value, bytes,
expression.getMaxLength(), column.getMaxLength(),
expression.getScale(), column.getScale())) {
throw new ValueTypeIncompatibleException(column.getDataType(),
column.getMaxLength(), column.getScale());
}
bytes = column.getDataType().coerceBytes(bytes, value, expression.getDataType(),
expression.getMaxLength(), expression.getScale(), column.getMaxLength(), column.getScale());
row.setValue(column, bytes);
}
}
for (Mutation mutation : row.toRowMutations()) {
mutations.add(new Pair<Mutation,Integer>(mutation,null));
}
} else if (deleteCF != null && deleteCQ != null) {
// No need to search for delete column, since we project only it
// if no empty key value is being set
if (emptyCF == null || result.getValue(deleteCF, deleteCQ) != null) {
Delete delete = new Delete(results.get(0).getRow());
delete.deleteColumns(deleteCF, deleteCQ, ts);
mutations.add(new Pair<Mutation,Integer>(delete,null));
}
}