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.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.type.BigintType.BIGINT;
 import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
 import static com.facebook.presto.util.Reflection.method;
 
 public class CountColumn
         extends ParametricAggregation
 {
     public static final CountColumn COUNT_COLUMN = new CountColumn();
     private static final String NAME = "count";
     private static final Signature SIGNATURE = new Signature(, ImmutableList.of(typeParameter("T")), ., ImmutableList.of("T"), falsefalse);
     private static final Method INPUT_FUNCTION = method(CountColumn.class"input"LongState.classBlock.classint.class);
     private static final Method COMBINE_FUNCTION = method(CountColumn.class"combine"LongState.classLongState.class);
 
     @Override
     public Signature getSignature()
     {
         return ;
     }
 
     @Override
     public String getDescription()
     {
         return "Counts the non-null values";
     }
 
     @Override
     public FunctionInfo specialize(Map<StringTypetypesint arityTypeManager typeManagerFunctionRegistry functionRegistry)
     {
         Type type = types.get("T");
         Signature signature = new Signature(parseTypeSignature(.), type.getTypeSignature());
         InternalAggregationFunction aggregation = generateAggregation(type);
         return new FunctionInfo(signaturegetDescription(), aggregation.getIntermediateType().getTypeSignature(), aggregationfalse);
     }
 
     private static InternalAggregationFunction generateAggregation(Type type)
     {
         DynamicClassLoader classLoader = new DynamicClassLoader(CountColumn.class.getClassLoader());
 
         AccumulatorStateSerializer<LongStatestateSerializer = new StateCompiler().generateStateSerializer(LongState.classclassLoader);
         AccumulatorStateFactory<LongStatestateFactory = new StateCompiler().generateStateFactory(LongState.classclassLoader);
         Type intermediateType = stateSerializer.getSerializedType();
 
         List<TypeinputTypes = ImmutableList.of(type);
 
         AggregationMetadata metadata = new AggregationMetadata(
                 generateAggregationName(inputTypes),
                 createInputParameterMetadata(type),
                 ,
                 null,
                 null,
                 ,
                 null,
                 LongState.class,
                 stateSerializer,
                 stateFactory,
                 ,
                 false);
 
         GenericAccumulatorFactoryBinder factory = new AccumulatorCompiler().generateAccumulatorFactoryBinder(metadataclassLoader);
        return new InternalAggregationFunction(inputTypesintermediateTypetruefalsefactory);
    }
    {
        return ImmutableList.of(new ParameterMetadata(), new ParameterMetadata(type), new ParameterMetadata());
    }
    public static void input(LongState stateBlock blockint index)
    {
        state.setLong(state.getLong() + 1);
    }
    public static void combine(LongState stateLongState otherState)
    {
        state.setLong(state.getLong() + otherState.getLong());
    }
New to GrepCode? Check out our FAQ X