You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2013/04/29 17:12:40 UTC

svn commit: r1477136 [1/4] - in /hive/branches/vectorization/ql/src: java/org/apache/hadoop/hive/ql/exec/vector/ java/org/apache/hadoop/hive/ql/exec/vector/expressions/ java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/ java/org/apache/...

Author: hashutosh
Date: Mon Apr 29 15:12:39 2013
New Revision: 1477136

URL: http://svn.apache.org/r1477136
Log:
HIVE-4381 : Implement vectorized aggregation expressions (Remus Rusanu via Ashutosh Chauhan)

Added:
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupByOperator.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ColumnExpression.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorAggregateExpression.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgDouble.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgLong.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFCountDouble.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFCountLong.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMaxDouble.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMaxLong.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMinDouble.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMinLong.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFStdPopDouble.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFStdPopLong.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFStdSampDouble.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFStdSampLong.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFSumDouble.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFSumLong.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFVarPopDouble.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFVarPopLong.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFVarSampDouble.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFVarSampLong.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFCount.txt
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFMinMax.txt
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFSum.txt
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/VectorUDAFVar.txt
    hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorGroupByOperator.java
    hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/util/
    hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/util/FakeCaptureOutputDesc.java
    hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/util/FakeCaptureOutputOperator.java
    hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/util/FakeVectorDataSourceOperator.java
    hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/util/FakeVectorDataSourceOperatorDesc.java
    hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/util/FakeVectorRowBatchBase.java
    hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/util/FakeVectorRowBatchFromConcat.java
    hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/util/FakeVectorRowBatchFromIterables.java
    hive/branches/vectorization/ql/src/test/org/apache/hadoop/hive/ql/exec/vector/util/FakeVectorRowBatchFromRepeats.java
Modified:
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/templates/CodeGen.java

Added: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupByOperator.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupByOperator.java?rev=1477136&view=auto
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupByOperator.java (added)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupByOperator.java Mon Apr 29 15:12:39 2013
@@ -0,0 +1,134 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.hadoop.hive.ql.exec.vector;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.ql.exec.Operator;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates
+    .VectorAggregateExpression.AggregationBuffer;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.plan.AggregationDesc;
+import org.apache.hadoop.hive.ql.plan.GroupByDesc;
+import org.apache.hadoop.hive.ql.plan.OperatorDesc;
+import org.apache.hadoop.hive.ql.plan.api.OperatorType;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+
+/**
+ * Vectorized GROUP BY operator impelementation. Consumes the vectorized input and
+ * stores the aggregates operators intermediate states. Emits row mode output.
+ *
+ */
+public class VectorGroupByOperator extends Operator<GroupByDesc> implements Serializable {
+
+  private final VectorizationContext vContext;
+
+  protected transient VectorAggregateExpression[] aggregators;
+  protected transient AggregationBuffer[] aggregationBuffers;
+
+  transient int heartbeatInterval;
+  transient int countAfterReport;
+
+  private static final long serialVersionUID = 1L;
+
+  public VectorGroupByOperator(VectorizationContext ctxt, OperatorDesc conf) {
+    super();
+    this.vContext = ctxt;
+    this.conf = (GroupByDesc) conf;
+  }
+
+  @Override
+  protected void initializeOp(Configuration hconf) throws HiveException {
+
+    List<ObjectInspector> objectInspectors = new ArrayList<ObjectInspector>();
+
+    try {
+      vContext.setOperatorType(OperatorType.GROUPBY);
+
+      ArrayList<AggregationDesc> aggrDesc = conf.getAggregators();
+
+      aggregators = new VectorAggregateExpression[aggrDesc.size()];
+      aggregationBuffers = new AggregationBuffer[aggrDesc.size()];
+      for (int i = 0; i < aggrDesc.size(); ++i) {
+        AggregationDesc desc = aggrDesc.get(i);
+        aggregators[i] = vContext.getAggregatorExpression (desc);
+        aggregationBuffers[i] = aggregators[i].getNewAggregationBuffer();
+        aggregators[i].reset(aggregationBuffers[i]);
+
+        objectInspectors.add(aggregators[i].getOutputObjectInspector());
+      }
+
+      List<String> outputFieldNames = conf.getOutputColumnNames();
+      outputObjInspector = ObjectInspectorFactory.getStandardStructObjectInspector(
+          outputFieldNames, objectInspectors);
+
+    } catch (HiveException he) {
+      throw he;
+    } catch (Throwable e) {
+      throw new HiveException(e);
+    }
+    initializeChildren(hconf);
+  }
+
+  @Override
+  public void processOp(Object row, int tag) throws HiveException {
+    VectorizedRowBatch vrg = (VectorizedRowBatch) row;
+
+    //TODO: proper group by hash
+    for (int i = 0; i < aggregators.length; ++i) {
+      aggregators[i].aggregateInput(aggregationBuffers[i], vrg);
+    }
+  }
+
+  @Override
+  public void closeOp(boolean aborted) throws HiveException {
+    if (!aborted) {
+      Object[] forwardCache = new Object[aggregators.length];
+      for (int i = 0; i < aggregators.length; ++i) {
+        forwardCache[i] = aggregators[i].evaluateOutput(aggregationBuffers[i]);
+      }
+      forward(forwardCache, outputObjInspector);
+    }
+  }
+
+  /**
+   * @return the name of the operator
+   */
+  @Override
+  public String getName() {
+    return getOperatorName();
+  }
+
+  static public String getOperatorName() {
+    return "GBY";
+  }
+
+  @Override
+  public OperatorType getType() {
+    return OperatorType.GROUPBY;
+  }
+
+}
+

Modified: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java?rev=1477136&r1=1477135&r2=1477136&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java (original)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java Mon Apr 29 15:12:39 2013
@@ -27,6 +27,7 @@ import java.util.Map;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hive.ql.exec.UDF;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.ColumnExpression;
 import org.apache.hadoop.hive.ql.exec.vector.expressions.FilterExprAndExpr;
 import org.apache.hadoop.hive.ql.exec.vector.expressions.FilterExprOrExpr;
 import org.apache.hadoop.hive.ql.exec.vector.expressions.FilterNotExpr;
@@ -36,7 +37,27 @@ import org.apache.hadoop.hive.ql.exec.ve
 import org.apache.hadoop.hive.ql.exec.vector.expressions.SelectColumnIsNull;
 import org.apache.hadoop.hive.ql.exec.vector.expressions.SelectColumnIsTrue;
 import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFAvgDouble;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFAvgLong;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFCountDouble;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFCountLong;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMaxDouble;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMaxLong;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMinDouble;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMinLong;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFStdPopDouble;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFStdPopLong;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFStdSampDouble;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFStdSampLong;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFSumDouble;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFSumLong;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFVarPopDouble;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFVarPopLong;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFVarSampDouble;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFVarSampLong;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.plan.AggregationDesc;
 import org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc;
 import org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc;
 import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
@@ -66,8 +87,13 @@ import org.apache.hadoop.hive.serde2.obj
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
 import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
 
+/**
+ * Context class for vectorization execution.
+ * Main role is to map column names to column indices and serves as a
+ * factory class for building vectorized expressions out of descriptors.
+ *
+ */
 public class VectorizationContext {
-
   private static final Log LOG = LogFactory.getLog(
       VectorizationContext.class.getName());
 
@@ -85,7 +111,7 @@ public class VectorizationContext {
     this.nextOutputColumn = initialOutputCol;
     this.outputColumnTypes = new HashMap<Integer, String>();
   }
-
+  
   public int allocateOutputColumn (String columnName, String columnType) {
     int newColumnIndex = nextOutputColumn++;
     columnMap.put(columnName, newColumnIndex);
@@ -748,6 +774,77 @@ public class VectorizationContext {
     return b.toString();
   }
 
+  static Object[][] aggregatesDefinition = {
+    {"min",       "Long",   VectorUDAFMinLong.class},
+    {"min",       "Double", VectorUDAFMinDouble.class},
+    {"max",       "Long",   VectorUDAFMaxLong.class},
+    {"max",       "Double", VectorUDAFMaxDouble.class},
+    {"count",     "Long",   VectorUDAFCountLong.class},
+    {"count",     "Double", VectorUDAFCountDouble.class},
+    {"sum",       "Long",   VectorUDAFSumLong.class},
+    {"sum",       "Double", VectorUDAFSumDouble.class},
+    {"avg",       "Long",   VectorUDAFAvgLong.class},
+    {"avg",       "Double", VectorUDAFAvgDouble.class},
+    {"variance",  "Long",   VectorUDAFVarPopLong.class},
+    {"var_pop",   "Long",   VectorUDAFVarPopLong.class},
+    {"variance",  "Double", VectorUDAFVarPopDouble.class},
+    {"var_pop",   "Double", VectorUDAFVarPopDouble.class},
+    {"var_samp",  "Long",   VectorUDAFVarSampLong.class},
+    {"var_samp" , "Double", VectorUDAFVarSampDouble.class},
+    {"std",       "Long",   VectorUDAFStdPopLong.class},
+    {"stddev",    "Long",   VectorUDAFStdPopLong.class},
+    {"stddev_pop","Long",   VectorUDAFStdPopLong.class},
+    {"std",       "Long",   VectorUDAFStdPopDouble.class},
+    {"stddev",    "Long",   VectorUDAFStdPopDouble.class},
+    {"stddev_pop","Long",   VectorUDAFStdPopDouble.class},
+    {"stddev_samp","Long",  VectorUDAFStdSampLong.class},
+    {"stddev_samp","Double",VectorUDAFStdSampDouble.class},
+  };
+  
+  public VectorAggregateExpression getAggregatorExpression(AggregationDesc desc) 
+      throws HiveException {
+    ArrayList<ExprNodeDesc> paramDescList = desc.getParameters();
+    VectorExpression[] vectorParams = new VectorExpression[paramDescList.size()];
+
+    for (int i = 0; i< paramDescList.size(); ++i) {
+      ExprNodeDesc exprDesc = paramDescList.get(i);
+      vectorParams[i] = this.getVectorExpression(exprDesc);
+    }
+    
+    String aggregateName = desc.getGenericUDAFName();
+    List<ExprNodeDesc> params = desc.getParameters();
+    //TODO: handle length != 1
+    assert (params.size() == 1);
+    ExprNodeDesc inputExpr = params.get(0);
+    String inputType = getNormalizedTypeName(inputExpr.getTypeString());
+
+    for (Object[] aggDef : aggregatesDefinition) {
+      if (aggDef[0].equals (aggregateName) &&
+          aggDef[1].equals(inputType)) {
+        Class<? extends VectorAggregateExpression> aggClass = 
+            (Class<? extends VectorAggregateExpression>) (aggDef[2]);
+        try
+        {
+          Constructor<? extends VectorAggregateExpression> ctor = 
+              aggClass.getConstructor(VectorExpression.class);
+          VectorAggregateExpression aggExpr = ctor.newInstance(vectorParams[0]);
+          return aggExpr;
+        }
+        // TODO: change to 1.7 syntax when possible
+        //catch (InvocationTargetException | IllegalAccessException 
+        // | NoSuchMethodException | InstantiationException)
+        catch (Exception e)
+        {
+          throw new HiveException("Internal exception for vector aggregate : \"" + 
+               aggregateName + "\" for type: \"" + inputType + "", e);
+        }
+      }
+    }
+
+    throw new HiveException("Vector aggregate not implemented: \"" + aggregateName + 
+        "\" for type: \"" + inputType + "");
+  }
+  
   static Object[][] columnTypes = {
     {"Double",  DoubleColumnVector.class},
     {"Long",    LongColumnVector.class},
@@ -808,3 +905,4 @@ public class VectorizationContext {
     return ObjectInspectorFactory.getStandardStructObjectInspector(columnNames, oids);
   }
 }
+

Added: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ColumnExpression.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ColumnExpression.java?rev=1477136&view=auto
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ColumnExpression.java (added)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ColumnExpression.java Mon Apr 29 15:12:39 2013
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.hadoop.hive.ql.exec.vector.expressions;
+
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+
+/**
+ * Vector column project. It's evaluation is a no-op.
+ *
+ */
+public class ColumnExpression extends VectorExpression {
+
+  private int colNum;
+  private String colType;
+
+  public ColumnExpression(int colNum, String colType) {
+    this.colNum = colNum;
+    this.colType = colType;
+  }
+
+  public void evaluate(VectorizedRowBatch vrg) {
+    //do nothing
+  }
+
+  @Override
+  public int getOutputColumn() {
+    return colNum;
+  }
+
+  @Override
+  public String getOutputType() {
+    return colType;
+  }
+}
+

Added: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorAggregateExpression.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorAggregateExpression.java?rev=1477136&view=auto
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorAggregateExpression.java (added)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorAggregateExpression.java Mon Apr 29 15:12:39 2013
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates;
+
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+
+public abstract class VectorAggregateExpression  {
+  
+  public static interface AggregationBuffer {
+  }; 
+
+  public abstract AggregationBuffer getNewAggregationBuffer() throws HiveException;
+  public abstract void aggregateInput(AggregationBuffer agg, VectorizedRowBatch unit)
+        throws HiveException;
+  public abstract void reset(AggregationBuffer agg) throws HiveException;
+  public abstract Object evaluateOutput(AggregationBuffer agg) throws HiveException;
+
+  public abstract ObjectInspector getOutputObjectInspector();
+}
+

Added: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgDouble.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgDouble.java?rev=1477136&view=auto
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgDouble.java (added)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgDouble.java Mon Apr 29 15:12:39 2013
@@ -0,0 +1,242 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen;
+
+import java.util.ArrayList;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.
+    VectorAggregateExpression.AggregationBuffer;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.StructField;
+import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
+import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
+
+/**
+* VectorUDAFAvgDouble. Vectorized implementation for AVG aggregates. 
+*/
+@Description(name = "avg", value = "_FUNC_(expr) - Returns the average value of expr (vectorized, type: double)")
+public class VectorUDAFAvgDouble extends VectorAggregateExpression {
+    
+    /** 
+    /* class for storing the current aggregate value.
+    */
+    static private final class Aggregation implements AggregationBuffer {
+      double sum;
+      long count;
+      boolean isNull;
+    }
+    
+    private VectorExpression inputExpression;
+    private Object[] partialResult;
+    private LongWritable resultCount;
+    private DoubleWritable resultSum;
+    private StructObjectInspector soi;
+        
+    public VectorUDAFAvgDouble(VectorExpression inputExpression) {
+      super();
+      this.inputExpression = inputExpression;
+      partialResult = new Object[2];
+      partialResult[0] = resultCount = new LongWritable();
+      partialResult[1] = resultSum = new DoubleWritable();
+      
+      initPartialResultInspector();
+    }
+
+  private void initPartialResultInspector () {
+      ArrayList<ObjectInspector> foi = new ArrayList<ObjectInspector>();
+        foi.add(PrimitiveObjectInspectorFactory.writableLongObjectInspector);
+        foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
+        ArrayList<String> fname = new ArrayList<String>();
+        fname.add("count");
+        fname.add("sum");
+        soi = ObjectInspectorFactory.getStandardStructObjectInspector(fname, foi);
+    }
+    
+    
+    @Override
+    public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch unit) 
+    throws HiveException {
+      
+      inputExpression.evaluate(unit);
+      
+      DoubleColumnVector inputVector = (DoubleColumnVector)unit.
+      cols[this.inputExpression.getOutputColumn()];
+      
+      int batchSize = unit.size;
+      
+      if (batchSize == 0) {
+        return;
+      }
+      
+      Aggregation myagg = (Aggregation)agg;
+
+      double[] vector = inputVector.vector;
+      
+      if (inputVector.isRepeating) {
+        if (inputVector.noNulls || !inputVector.isNull[0]) {
+          if (myagg.isNull) {
+            myagg.isNull = false;
+            myagg.sum = 0;
+            myagg.count = 0;
+          }
+          myagg.sum += vector[0]*batchSize;
+          myagg.count += batchSize;
+        }
+        return;
+      }
+      
+      if (!unit.selectedInUse && inputVector.noNulls) {
+        iterateNoSelectionNoNulls(myagg, vector, batchSize);
+      }
+      else if (!unit.selectedInUse) {
+        iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull);
+      }
+      else if (inputVector.noNulls){
+        iterateSelectionNoNulls(myagg, vector, batchSize, unit.selected);
+      }
+      else {
+        iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, unit.selected);
+      }
+    }
+  
+    private void iterateSelectionHasNulls(
+        Aggregation myagg, 
+        double[] vector, 
+        int batchSize,
+        boolean[] isNull, 
+        int[] selected) {
+      
+      for (int j=0; j< batchSize; ++j) {
+        int i = selected[j];
+        if (!isNull[i]) {
+          double value = vector[i];
+          if (myagg.isNull) {
+            myagg.isNull = false;
+            myagg.sum = 0;
+            myagg.count = 0;
+          }
+          myagg.sum += value;
+          myagg.count += 1;
+        }
+      }
+    }
+
+    private void iterateSelectionNoNulls(
+        Aggregation myagg, 
+        double[] vector, 
+        int batchSize, 
+        int[] selected) {
+      
+      if (myagg.isNull) {
+        myagg.isNull = false;
+        myagg.sum = 0;
+        myagg.count = 0;
+      }
+      
+      for (int i=0; i< batchSize; ++i) {
+        double value = vector[selected[i]];
+        myagg.sum += value;
+        myagg.count += 1;
+      }
+    }
+
+    private void iterateNoSelectionHasNulls(
+        Aggregation myagg, 
+        double[] vector, 
+        int batchSize,
+        boolean[] isNull) {
+      
+      for(int i=0;i<batchSize;++i) {
+        if (!isNull[i]) {
+          double value = vector[i];
+          if (myagg.isNull) { 
+            myagg.isNull = false;
+            myagg.sum = 0;
+            myagg.count = 0;
+          }
+          myagg.sum += value;
+          myagg.count += 1;
+        }
+      }
+    }
+
+    private void iterateNoSelectionNoNulls(
+        Aggregation myagg, 
+        double[] vector, 
+        int batchSize) {
+      if (myagg.isNull) {
+        myagg.isNull = false;
+        myagg.sum = 0;
+        myagg.count = 0;
+      }
+      
+      for (int i=0;i<batchSize;++i) {
+        double value = vector[i];
+        myagg.sum += value;
+        myagg.count += 1;
+      }
+    }
+
+    @Override
+    public AggregationBuffer getNewAggregationBuffer() throws HiveException {
+      return new Aggregation();
+    }
+
+    @Override
+    public void reset(AggregationBuffer agg) throws HiveException {
+      Aggregation myAgg = (Aggregation) agg;
+      myAgg.isNull = true;
+    }
+
+    @Override
+    public Object evaluateOutput(
+        AggregationBuffer agg) throws HiveException {
+      Aggregation myagg = (Aggregation) agg;
+      if (myagg.isNull) {
+        return null;
+      }
+      else {
+        assert(0 < myagg.count);
+        resultCount.set (myagg.count);
+        resultSum.set (myagg.sum);
+        return partialResult;
+      }
+    }
+    
+  @Override
+    public ObjectInspector getOutputObjectInspector() {
+      return soi;
+    }
+}
+

Added: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgLong.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgLong.java?rev=1477136&view=auto
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgLong.java (added)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFAvgLong.java Mon Apr 29 15:12:39 2013
@@ -0,0 +1,242 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen;
+
+import java.util.ArrayList;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.
+    VectorAggregateExpression.AggregationBuffer;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.StructField;
+import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
+import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
+
+/**
+* VectorUDAFAvgLong. Vectorized implementation for AVG aggregates. 
+*/
+@Description(name = "avg", value = "_FUNC_(expr) - Returns the average value of expr (vectorized, type: long)")
+public class VectorUDAFAvgLong extends VectorAggregateExpression {
+    
+    /** 
+    /* class for storing the current aggregate value.
+    */
+    static private final class Aggregation implements AggregationBuffer {
+      long sum;
+      long count;
+      boolean isNull;
+    }
+    
+    private VectorExpression inputExpression;
+    private Object[] partialResult;
+    private LongWritable resultCount;
+    private DoubleWritable resultSum;
+    private StructObjectInspector soi;
+        
+    public VectorUDAFAvgLong(VectorExpression inputExpression) {
+      super();
+      this.inputExpression = inputExpression;
+      partialResult = new Object[2];
+      partialResult[0] = resultCount = new LongWritable();
+      partialResult[1] = resultSum = new DoubleWritable();
+      
+      initPartialResultInspector();
+    }
+
+  private void initPartialResultInspector () {
+      ArrayList<ObjectInspector> foi = new ArrayList<ObjectInspector>();
+        foi.add(PrimitiveObjectInspectorFactory.writableLongObjectInspector);
+        foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
+        ArrayList<String> fname = new ArrayList<String>();
+        fname.add("count");
+        fname.add("sum");
+        soi = ObjectInspectorFactory.getStandardStructObjectInspector(fname, foi);
+    }
+    
+    
+    @Override
+    public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch unit) 
+    throws HiveException {
+      
+      inputExpression.evaluate(unit);
+      
+      LongColumnVector inputVector = (LongColumnVector)unit.
+      cols[this.inputExpression.getOutputColumn()];
+      
+      int batchSize = unit.size;
+      
+      if (batchSize == 0) {
+        return;
+      }
+      
+      Aggregation myagg = (Aggregation)agg;
+
+      long[] vector = inputVector.vector;
+      
+      if (inputVector.isRepeating) {
+        if (inputVector.noNulls || !inputVector.isNull[0]) {
+          if (myagg.isNull) {
+            myagg.isNull = false;
+            myagg.sum = 0;
+            myagg.count = 0;
+          }
+          myagg.sum += vector[0]*batchSize;
+          myagg.count += batchSize;
+        }
+        return;
+      }
+      
+      if (!unit.selectedInUse && inputVector.noNulls) {
+        iterateNoSelectionNoNulls(myagg, vector, batchSize);
+      }
+      else if (!unit.selectedInUse) {
+        iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull);
+      }
+      else if (inputVector.noNulls){
+        iterateSelectionNoNulls(myagg, vector, batchSize, unit.selected);
+      }
+      else {
+        iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, unit.selected);
+      }
+    }
+  
+    private void iterateSelectionHasNulls(
+        Aggregation myagg, 
+        long[] vector, 
+        int batchSize,
+        boolean[] isNull, 
+        int[] selected) {
+      
+      for (int j=0; j< batchSize; ++j) {
+        int i = selected[j];
+        if (!isNull[i]) {
+          long value = vector[i];
+          if (myagg.isNull) {
+            myagg.isNull = false;
+            myagg.sum = 0;
+            myagg.count = 0;
+          }
+          myagg.sum += value;
+          myagg.count += 1;
+        }
+      }
+    }
+
+    private void iterateSelectionNoNulls(
+        Aggregation myagg, 
+        long[] vector, 
+        int batchSize, 
+        int[] selected) {
+      
+      if (myagg.isNull) {
+        myagg.isNull = false;
+        myagg.sum = 0;
+        myagg.count = 0;
+      }
+      
+      for (int i=0; i< batchSize; ++i) {
+        long value = vector[selected[i]];
+        myagg.sum += value;
+        myagg.count += 1;
+      }
+    }
+
+    private void iterateNoSelectionHasNulls(
+        Aggregation myagg, 
+        long[] vector, 
+        int batchSize,
+        boolean[] isNull) {
+      
+      for(int i=0;i<batchSize;++i) {
+        if (!isNull[i]) {
+          long value = vector[i];
+          if (myagg.isNull) { 
+            myagg.isNull = false;
+            myagg.sum = 0;
+            myagg.count = 0;
+          }
+          myagg.sum += value;
+          myagg.count += 1;
+        }
+      }
+    }
+
+    private void iterateNoSelectionNoNulls(
+        Aggregation myagg, 
+        long[] vector, 
+        int batchSize) {
+      if (myagg.isNull) {
+        myagg.isNull = false;
+        myagg.sum = 0;
+        myagg.count = 0;
+      }
+      
+      for (int i=0;i<batchSize;++i) {
+        long value = vector[i];
+        myagg.sum += value;
+        myagg.count += 1;
+      }
+    }
+
+    @Override
+    public AggregationBuffer getNewAggregationBuffer() throws HiveException {
+      return new Aggregation();
+    }
+
+    @Override
+    public void reset(AggregationBuffer agg) throws HiveException {
+      Aggregation myAgg = (Aggregation) agg;
+      myAgg.isNull = true;
+    }
+
+    @Override
+    public Object evaluateOutput(
+        AggregationBuffer agg) throws HiveException {
+      Aggregation myagg = (Aggregation) agg;
+      if (myagg.isNull) {
+        return null;
+      }
+      else {
+        assert(0 < myagg.count);
+        resultCount.set (myagg.count);
+        resultSum.set (myagg.sum);
+        return partialResult;
+      }
+    }
+    
+  @Override
+    public ObjectInspector getOutputObjectInspector() {
+      return soi;
+    }
+}
+

Added: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFCountDouble.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFCountDouble.java?rev=1477136&view=auto
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFCountDouble.java (added)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFCountDouble.java Mon Apr 29 15:12:39 2013
@@ -0,0 +1,162 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen;
+
+import java.util.ArrayList;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.
+    VectorAggregateExpression.AggregationBuffer;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.StructField;
+import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
+
+/**
+* VectorUDAFCountDouble. Vectorized implementation for COUNT aggregates. 
+*/
+@Description(name = "count", value = "_FUNC_(expr) - Returns the maximum value of expr (vectorized, type: double)")
+public class VectorUDAFCountDouble extends VectorAggregateExpression {
+    
+    /** 
+    /* class for storing the current aggregate value.
+    */
+    static class Aggregation implements AggregationBuffer {
+      long value;
+      boolean isNull;
+    }
+    
+    private VectorExpression inputExpression;
+  private LongWritable result;    
+    
+    public VectorUDAFCountDouble(VectorExpression inputExpression) {
+      super();
+      this.inputExpression = inputExpression;
+      result = new LongWritable(0);
+    }
+    
+    @Override
+    public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch unit) 
+    throws HiveException {
+      
+      inputExpression.evaluate(unit);
+      
+      DoubleColumnVector inputVector = (DoubleColumnVector)unit.
+        cols[this.inputExpression.getOutputColumn()];
+      
+      int batchSize = unit.size;
+      
+      if (batchSize == 0) {
+        return;
+      }
+      
+      Aggregation myagg = (Aggregation)agg;
+
+      if (myagg.isNull) {
+        myagg.value = 0;
+        myagg.isNull = false;
+      }
+      
+      if (inputVector.isRepeating) {
+        if (inputVector.noNulls || !inputVector.isNull[0]) {
+          myagg.value += batchSize;
+        }
+        return;
+      }
+      
+      if (inputVector.noNulls) {
+        myagg.value += batchSize;
+        return;
+      }
+      else if (!unit.selectedInUse) {
+        iterateNoSelectionHasNulls(myagg, batchSize, inputVector.isNull);
+      }
+      else {
+        iterateSelectionHasNulls(myagg, batchSize, inputVector.isNull, unit.selected);
+      }
+    }
+  
+    private void iterateSelectionHasNulls(
+        Aggregation myagg, 
+        int batchSize,
+        boolean[] isNull, 
+        int[] selected) {
+      
+      for (int j=0; j< batchSize; ++j) {
+        int i = selected[j];
+        if (!isNull[i]) {
+          myagg.value += 1;
+        }
+      }
+    }
+
+    private void iterateNoSelectionHasNulls(
+        Aggregation myagg, 
+        int batchSize, 
+        boolean[] isNull) {
+      
+      for (int i=0; i< batchSize; ++i) {
+        if (!isNull[i]) {
+          myagg.value += 1;
+        }
+      }
+    }
+
+    @Override
+    public AggregationBuffer getNewAggregationBuffer() throws HiveException {
+      return new Aggregation();
+    }
+
+    @Override
+    public void reset(AggregationBuffer agg) throws HiveException {
+      Aggregation myAgg = (Aggregation) agg;
+      myAgg.isNull = true;
+    }
+
+    @Override
+    public Object evaluateOutput(AggregationBuffer agg) throws HiveException {
+    Aggregation myagg = (Aggregation) agg;
+      if (myagg.isNull) {
+      return null;    
+      }
+      else {
+        result.set (myagg.value);
+      return result;
+      }
+    }
+
+    @Override
+    public ObjectInspector getOutputObjectInspector() {
+      return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
+    }
+
+}
+

Added: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFCountLong.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFCountLong.java?rev=1477136&view=auto
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFCountLong.java (added)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFCountLong.java Mon Apr 29 15:12:39 2013
@@ -0,0 +1,162 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen;
+
+import java.util.ArrayList;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.
+    VectorAggregateExpression.AggregationBuffer;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.StructField;
+import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
+
+/**
+* VectorUDAFCountLong. Vectorized implementation for COUNT aggregates. 
+*/
+@Description(name = "count", value = "_FUNC_(expr) - Returns the maximum value of expr (vectorized, type: long)")
+public class VectorUDAFCountLong extends VectorAggregateExpression {
+    
+    /** 
+    /* class for storing the current aggregate value.
+    */
+    static class Aggregation implements AggregationBuffer {
+      long value;
+      boolean isNull;
+    }
+    
+    private VectorExpression inputExpression;
+  private LongWritable result;    
+    
+    public VectorUDAFCountLong(VectorExpression inputExpression) {
+      super();
+      this.inputExpression = inputExpression;
+      result = new LongWritable(0);
+    }
+    
+    @Override
+    public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch unit) 
+    throws HiveException {
+      
+      inputExpression.evaluate(unit);
+      
+      LongColumnVector inputVector = (LongColumnVector)unit.
+        cols[this.inputExpression.getOutputColumn()];
+      
+      int batchSize = unit.size;
+      
+      if (batchSize == 0) {
+        return;
+      }
+      
+      Aggregation myagg = (Aggregation)agg;
+
+      if (myagg.isNull) {
+        myagg.value = 0;
+        myagg.isNull = false;
+      }
+      
+      if (inputVector.isRepeating) {
+        if (inputVector.noNulls || !inputVector.isNull[0]) {
+          myagg.value += batchSize;
+        }
+        return;
+      }
+      
+      if (inputVector.noNulls) {
+        myagg.value += batchSize;
+        return;
+      }
+      else if (!unit.selectedInUse) {
+        iterateNoSelectionHasNulls(myagg, batchSize, inputVector.isNull);
+      }
+      else {
+        iterateSelectionHasNulls(myagg, batchSize, inputVector.isNull, unit.selected);
+      }
+    }
+  
+    private void iterateSelectionHasNulls(
+        Aggregation myagg, 
+        int batchSize,
+        boolean[] isNull, 
+        int[] selected) {
+      
+      for (int j=0; j< batchSize; ++j) {
+        int i = selected[j];
+        if (!isNull[i]) {
+          myagg.value += 1;
+        }
+      }
+    }
+
+    private void iterateNoSelectionHasNulls(
+        Aggregation myagg, 
+        int batchSize, 
+        boolean[] isNull) {
+      
+      for (int i=0; i< batchSize; ++i) {
+        if (!isNull[i]) {
+          myagg.value += 1;
+        }
+      }
+    }
+
+    @Override
+    public AggregationBuffer getNewAggregationBuffer() throws HiveException {
+      return new Aggregation();
+    }
+
+    @Override
+    public void reset(AggregationBuffer agg) throws HiveException {
+      Aggregation myAgg = (Aggregation) agg;
+      myAgg.isNull = true;
+    }
+
+    @Override
+    public Object evaluateOutput(AggregationBuffer agg) throws HiveException {
+    Aggregation myagg = (Aggregation) agg;
+      if (myagg.isNull) {
+      return null;    
+      }
+      else {
+        result.set (myagg.value);
+      return result;
+      }
+    }
+
+    @Override
+    public ObjectInspector getOutputObjectInspector() {
+      return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
+    }
+
+}
+

Added: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMaxDouble.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMaxDouble.java?rev=1477136&view=auto
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMaxDouble.java (added)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMaxDouble.java Mon Apr 29 15:12:39 2013
@@ -0,0 +1,215 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen;
+
+import java.util.ArrayList;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.
+    VectorAggregateExpression.AggregationBuffer;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.StructField;
+import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
+
+/**
+* VectorUDAFMaxDouble. Vectorized implementation for MIN/MAX aggregates. 
+*/
+@Description(name = "max", value = "_FUNC_(expr) - Returns the maximum value of expr (vectorized, type: double)")
+public class VectorUDAFMaxDouble extends VectorAggregateExpression {
+    
+    /** 
+    /* class for storing the current aggregate value.
+    */
+    static private final class Aggregation implements AggregationBuffer {
+      double value;
+      boolean isNull;
+    }
+    
+    private VectorExpression inputExpression;
+    private DoubleWritable result;
+    
+    public VectorUDAFMaxDouble(VectorExpression inputExpression) {
+      super();
+      this.inputExpression = inputExpression;
+      result = new DoubleWritable();
+    }
+    
+    @Override
+    public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch unit) throws HiveException {
+        
+        inputExpression.evaluate(unit);
+        
+        DoubleColumnVector inputVector = (DoubleColumnVector)unit.
+            cols[this.inputExpression.getOutputColumn()];
+        
+        int batchSize = unit.size;
+        
+        if (batchSize == 0) {
+          return;
+        }
+        
+        Aggregation myagg = (Aggregation)agg;
+  
+        double[] vector = inputVector.vector;
+        
+        if (inputVector.isRepeating) {
+          if ((inputVector.noNulls || !inputVector.isNull[0]) &&
+            myagg.isNull || vector[0] < myagg.value) {
+            myagg.isNull = false;
+            myagg.value = vector[0];
+          }
+          return;
+        }
+        
+        if (!unit.selectedInUse && inputVector.noNulls) {
+          iterateNoSelectionNoNulls(myagg, vector, batchSize);
+        }
+        else if (!unit.selectedInUse) {
+          iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull);
+        }
+        else if (inputVector.noNulls){
+          iterateSelectionNoNulls(myagg, vector, batchSize, unit.selected);
+        }
+        else {
+          iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, unit.selected);
+        }
+    }
+  
+    private void iterateSelectionHasNulls(
+        Aggregation myagg, 
+        double[] vector, 
+        int batchSize,
+        boolean[] isNull, 
+        int[] selected) {
+      
+      for (int j=0; j< batchSize; ++j) {
+        int i = selected[j];
+        if (!isNull[i]) {
+          double value = vector[i];
+          if (myagg.isNull) {
+            myagg.isNull = false;
+            myagg.value = value;
+          }
+          else if (value > myagg.value) {
+            myagg.value = value;
+          }
+        }
+      }
+    }
+
+    private void iterateSelectionNoNulls(
+        Aggregation myagg, 
+        double[] vector, 
+        int batchSize, 
+        int[] selected) {
+      
+      if (myagg.isNull) {
+        myagg.value = vector[selected[0]];
+        myagg.isNull = false;
+      }
+      
+      for (int i=0; i< batchSize; ++i) {
+        double value = vector[selected[i]];
+        if (value > myagg.value) {
+          myagg.value = value;
+        }
+      }
+    }
+
+    private void iterateNoSelectionHasNulls(
+        Aggregation myagg, 
+        double[] vector, 
+        int batchSize,
+        boolean[] isNull) {
+      
+      for(int i=0;i<batchSize;++i) {
+        if (!isNull[i]) {
+          double value = vector[i];
+          if (myagg.isNull) { 
+            myagg.value = value;
+            myagg.isNull = false;
+          }
+          else if (value > myagg.value) {
+            myagg.value = value;
+          }
+        }
+      }
+    }
+
+    private void iterateNoSelectionNoNulls(
+        Aggregation myagg, 
+        double[] vector, 
+        int batchSize) {
+      if (myagg.isNull) {
+        myagg.value = vector[0];
+        myagg.isNull = false;
+      }
+      
+      for (int i=0;i<batchSize;++i) {
+        double value = vector[i];
+        if (value > myagg.value) {
+          myagg.value = value;
+        }
+      }
+    }
+
+    @Override
+    public AggregationBuffer getNewAggregationBuffer() throws HiveException {
+      return new Aggregation();
+    }
+
+    @Override
+    public void reset(AggregationBuffer agg) throws HiveException {
+      Aggregation myAgg = (Aggregation) agg;
+      myAgg.isNull = true;
+    }
+
+    @Override
+    public Object evaluateOutput(
+        AggregationBuffer agg) throws HiveException {
+    Aggregation myagg = (Aggregation) agg;
+      if (myagg.isNull) {
+        return null;
+      }
+      else {
+        result.set(myagg.value);
+        return result;
+      }
+    }
+    
+    @Override
+    public ObjectInspector getOutputObjectInspector() {
+      return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
+    }
+}
+

Added: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMaxLong.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMaxLong.java?rev=1477136&view=auto
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMaxLong.java (added)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMaxLong.java Mon Apr 29 15:12:39 2013
@@ -0,0 +1,215 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen;
+
+import java.util.ArrayList;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.
+    VectorAggregateExpression.AggregationBuffer;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.StructField;
+import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
+
+/**
+* VectorUDAFMaxLong. Vectorized implementation for MIN/MAX aggregates. 
+*/
+@Description(name = "max", value = "_FUNC_(expr) - Returns the maximum value of expr (vectorized, type: long)")
+public class VectorUDAFMaxLong extends VectorAggregateExpression {
+    
+    /** 
+    /* class for storing the current aggregate value.
+    */
+    static private final class Aggregation implements AggregationBuffer {
+      long value;
+      boolean isNull;
+    }
+    
+    private VectorExpression inputExpression;
+    private LongWritable result;
+    
+    public VectorUDAFMaxLong(VectorExpression inputExpression) {
+      super();
+      this.inputExpression = inputExpression;
+      result = new LongWritable();
+    }
+    
+    @Override
+    public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch unit) throws HiveException {
+        
+        inputExpression.evaluate(unit);
+        
+        LongColumnVector inputVector = (LongColumnVector)unit.
+            cols[this.inputExpression.getOutputColumn()];
+        
+        int batchSize = unit.size;
+        
+        if (batchSize == 0) {
+          return;
+        }
+        
+        Aggregation myagg = (Aggregation)agg;
+  
+        long[] vector = inputVector.vector;
+        
+        if (inputVector.isRepeating) {
+          if ((inputVector.noNulls || !inputVector.isNull[0]) &&
+            myagg.isNull || vector[0] < myagg.value) {
+            myagg.isNull = false;
+            myagg.value = vector[0];
+          }
+          return;
+        }
+        
+        if (!unit.selectedInUse && inputVector.noNulls) {
+          iterateNoSelectionNoNulls(myagg, vector, batchSize);
+        }
+        else if (!unit.selectedInUse) {
+          iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull);
+        }
+        else if (inputVector.noNulls){
+          iterateSelectionNoNulls(myagg, vector, batchSize, unit.selected);
+        }
+        else {
+          iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, unit.selected);
+        }
+    }
+  
+    private void iterateSelectionHasNulls(
+        Aggregation myagg, 
+        long[] vector, 
+        int batchSize,
+        boolean[] isNull, 
+        int[] selected) {
+      
+      for (int j=0; j< batchSize; ++j) {
+        int i = selected[j];
+        if (!isNull[i]) {
+          long value = vector[i];
+          if (myagg.isNull) {
+            myagg.isNull = false;
+            myagg.value = value;
+          }
+          else if (value > myagg.value) {
+            myagg.value = value;
+          }
+        }
+      }
+    }
+
+    private void iterateSelectionNoNulls(
+        Aggregation myagg, 
+        long[] vector, 
+        int batchSize, 
+        int[] selected) {
+      
+      if (myagg.isNull) {
+        myagg.value = vector[selected[0]];
+        myagg.isNull = false;
+      }
+      
+      for (int i=0; i< batchSize; ++i) {
+        long value = vector[selected[i]];
+        if (value > myagg.value) {
+          myagg.value = value;
+        }
+      }
+    }
+
+    private void iterateNoSelectionHasNulls(
+        Aggregation myagg, 
+        long[] vector, 
+        int batchSize,
+        boolean[] isNull) {
+      
+      for(int i=0;i<batchSize;++i) {
+        if (!isNull[i]) {
+          long value = vector[i];
+          if (myagg.isNull) { 
+            myagg.value = value;
+            myagg.isNull = false;
+          }
+          else if (value > myagg.value) {
+            myagg.value = value;
+          }
+        }
+      }
+    }
+
+    private void iterateNoSelectionNoNulls(
+        Aggregation myagg, 
+        long[] vector, 
+        int batchSize) {
+      if (myagg.isNull) {
+        myagg.value = vector[0];
+        myagg.isNull = false;
+      }
+      
+      for (int i=0;i<batchSize;++i) {
+        long value = vector[i];
+        if (value > myagg.value) {
+          myagg.value = value;
+        }
+      }
+    }
+
+    @Override
+    public AggregationBuffer getNewAggregationBuffer() throws HiveException {
+      return new Aggregation();
+    }
+
+    @Override
+    public void reset(AggregationBuffer agg) throws HiveException {
+      Aggregation myAgg = (Aggregation) agg;
+      myAgg.isNull = true;
+    }
+
+    @Override
+    public Object evaluateOutput(
+        AggregationBuffer agg) throws HiveException {
+    Aggregation myagg = (Aggregation) agg;
+      if (myagg.isNull) {
+        return null;
+      }
+      else {
+        result.set(myagg.value);
+        return result;
+      }
+    }
+    
+    @Override
+    public ObjectInspector getOutputObjectInspector() {
+      return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
+    }
+}
+

Added: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMinDouble.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMinDouble.java?rev=1477136&view=auto
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMinDouble.java (added)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMinDouble.java Mon Apr 29 15:12:39 2013
@@ -0,0 +1,215 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen;
+
+import java.util.ArrayList;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.
+    VectorAggregateExpression.AggregationBuffer;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.StructField;
+import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
+
+/**
+* VectorUDAFMinDouble. Vectorized implementation for MIN/MAX aggregates. 
+*/
+@Description(name = "min", value = "_FUNC_(expr) - Returns the minimum value of expr (vectorized, type: double)")
+public class VectorUDAFMinDouble extends VectorAggregateExpression {
+    
+    /** 
+    /* class for storing the current aggregate value.
+    */
+    static private final class Aggregation implements AggregationBuffer {
+      double value;
+      boolean isNull;
+    }
+    
+    private VectorExpression inputExpression;
+    private DoubleWritable result;
+    
+    public VectorUDAFMinDouble(VectorExpression inputExpression) {
+      super();
+      this.inputExpression = inputExpression;
+      result = new DoubleWritable();
+    }
+    
+    @Override
+    public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch unit) throws HiveException {
+        
+        inputExpression.evaluate(unit);
+        
+        DoubleColumnVector inputVector = (DoubleColumnVector)unit.
+            cols[this.inputExpression.getOutputColumn()];
+        
+        int batchSize = unit.size;
+        
+        if (batchSize == 0) {
+          return;
+        }
+        
+        Aggregation myagg = (Aggregation)agg;
+  
+        double[] vector = inputVector.vector;
+        
+        if (inputVector.isRepeating) {
+          if ((inputVector.noNulls || !inputVector.isNull[0]) &&
+            myagg.isNull || vector[0] < myagg.value) {
+            myagg.isNull = false;
+            myagg.value = vector[0];
+          }
+          return;
+        }
+        
+        if (!unit.selectedInUse && inputVector.noNulls) {
+          iterateNoSelectionNoNulls(myagg, vector, batchSize);
+        }
+        else if (!unit.selectedInUse) {
+          iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull);
+        }
+        else if (inputVector.noNulls){
+          iterateSelectionNoNulls(myagg, vector, batchSize, unit.selected);
+        }
+        else {
+          iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, unit.selected);
+        }
+    }
+  
+    private void iterateSelectionHasNulls(
+        Aggregation myagg, 
+        double[] vector, 
+        int batchSize,
+        boolean[] isNull, 
+        int[] selected) {
+      
+      for (int j=0; j< batchSize; ++j) {
+        int i = selected[j];
+        if (!isNull[i]) {
+          double value = vector[i];
+          if (myagg.isNull) {
+            myagg.isNull = false;
+            myagg.value = value;
+          }
+          else if (value < myagg.value) {
+            myagg.value = value;
+          }
+        }
+      }
+    }
+
+    private void iterateSelectionNoNulls(
+        Aggregation myagg, 
+        double[] vector, 
+        int batchSize, 
+        int[] selected) {
+      
+      if (myagg.isNull) {
+        myagg.value = vector[selected[0]];
+        myagg.isNull = false;
+      }
+      
+      for (int i=0; i< batchSize; ++i) {
+        double value = vector[selected[i]];
+        if (value < myagg.value) {
+          myagg.value = value;
+        }
+      }
+    }
+
+    private void iterateNoSelectionHasNulls(
+        Aggregation myagg, 
+        double[] vector, 
+        int batchSize,
+        boolean[] isNull) {
+      
+      for(int i=0;i<batchSize;++i) {
+        if (!isNull[i]) {
+          double value = vector[i];
+          if (myagg.isNull) { 
+            myagg.value = value;
+            myagg.isNull = false;
+          }
+          else if (value < myagg.value) {
+            myagg.value = value;
+          }
+        }
+      }
+    }
+
+    private void iterateNoSelectionNoNulls(
+        Aggregation myagg, 
+        double[] vector, 
+        int batchSize) {
+      if (myagg.isNull) {
+        myagg.value = vector[0];
+        myagg.isNull = false;
+      }
+      
+      for (int i=0;i<batchSize;++i) {
+        double value = vector[i];
+        if (value < myagg.value) {
+          myagg.value = value;
+        }
+      }
+    }
+
+    @Override
+    public AggregationBuffer getNewAggregationBuffer() throws HiveException {
+      return new Aggregation();
+    }
+
+    @Override
+    public void reset(AggregationBuffer agg) throws HiveException {
+      Aggregation myAgg = (Aggregation) agg;
+      myAgg.isNull = true;
+    }
+
+    @Override
+    public Object evaluateOutput(
+        AggregationBuffer agg) throws HiveException {
+    Aggregation myagg = (Aggregation) agg;
+      if (myagg.isNull) {
+        return null;
+      }
+      else {
+        result.set(myagg.value);
+        return result;
+      }
+    }
+    
+    @Override
+    public ObjectInspector getOutputObjectInspector() {
+      return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
+    }
+}
+

Added: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMinLong.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMinLong.java?rev=1477136&view=auto
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMinLong.java (added)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/gen/VectorUDAFMinLong.java Mon Apr 29 15:12:39 2013
@@ -0,0 +1,215 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen;
+
+import java.util.ArrayList;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.
+    VectorAggregateExpression.AggregationBuffer;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.StructField;
+import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
+
+/**
+* VectorUDAFMinLong. Vectorized implementation for MIN/MAX aggregates. 
+*/
+@Description(name = "min", value = "_FUNC_(expr) - Returns the minimum value of expr (vectorized, type: long)")
+public class VectorUDAFMinLong extends VectorAggregateExpression {
+    
+    /** 
+    /* class for storing the current aggregate value.
+    */
+    static private final class Aggregation implements AggregationBuffer {
+      long value;
+      boolean isNull;
+    }
+    
+    private VectorExpression inputExpression;
+    private LongWritable result;
+    
+    public VectorUDAFMinLong(VectorExpression inputExpression) {
+      super();
+      this.inputExpression = inputExpression;
+      result = new LongWritable();
+    }
+    
+    @Override
+    public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch unit) throws HiveException {
+        
+        inputExpression.evaluate(unit);
+        
+        LongColumnVector inputVector = (LongColumnVector)unit.
+            cols[this.inputExpression.getOutputColumn()];
+        
+        int batchSize = unit.size;
+        
+        if (batchSize == 0) {
+          return;
+        }
+        
+        Aggregation myagg = (Aggregation)agg;
+  
+        long[] vector = inputVector.vector;
+        
+        if (inputVector.isRepeating) {
+          if ((inputVector.noNulls || !inputVector.isNull[0]) &&
+            myagg.isNull || vector[0] < myagg.value) {
+            myagg.isNull = false;
+            myagg.value = vector[0];
+          }
+          return;
+        }
+        
+        if (!unit.selectedInUse && inputVector.noNulls) {
+          iterateNoSelectionNoNulls(myagg, vector, batchSize);
+        }
+        else if (!unit.selectedInUse) {
+          iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull);
+        }
+        else if (inputVector.noNulls){
+          iterateSelectionNoNulls(myagg, vector, batchSize, unit.selected);
+        }
+        else {
+          iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, unit.selected);
+        }
+    }
+  
+    private void iterateSelectionHasNulls(
+        Aggregation myagg, 
+        long[] vector, 
+        int batchSize,
+        boolean[] isNull, 
+        int[] selected) {
+      
+      for (int j=0; j< batchSize; ++j) {
+        int i = selected[j];
+        if (!isNull[i]) {
+          long value = vector[i];
+          if (myagg.isNull) {
+            myagg.isNull = false;
+            myagg.value = value;
+          }
+          else if (value < myagg.value) {
+            myagg.value = value;
+          }
+        }
+      }
+    }
+
+    private void iterateSelectionNoNulls(
+        Aggregation myagg, 
+        long[] vector, 
+        int batchSize, 
+        int[] selected) {
+      
+      if (myagg.isNull) {
+        myagg.value = vector[selected[0]];
+        myagg.isNull = false;
+      }
+      
+      for (int i=0; i< batchSize; ++i) {
+        long value = vector[selected[i]];
+        if (value < myagg.value) {
+          myagg.value = value;
+        }
+      }
+    }
+
+    private void iterateNoSelectionHasNulls(
+        Aggregation myagg, 
+        long[] vector, 
+        int batchSize,
+        boolean[] isNull) {
+      
+      for(int i=0;i<batchSize;++i) {
+        if (!isNull[i]) {
+          long value = vector[i];
+          if (myagg.isNull) { 
+            myagg.value = value;
+            myagg.isNull = false;
+          }
+          else if (value < myagg.value) {
+            myagg.value = value;
+          }
+        }
+      }
+    }
+
+    private void iterateNoSelectionNoNulls(
+        Aggregation myagg, 
+        long[] vector, 
+        int batchSize) {
+      if (myagg.isNull) {
+        myagg.value = vector[0];
+        myagg.isNull = false;
+      }
+      
+      for (int i=0;i<batchSize;++i) {
+        long value = vector[i];
+        if (value < myagg.value) {
+          myagg.value = value;
+        }
+      }
+    }
+
+    @Override
+    public AggregationBuffer getNewAggregationBuffer() throws HiveException {
+      return new Aggregation();
+    }
+
+    @Override
+    public void reset(AggregationBuffer agg) throws HiveException {
+      Aggregation myAgg = (Aggregation) agg;
+      myAgg.isNull = true;
+    }
+
+    @Override
+    public Object evaluateOutput(
+        AggregationBuffer agg) throws HiveException {
+    Aggregation myagg = (Aggregation) agg;
+      if (myagg.isNull) {
+        return null;
+      }
+      else {
+        result.set(myagg.value);
+        return result;
+      }
+    }
+    
+    @Override
+    public ObjectInspector getOutputObjectInspector() {
+      return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
+    }
+}
+