Hive UDF/UDAF/UDTF Example

Source: Internet
Author: User

Some hive UDF Udaf UDTF examples originate from the Hive source code


Udf:


1


    
    
     
     /** * Licensed to the Apache software Foundation (ASF) under one * or more C  Ontributor license agreements. See the NOTICE file * Distributed with this work for additional information * regarding copyright  Ownership. The ASF licenses this file * under the Apache License, Version 2.0 (The * "License");  You are not a use of this file except in compliance * with the License.
     
      Obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * unless required by applicable or agreed to writing, software * distributed under T He License is distributed on a "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.contrib.udf.example;
     
     Import org.apache.hadoop.hive.ql.exec.Description;
     
     
     
     Import Org.apache.hadoop.hive.ql.exec.UDF;
     
      /** * Udfexampleadd. 
     
     * */@Description (name = "Example_add", value = "_func_ (expr)-example UDAF that returns the sum")
     
         public class Udfexampleadd extends UDF {public integer evaluate (Integer ... a) {
     
         int total = 0;
     
           for (Integer element:a) {if (element! = NULL) {total + = element;
     
       }} return total;
     
         } public double evaluate (double ... a) {double total = 0;
     
           for (Double element:a) {if (element! = NULL) {total + = element;
     
         }
     
         }return total;
    
     }
     
     
     
     }


2


    
    
     
     /**
     
      * 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
     
     
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.