Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.operator.aggregation;
import static com.facebook.presto.spi.type.StandardTypes.BIGINT;
import static com.facebook.presto.spi.type.StandardTypes.DOUBLE;
@AggregationFunction("numeric_histogram")
    public static final int ENTRY_BUFFER_SIZE = 100;
    {
    }
    @AccumulatorStateMetadata(stateSerializerClass = NumericHistogramStateSerializer.class, stateFactoryClass = NumericHistogramStateFactory.class)
    public interface State
            extends AccumulatorState
    {
        @NotNull
        NumericHistogram get();
        void set(NumericHistogram value);
    }
    public static void add(State state, @SqlType(long buckets, @SqlType(double value, @SqlType(double weight)
    {
        NumericHistogram histogram = state.get();
        if (histogram == null) {
            histogram = new NumericHistogram(Ints.checkedCast(buckets), );
            state.set(histogram);
        }
        histogram.add(valueweight);
    }
    public static void add(State state, @SqlType(long buckets, @SqlType(double value)
    {
        add(statebucketsvalue, 1);
    }
    public static void merge(State stateState other)
    {
        NumericHistogram input = other.get();
        NumericHistogram previous = state.get();
        if (previous == null) {
            state.set(input);
        }
        else {
            previous.mergeWith(input);
        }
    }
    @OutputFunction("map<double,double>")
    public static void output(State stateBlockBuilder out)
    {
        if (state.get() == null) {
            out.appendNull();
        }
        else {
            Slice slice = MapType.toStackRepresentation(state.get().getBuckets());
            out.writeBytes(slice, 0, slice.length());
            out.closeEntry();
        }
    }
New to GrepCode? Check out our FAQ X