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 java.util.List;
 import java.util.Map;
 
 import static com.facebook.presto.metadata.Signature.orderableTypeParameter;
 import static com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata;
 import static com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL;
 import static com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata.ParameterType.STATE;
 import static com.facebook.presto.operator.aggregation.AggregationUtils.generateAggregationName;
 import static com.facebook.presto.spi.StandardErrorCode.INTERNAL_ERROR;
 import static com.facebook.presto.util.Reflection.methodHandle;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 public abstract class AbstractMinMaxAggregation
         extends ParametricAggregation
 {
     private static final MethodHandle LONG_INPUT_FUNCTION = methodHandle(AbstractMinMaxAggregation.class"input"MethodHandle.classNullableLongState.classlong.class);
     private static final MethodHandle DOUBLE_INPUT_FUNCTION = methodHandle(AbstractMinMaxAggregation.class"input"MethodHandle.classNullableDoubleState.classdouble.class);
     private static final MethodHandle SLICE_INPUT_FUNCTION = methodHandle(AbstractMinMaxAggregation.class"input"MethodHandle.classSliceState.classSlice.class);
     private static final MethodHandle BOOLEAN_INPUT_FUNCTION = methodHandle(AbstractMinMaxAggregation.class"input"MethodHandle.classNullableBooleanState.classboolean.class);
 
     private final String name;
     private final OperatorType operatorType;
     private final Signature signature;
 
     private final StateCompiler compiler = new StateCompiler();
 
     protected AbstractMinMaxAggregation(String nameOperatorType operatorType)
     {
         checkNotNull(name);
         checkNotNull(operatorType);
         this. = name;
         this. = operatorType;
         this. = new Signature(name, ImmutableList.of(orderableTypeParameter("E")), "E", ImmutableList.of("E"), falsefalse);
     }
 
     @Override
     public Signature getSignature()
     {
         return ;
     }
 
     @Override
     public FunctionInfo specialize(Map<StringTypetypesint arityTypeManager typeManagerFunctionRegistry functionRegistry)
     {
         Type type = types.get("E");
         MethodHandle compareMethodHandle = functionRegistry.resolveOperator(, ImmutableList.of(typetype)).getMethodHandle();
         Signature signature = new Signature(type.getTypeSignature(), type.getTypeSignature());
         InternalAggregationFunction aggregation = generateAggregation(typecompareMethodHandle);
         return new FunctionInfo(signaturegetDescription(), aggregation.getIntermediateType().getTypeSignature(), aggregationfalse);
     }
 
     protected InternalAggregationFunction generateAggregation(Type typeMethodHandle compareMethodHandle)
     {
         DynamicClassLoader classLoader = new DynamicClassLoader(AbstractMinMaxAggregation.class.getClassLoader());
 
         List<TypeinputTypes = ImmutableList.of(type);
 
        AccumulatorStateSerializer stateSerializer;
        AccumulatorStateFactory stateFactory;
        MethodHandle inputFunction;
        Class<? extends AccumulatorStatestateInterface;
        if (type.getJavaType() == long.class) {
            stateFactory = .generateStateFactory(NullableLongState.classclassLoader);
            stateSerializer = new NullableLongStateSerializer(type);
            stateInterface = NullableLongState.class;
            inputFunction = ;
        }
        else if (type.getJavaType() == double.class) {
            stateFactory = .generateStateFactory(NullableDoubleState.classclassLoader);
            stateSerializer = new NullableDoubleStateSerializer(type);
            stateInterface = NullableDoubleState.class;
            inputFunction = ;
        }
        else if (type.getJavaType() == Slice.class) {
            stateFactory = .generateStateFactory(SliceState.classclassLoader);
            stateSerializer = new SliceStateSerializer(type);
            stateInterface = SliceState.class;
            inputFunction = ;
        }
        else if (type.getJavaType() == boolean.class) {
            stateFactory = .generateStateFactory(NullableBooleanState.classclassLoader);
            stateSerializer = new NullableBooleanStateSerializer(type);
            stateInterface = NullableBooleanState.class;
            inputFunction = ;
        }
        else {
            throw new PrestoException(."Argument type to max/min unsupported");
        }
        inputFunction = inputFunction.bindTo(compareMethodHandle);
        Type intermediateType = stateSerializer.getSerializedType();
        List<ParameterMetadatainputParameterMetadata = createInputParameterMetadata(type);
        AggregationMetadata metadata = new AggregationMetadata(
                generateAggregationName(typeinputTypes),
                inputParameterMetadata,
                inputFunction,
                inputParameterMetadata,
                inputFunction,
                null,
                null,
                stateInterface,
                stateSerializer,
                stateFactory,
                type,
                false);
        GenericAccumulatorFactoryBinder factory = new AccumulatorCompiler().generateAccumulatorFactoryBinder(metadataclassLoader);
        return new InternalAggregationFunction(inputTypesintermediateTypetypetruefalsefactory);
    }
    {
        return ImmutableList.of(
                new ParameterMetadata(),
                new ParameterMetadata(type));
    }
    public static void input(MethodHandle methodHandleNullableDoubleState statedouble value)
    {
        if (state.isNull()) {
            state.setNull(false);
            state.setDouble(value);
            return;
        }
        try {
            if ((booleanmethodHandle.invokeExact(valuestate.getDouble())) {
                state.setDouble(value);
            }
        }
        catch (Throwable t) {
            Throwables.propagateIfInstanceOf(tError.class);
            Throwables.propagateIfInstanceOf(tPrestoException.class);
            throw new PrestoException(t);
        }
    }
    public static void input(MethodHandle methodHandleNullableLongState statelong value)
    {
        if (state.isNull()) {
            state.setNull(false);
            state.setLong(value);
            return;
        }
        try {
            if ((booleanmethodHandle.invokeExact(valuestate.getLong())) {
                state.setLong(value);
            }
        }
        catch (Throwable t) {
            Throwables.propagateIfInstanceOf(tError.class);
            Throwables.propagateIfInstanceOf(tPrestoException.class);
            throw new PrestoException(t);
        }
    }
    public static void input(MethodHandle methodHandleSliceState stateSlice value)
    {
        if (state.getSlice() == null) {
            state.setSlice(value);
            return;
        }
        try {
            if ((booleanmethodHandle.invokeExact(valuestate.getSlice())) {
                state.setSlice(value);
            }
        }
        catch (Throwable t) {
            Throwables.propagateIfInstanceOf(tError.class);
            Throwables.propagateIfInstanceOf(tPrestoException.class);
            throw new PrestoException(t);
        }
    }
    public static void input(MethodHandle methodHandleNullableBooleanState stateboolean value)
    {
        if (state.isNull()) {
            state.setNull(false);
            state.setBoolean(value);
            return;
        }
        try {
            if ((booleanmethodHandle.invokeExact(valuestate.getBoolean())) {
                state.setBoolean(value);
            }
        }
        catch (Throwable t) {
            Throwables.propagateIfInstanceOf(tError.class);
            Throwables.propagateIfInstanceOf(tPrestoException.class);
            throw new PrestoException(t);
        }
    }
New to GrepCode? Check out our FAQ X