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.typeParameter;
 import static com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata;
 import static com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata.ParameterType.BLOCK_INDEX;
 import static com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata.ParameterType.BLOCK_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.util.Reflection.methodHandle;
 
 public class ArbitraryAggregation
         extends ParametricAggregation
 {
     public static final ArbitraryAggregation ARBITRARY_AGGREGATION = new ArbitraryAggregation();
     private static final String NAME = "arbitrary";
     private static final MethodHandle OUTPUT_FUNCTION = methodHandle(ArbitraryAggregation.class"output"ArbitraryAggregationState.classBlockBuilder.class);
     private static final MethodHandle INPUT_FUNCTION = methodHandle(ArbitraryAggregation.class"input"ArbitraryAggregationState.classBlock.classint.class);
     private static final MethodHandle COMBINE_FUNCTION = methodHandle(ArbitraryAggregation.class"combine"ArbitraryAggregationState.classArbitraryAggregationState.class);
     private static final Signature SIGNATURE = new Signature(, ImmutableList.of(typeParameter("T")), "T", ImmutableList.of("T"), falsefalse);
 
     @Override
     public Signature getSignature()
     {
         return ;
     }
 
     @Override
     public String getDescription()
     {
         return "return an arbitrary non-null input value";
     }
 
     @Override
     public FunctionInfo specialize(Map<StringTypetypesint arityTypeManager typeManagerFunctionRegistry functionRegistry)
     {
         Type valueType = types.get("T");
         Signature signature = new Signature(valueType.getTypeSignature(), valueType.getTypeSignature());
         InternalAggregationFunction aggregation = generateAggregation(valueType);
         return new FunctionInfo(signaturegetDescription(), aggregation);
     }
 
     private static InternalAggregationFunction generateAggregation(Type valueType)
     {
         DynamicClassLoader classLoader = new DynamicClassLoader(ArbitraryAggregation.class.getClassLoader());
 
         ArbitraryAggregationStateSerializer stateSerializer = new ArbitraryAggregationStateSerializer();
         Type intermediateType = stateSerializer.getSerializedType();
 
         List<TypeinputTypes = ImmutableList.of(valueType);
 
         ArbitraryAggregationStateFactory stateFactory = new ArbitraryAggregationStateFactory(valueType);
         AggregationMetadata metadata = new AggregationMetadata(
                 generateAggregationName(valueTypeinputTypes),
                 createInputParameterMetadata(valueType),
                 ,
                 null,
                 null,
                 ,
                 ,
                 ArbitraryAggregationState.class,
                 stateSerializer,
                 stateFactory,
                 valueType,
                 false);
 
         GenericAccumulatorFactoryBinder factory = new AccumulatorCompiler().generateAccumulatorFactoryBinder(metadataclassLoader);
         return new InternalAggregationFunction(inputTypesintermediateTypevalueTypetruefalsefactory);
     }
    private static List<ParameterMetadatacreateInputParameterMetadata(Type value)
    {
        return ImmutableList.of(new ParameterMetadata(), new ParameterMetadata(value), new ParameterMetadata());
    }
    public static void input(ArbitraryAggregationState stateBlock valueint position)
    {
        if (state.getValue() == null) {
            state.setValue(value.getSingleValueBlock(position));
        }
    }
    public static void combine(ArbitraryAggregationState stateArbitraryAggregationState otherState)
    {
        if (state.getValue() == null && otherState.getValue() != null) {
            state.setValue(otherState.getValue());
        }
    }
    public static void output(ArbitraryAggregationState stateBlockBuilder out)
    {
        if (state.getValue() == null) {
            out.appendNull();
        }
        else {
            state.getType().appendTo(state.getValue(), 0, out);
        }
    }
New to GrepCode? Check out our FAQ X