hivemall-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myui <...@git.apache.org>
Subject [GitHub] incubator-hivemall pull request #58: [WIP][HIVEMALL-24] Scalable field-aware...
Date Tue, 25 Jul 2017 11:01:08 GMT
Github user myui commented on a diff in the pull request:

    https://github.com/apache/incubator-hivemall/pull/58#discussion_r129273987
  
    --- Diff: core/src/main/java/hivemall/fm/FFMPredictGenericUDAF.java ---
    @@ -0,0 +1,272 @@
    +/*
    + * 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.fm;
    +
    +import hivemall.utils.hadoop.HiveUtils;
    +import hivemall.utils.hadoop.WritableUtils;
    +import org.apache.hadoop.hive.ql.exec.Description;
    +import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
    +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
    +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.AbstractGenericUDAFResolver;
    +import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator;
    +import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator.AbstractAggregationBuffer;
    +import org.apache.hadoop.hive.serde2.io.DoubleWritable;
    +import org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryArray;
    +import org.apache.hadoop.hive.serde2.objectinspector.*;
    +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
    +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
    +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
    +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableDoubleObjectInspector;
    +import org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo;
    +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
    +
    +import javax.annotation.Nonnull;
    +import javax.annotation.Nullable;
    +import java.util.ArrayList;
    +import java.util.List;
    +
    +@Description(
    +        name = "ffm_predict",
    +        value = "_FUNC_(Float Wi, Float Wj, array<float> Vifj, array<float>
Vjfi, float Xi, float Xj)"
    +                + " - Returns a prediction value in Double")
    +public final class FFMPredictGenericUDAF extends AbstractGenericUDAFResolver {
    +
    +    private FFMPredictGenericUDAF() {}
    +
    +    @Override
    +    public Evaluator getEvaluator(TypeInfo[] typeInfo) throws SemanticException {
    +        if (typeInfo.length != 5) {
    +            throw new UDFArgumentLengthException(
    +                "Expected argument length is 6 but given argument length was " + typeInfo.length);
    +        }
    +        if (!HiveUtils.isNumberTypeInfo(typeInfo[0])) {
    +            throw new UDFArgumentTypeException(0,
    +                "Number type is expected for the first argument Wi: " + typeInfo[0].getTypeName());
    +        }
    +        if (typeInfo[1].getCategory() != Category.LIST) {
    +            throw new UDFArgumentTypeException(1,
    +                "List type is expected for the second argument Vifj: " + typeInfo[1].getTypeName());
    +        }
    +        if (typeInfo[2].getCategory() != Category.LIST) {
    +            throw new UDFArgumentTypeException(2,
    +                "List type is expected for the third argument Vjfi: " + typeInfo[2].getTypeName());
    +        }
    +        ListTypeInfo typeInfo1 = (ListTypeInfo) typeInfo[1];
    +        if (!HiveUtils.isNumberTypeInfo(typeInfo1.getListElementTypeInfo())) {
    +            throw new UDFArgumentTypeException(1,
    +                "Number type is expected for the element type of list Vifj: "
    +                        + typeInfo1.getTypeName());
    +        }
    +        ListTypeInfo typeInfo2 = (ListTypeInfo) typeInfo[2];
    +        if (!HiveUtils.isNumberTypeInfo(typeInfo2.getListElementTypeInfo())) {
    +            throw new UDFArgumentTypeException(2,
    +                "Number type is expected for the element type of list Vjfi: "
    +                        + typeInfo1.getTypeName());
    +        }
    +        if (!HiveUtils.isNumberTypeInfo(typeInfo[3])) {
    +            throw new UDFArgumentTypeException(3,
    +                "Number type is expected for the third argument Xi: " + typeInfo[3].getTypeName());
    +        }
    +        if (!HiveUtils.isNumberTypeInfo(typeInfo[4])) {
    +            throw new UDFArgumentTypeException(4,
    +                "Number type is expected for the third argument Xi: " + typeInfo[4].getTypeName());
    +        }
    +        return new Evaluator();
    +    }
    +
    +    public static class Evaluator extends GenericUDAFEvaluator {
    +
    +        // input OI
    +        private PrimitiveObjectInspector wiOI;
    +        private ListObjectInspector vijOI;
    +        private ListObjectInspector vjiOI;
    +        private PrimitiveObjectInspector xiOI;
    +        private PrimitiveObjectInspector xjOI;
    +
    +        // merge OI
    +        private StructObjectInspector internalMergeOI;
    +        private StructField sumField;
    +
    +        public Evaluator() {}
    +
    +        @Override
    +        public ObjectInspector init(Mode mode, ObjectInspector[] parameters) throws HiveException
{
    +            assert (parameters.length == 5);
    +            super.init(mode, parameters);
    +
    +            // initialize input
    +            if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) {// from original data
    +                this.wiOI = HiveUtils.asDoubleCompatibleOI(parameters[0]);
    +                this.vijOI = HiveUtils.asListOI(parameters[1]);
    +                this.vjiOI = HiveUtils.asListOI(parameters[2]);
    +                this.xiOI = HiveUtils.asDoubleCompatibleOI(parameters[3]);
    +                this.xjOI = HiveUtils.asDoubleCompatibleOI(parameters[4]);
    +            } else {// from partial aggregation
    +                StructObjectInspector soi = (StructObjectInspector) parameters[0];
    --- End diff --
    
    doubleOI is enough


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message