hive UDF

1.UDF user define function ,用戶自定義函數
//current_database(),current_user();java

2.顯示全部函數
$hive>show functions ;
3.表生成函數
$hive>explode(str,exp); //按照exp來切割str
$hive>select explode(array(1,2,3));
4.顯示指定函數幫助:
$hive>describe function split;
$hive>desc function current_databases ;app

5.自定義函數

1.建立類,繼承
2.打成jar包到hive的類路徑:hive/lib目錄的下面
    //添加jar到類路徑
    $hive>add jar /mnt/hgfs/downloads/bigdata/data/HiveDemo-1.0-SNAPSHOT.jar  /soft/hive/lib
3.建立臨時函數
    create temporary function add as 'com.it18zhang.hiveDemo.udf.addudf';
4.在查詢中使用自定義函數
    $hive>select myadd(1,2);
5.在查詢中自定義函數
$hive>select add(1,2);

6.定義日期函數
1)定義
    package com.itheim.hivedemo.test;

import org.junit.Test;函數

import java.text.SimpleDateFormat;
import java.util.Date;code

/**orm

  • Created by Administrator
  • on 2018/7/9 0009.
    */
    public class Test3 {
    @Test
    public void test1(){
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat();
    sdf.applyPattern("yyyy/mm/dd HH:mm:ss");
    System.out.println(sdf.format(date));
    }
    public String test2(Date date){
    SimpleDateFormat sdf = new SimpleDateFormat();
    sdf.applyPattern("yyyy/mm/dd HH:mm:ss");
    return sdf.format(date);
    }
    public String test3(Date date,String frt){
    SimpleDateFormat sdf = new SimpleDateFormat();
    sdf.applyPattern(frt);
    return sdf.format(date);
    }
    }
    2)導出jar包,經過命令添加到hive的路徑(不須要重進hive)
    $hive>add jar /mnt/hgfs/downloads/bigdata/data/HiveDemo-1.0-SNAPSHOT.jar繼承

    3)註冊函數
    $hive>create temporary function to_char as 'com.it18zhang.hiveDemo.ToCharUDF';it

mapreduce數據傾斜

1):自定義分區,再開一個mr進行二次計算
2):

hive中解決數據傾斜

$hive>set hive.optimize.skewjoin=true;//設置一個傾斜鏈接打開
$hive>set hive.skewjoin.key=100000;
$hive>set hive.groupby.skewindata=true;
相關文章
相關標籤/搜索