use of org.apache.phoenix.util.FirstLastNthValueDataContainer in project phoenix by apache.
the class FirstLastValueBaseClientAggregator method aggregate.
@Override
public void aggregate(Tuple tuple, ImmutableBytesWritable ptr) {
//if is called cause aggregation in ORDER BY clausule
if (tuple instanceof SingleKeyValueTuple) {
topValue = ptr.copyBytes();
return;
}
FirstLastNthValueDataContainer payload = new FirstLastNthValueDataContainer();
payload.setPayload(ptr.copyBytes());
isAscending = payload.getIsAscending();
TreeMap<byte[], LinkedList<byte[]>> serverAggregatorResult = payload.getData();
if (useOffset) {
//merge topValues
for (Entry<byte[], LinkedList<byte[]>> entry : serverAggregatorResult.entrySet()) {
byte[] itemKey = entry.getKey();
LinkedList<byte[]> itemList = entry.getValue();
if (topValues.containsKey(itemKey)) {
topValues.get(itemKey).addAll(itemList);
} else {
topValues.put(itemKey, itemList);
}
}
} else {
Entry<byte[], LinkedList<byte[]>> valueEntry = serverAggregatorResult.firstEntry();
byte[] currentOrder = valueEntry.getKey();
boolean isBetter;
if (isAscending) {
isBetter = topOrder.compareTo(currentOrder) > 0;
} else {
//desc
isBetter = topOrder.compareTo(currentOrder) < 0;
}
if (topOrder.getValue().length < 1 || isBetter) {
topOrder = new BinaryComparator(currentOrder);
topValue = valueEntry.getValue().getFirst();
}
}
}
use of org.apache.phoenix.util.FirstLastNthValueDataContainer in project phoenix by apache.
the class FirstLastValueServerAggregator method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
FirstLastNthValueDataContainer payload = new FirstLastNthValueDataContainer();
payload.setIsAscending(isAscending);
payload.setFixedWidthOrderValues(orderByColumn.getDataType().isFixedWidth());
payload.setFixedWidthDataValues(dataColumn.getDataType().isFixedWidth());
if (useOffset) {
payload.setOffset(offset);
if (topValuesCount == 0) {
return false;
}
} else {
if (topValue == null) {
return false;
}
LinkedList<byte[]> topValueList = new LinkedList<byte[]>();
topValueList.push(topValue);
topValues.put(topOrder.getValue(), topValueList);
}
payload.setData(topValues);
try {
ptr.set(payload.getPayload());
} catch (IOException ex) {
logger.error(ex.getMessage());
return false;
}
return true;
}
Aggregations