Github user myui commented on a diff in the pull request:

    https://github.com/apache/incubator-hivemall/pull/108#discussion_r131596381
  
    --- Diff: 
core/src/main/java/hivemall/tools/map/UDAFToBoundedOrderedMap.java ---
    @@ -0,0 +1,259 @@
    +/*
    + * 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 hivemall.tools.map;
    +
    +import hivemall.utils.hadoop.HiveUtils;
    +
    +import org.apache.hadoop.hive.ql.exec.Description;
    +import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
    +import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
    +import org.apache.hadoop.hive.ql.metadata.HiveException;
    +import org.apache.hadoop.hive.ql.parse.SemanticException;
    +import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator;
    +import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo;
    +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
    +import 
org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
    +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
    +import 
org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
    +import 
org.apache.hadoop.hive.serde2.objectinspector.StandardMapObjectInspector;
    +import org.apache.hadoop.hive.serde2.objectinspector.StructField;
    +import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
    +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
    +import org.apache.hadoop.io.IntWritable;
    +
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.Map;
    +import java.util.SortedMap;
    +import java.util.TreeMap;
    +
    +/**
    + * Convert two aggregated columns into a fixed-size sorted map.
    + */
    +@Description(name = "to_bounded_ordered_map",
    +        value = "_FUNC_(key, value, size [, const boolean 
reverseOrder=false]) "
    +                + "- Convert two aggregated columns into a fixed-size 
sorted map")
    +public class UDAFToBoundedOrderedMap extends UDAFToMap {
    +
    +    @Override
    +    public GenericUDAFEvaluator getEvaluator(GenericUDAFParameterInfo info)
    +            throws SemanticException {
    +        @SuppressWarnings("deprecation")
    +        TypeInfo[] typeInfo = info.getParameters();
    +        if (typeInfo.length != 3 && typeInfo.length != 4) {
    +            throw new UDFArgumentTypeException(typeInfo.length - 1,
    +                "Expecting three or four arguments: " + typeInfo.length);
    +        }
    +
    +        if (typeInfo[0].getCategory() != 
ObjectInspector.Category.PRIMITIVE) {
    +            throw new UDFArgumentTypeException(0,
    +                "Only primitive type arguments are accepted for the key 
but "
    +                        + typeInfo[0].getTypeName() + " was passed as 
parameter 1.");
    +        }
    +
    +        if (!HiveUtils.isIntegerTypeInfo(typeInfo[2])) {
    +            throw new UDFArgumentTypeException(2, "The third argument must 
be integer type: "
    +                    + typeInfo[2].getTypeName());
    +        }
    +
    +        boolean reverseOrder = false;
    +        if (typeInfo.length == 4) {
    +            if (!HiveUtils.isBooleanTypeInfo(typeInfo[3])) {
    +                throw new UDFArgumentTypeException(3, "The fourth argument 
must be boolean type: "
    +                        + typeInfo[3].getTypeName());
    +            }
    +            ObjectInspector[] argOIs = info.getParameterObjectInspectors();
    +            reverseOrder = HiveUtils.getConstBoolean(argOIs[3]);
    +        }
    +
    +        if (reverseOrder) {
    +            return new BoundedReverseOrderedMapEvaluator();
    +        } else {
    +            return new BoundedOrderedMapEvaluator();
    +        }
    +    }
    +
    +    public static class BoundedOrderedMapEvaluator extends 
GenericUDAFEvaluator {
    +
    +        protected PrimitiveObjectInspector inputKeyOI;
    +        protected ObjectInspector inputValueOI;
    +        protected StandardMapObjectInspector partialMapOI;
    +        protected PrimitiveObjectInspector sizeOI;
    +
    +        protected StructObjectInspector internalMergeOI;
    +
    +        protected StructField partialMapField;
    +        protected StructField sizeField;
    +
    +        @Override
    +        public ObjectInspector init(Mode mode, ObjectInspector[] argOIs) 
throws HiveException {
    +            assert (argOIs.length == 3) : argOIs.length;
    --- End diff --
    
    argOIs.length might be 4


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to