1. å¨Hiveä¸ç»æ们å ç½®äºå¾å¤å½æ°
è¿å ¥hive客æ·ç«¯ï¼æ¥çhiveå ç½®å½æ°ï¼
hive > show functions;
OK
!
!=
%
&
*
+
-
/
<
<=
<=>
<>
=
==
>
>=
^
abs
acos
add_months
and
array
...
 æ¥çå½æ°çå ·ä½æ¹æ³ï¼
hive> DESCRIBE FUNCTION case;
OK
CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END - When a = b, returns c; when a = d, return e; else return f
hive> DESCRIBE FUNCTION EXTENDED case;
hive> DESCRIBE FUNCTION EXTENDED case;
OK
CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END - When a = b, returns c; when a = d, return e; else return f
Example:
 SELECT
 CASE deptno
  WHEN 1 THEN Engineering
  WHEN 2 THEN Finance
  ELSE admin
 END,
 CASE zone
  WHEN 7 THEN Americas
  ELSE Asia-Pac
 END
 FROM emp_de
tails
2. hiveå½æ°é¤äºå ç½®è¿å¯ä»¥èªå®ä¹
èªå®ä¹å½æ°å¼åUDFï¼
1. 使ç¨mavenå建ä¸ä¸ªjava项ç®
2. 继æ¿UDFç±»ï¼
3. éåevaluateæ¹æ³
å建ä¸ä¸ªUrlDecodeWithChar类继æ¿UDFï¼å¹¶ä¸éåevaluateæ¹æ³
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
public class UrlDecodeWithChar extends UDF{
  Â
   public Text evaluate(Text param, Text charset) {
      if (charset == null || charset.toString().length() == 0) {
         charset = new Text("UTF-8");
      }
      String decode = null;
       if (param == null) {
          return param;
       } else {
         String str = param.toString();
         try {
            decode = URLDecoder.decode(str, charset.toString());
         } catch (UnsupportedEncodingException e) {
            decode = param.toString();
         }
      }
       return new Text(decode);
   }
  Â
}
å°å好ç代ç ææjarå .
å建临æ¶å½æ°æ¶:
      1. å°jarå æ¾å¨linuxæ个ç®å½ä¸,eg: /home/urldecode.jar
      2. è¿å ¥hive客æ·ç«¯,å¦ä¸æä½:
      a) add jar /home/urldecode.jar;
      b). create temporary function urldecode as 'com.jobs.main.UrlDecodeWithChar';
临æ¶å½æ°çæ(åªå¯¹å½åsessionææ).
æ¥è¯¢ç»æ:
hive > select 'Bom',urldecode('%E5%B9%BF%E5%B7%9E%E5%B8%82%E7%BB%BF%E7%9B%88%E6%B1%BD%E8%BD%A6%E6%9C%8D%E5%8A%A1%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8') from ls limit 2;
Bom    广å·å¸ç»¿ç汽车æå¡æéå ¬å¸
Bom    广å·å¸ç»¿ç汽车æå¡æéå ¬å¸
æ¥çjarå
hive> list jar;
æ¥çèªå®ä¹å½æ°
hive> show functons;Â
å é¤èªå®ä¹å½æ°
hive> drop functon urldecode;Â
çææ°¸ä¹ å½æ°
     1. éè¦å°jarå ä¸ä¼ å°hdfsä¸é¢
      eg: hdfs dfs -put /home/urldecode.jar /usr/lib
    2. åå»ºæ°¸ä¹ å½æ°
      create function urldecode as 'com.jobs.main.UrlDecodeWithChar' using jar 'hdfs:///usr/lib';
注æï¼æ§è¡è¿æ¡è¯å¥åå»ºæ°¸ä¹ å½æ°ï¼show functiuons ä¼å ä¸é»è®¤çæ°æ®åºåå¨å½æ°ååãï¼default.urldecode ï¼