Search in sources :

Example 1 with FirstLastNthValueDataContainer

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();
        }
    }
}
Also used : FirstLastNthValueDataContainer(org.apache.phoenix.util.FirstLastNthValueDataContainer) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) LinkedList(java.util.LinkedList) BinaryComparator(org.apache.hadoop.hbase.filter.BinaryComparator)

Example 2 with FirstLastNthValueDataContainer

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;
}
Also used : FirstLastNthValueDataContainer(org.apache.phoenix.util.FirstLastNthValueDataContainer) IOException(java.io.IOException) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)2 FirstLastNthValueDataContainer (org.apache.phoenix.util.FirstLastNthValueDataContainer)2 IOException (java.io.IOException)1 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)1 SingleKeyValueTuple (org.apache.phoenix.schema.tuple.SingleKeyValueTuple)1