Search in sources :

Example 6 with ExceededMemoryLimitException

use of com.facebook.presto.ExceededMemoryLimitException in project presto by prestodb.

the class MapAggregationFunction method combine.

public static void combine(KeyValuePairsState state, KeyValuePairsState otherState) {
    if (state.get() != null && otherState.get() != null) {
        Block keys = otherState.get().getKeys();
        Block values = otherState.get().getValues();
        KeyValuePairs pairs = state.get();
        long startSize = pairs.estimatedInMemorySize();
        for (int i = 0; i < keys.getPositionCount(); i++) {
            try {
                pairs.add(keys, values, i, i);
            } catch (ExceededMemoryLimitException e) {
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("The result of map_agg may not exceed %s", e.getMaxMemory()));
            }
        }
        state.addMemoryUsage(pairs.estimatedInMemorySize() - startSize);
    } else if (state.get() == null) {
        state.set(otherState.get());
    }
}
Also used : Block(com.facebook.presto.spi.block.Block) PrestoException(com.facebook.presto.spi.PrestoException) ExceededMemoryLimitException(com.facebook.presto.ExceededMemoryLimitException)

Aggregations

ExceededMemoryLimitException (com.facebook.presto.ExceededMemoryLimitException)6 PrestoException (com.facebook.presto.spi.PrestoException)6 Block (com.facebook.presto.spi.block.Block)2