11#hive-third-functions [ ![ Build Status] ( https://travis-ci.org/aaronshan/hive-third-functions.svg?branch=master )] ( https://travis-ci.org/aaronshan/hive-third-functions )
22
33## Introduction
4- some useful hive udf functions
4+
5+ Some useful custom hive udf functions, especial json functions.
6+
7+ > Note:
8+ > hive-third-functions support hive-0.11.0 or higher.
59
610## Build
711
12+ ### 1. install dependency
13+
14+ Now, jdo2-api-2.3-ec.jar not available in the maven central repository, so we have to manually install it into our local maven repository.
15+
816```
917wget http://www.datanucleus.org/downloads/maven2/javax/jdo/jdo2-api/2.3-ec/jdo2-api-2.3-ec.jar -O ~/jdo2-api-2.3-ec.jar
1018mvn install:install-file -DgroupId=javax.jdo -DartifactId=jdo2-api -Dversion=2.3-ec -Dpackaging=jar -Dfile=~/jdo2-api-2.3-ec.jar
19+ ```
20+
21+ ### 2. mvn package
22+
23+ ```
1124cd ${project_home}
1225mvn clean package
1326```
1427
15- If you want skip unit tests, please run:
28+ If you want to skip unit tests, please run:
1629```
17- wget http://www.datanucleus.org/downloads/maven2/javax/jdo/jdo2-api/2.3-ec/jdo2-api-2.3-ec.jar -O ~/jdo2-api-2.3-ec.jar
18- mvn install:install-file -DgroupId=javax.jdo -DartifactId=jdo2-api -Dversion=2.3-ec -Dpackaging=jar -Dfile=~/jdo2-api-2.3-ec.jar
1930cd ${project_home}
2031mvn clean package -DskipTests
2132```
2233
2334It will generate hive-third-functions-${version}-shaded.jar in target directory.
2435
36+ You can also directly download file from [ release page] ( https://github.com/aaronshan/hive-third-functions/releases ) .
37+
2538> current latest version is ` 2.0.0 `
2639
27- ## functions
40+ ## Functions
2841
2942### 1. string functions
3043
@@ -44,10 +57,10 @@ It will generate hive-third-functions-${version}-shaded.jar in target directory.
4457
4558| function| description |
4659| :--| :--|
47- | dayofweek (date_string \| date) -> int | day of week,if monday,return 1, sunday return 7, error return null.|
60+ | day_of_week (date_string \| date) -> int | day of week,if monday,return 1, sunday return 7, error return null.|
4861| zodiac_en(date_string \| date) -> string | convert date to zodiac|
4962| zodiac_cn(date_string \| date) -> string | convert date to zodiac chinese |
50- | typeofdate (date_string \| date) -> string | for chinese. 获取日期的类型(1: 法定节假日, 2: 正常周末, 3: 正常工作日 4:攒假的工作日),错误返回-1. |
63+ | type_of_day (date_string \| date) -> string | for chinese. 获取日期的类型(1: 法定节假日, 2: 正常周末, 3: 正常工作日 4:攒假的工作日),错误返回-1. |
5164
5265### 4. JSON functions
5366| function| description |
@@ -74,13 +87,13 @@ It will generate hive-third-functions-${version}-shaded.jar in target directory.
7487
7588## Use
7689
77- Put these statements into ${HOME}/.hiverc or exec its on hive cli env.
90+ Put these statements into ` ${HOME}/.hiverc ` or exec its on hive cli env.
7891
7992```
8093add jar ${jar_location_dir}/hive-third-functions-1.0-SNAPSHOT-shaded.jar
8194create temporary function array_contains as 'cc.shanruifeng.functions.array.UDFArrayContains';
82- create temporary function dayOfWeek as 'cc.shanruifeng.functions.date.UDFDayOfWeek';
83- create temporary function typeOfDay as 'cc.shanruifeng.functions.date.UDFTypeOfDay';
95+ create temporary function day_of_week as 'cc.shanruifeng.functions.date.UDFDayOfWeek';
96+ create temporary function type_of_day as 'cc.shanruifeng.functions.date.UDFTypeOfDay';
8497create temporary function zodiac_cn as 'cc.shanruifeng.functions.date.UDFZodiacSignCn';
8598create temporary function zodiac_en as 'cc.shanruifeng.functions.date.UDFZodiacSignEn';
8699create temporary function pinyin as 'cc.shanruifeng.functions.string.UDFChineseToPinYin';
@@ -126,25 +139,25 @@ Example:
126139```
127140
128141```
129- select dayOfWeek ('2016-07-12') => 2
130- select typeOfDay ('2016-10-01') => 1
131- select typeOfDay ('2016-07-16') => 2
132- select typeOfDay ('2016-07-15') => 3
133- select typeOfDay ('2016-09-18') => 4
142+ select day_of_week ('2016-07-12') => 2
143+ select type_of_day ('2016-10-01') => 1
144+ select type_of_day ('2016-07-16') => 2
145+ select type_of_day ('2016-07-15') => 3
146+ select type_of_day ('2016-09-18') => 4
134147select zodiac_cn('1989-01-08') => 魔羯座
135148select zodiac_en('1989-01-08') => Capricorn
136149```
137150
138151```
139- select id_card_info('110101198901084517') => {"area":"东城区","valid":true ,"province":"北京市","gender":"男","city":"北京市"}
152+ select id_card_info('110101198901084517') => {"valid":true,"area":"东城区" ,"province":"北京市","gender":"男","city":"北京市"}
140153```
141154
142155```
143156select json_array_get("[{\"a\":{\"b\":\"13\"}}, {\"a\":{\"b\":\"18\"}}, {\"a\":{\"b\":\"12\"}}]", 1); => {"a":{"b":"18"}}
144- select json_array_get('["a", "b", "c"]', 0); => 'a'
145- select json_array_get('["a", "b", "c"]', 1); => 'b'
146- select json_array_get('["c", "b", "a"]', -1); => 'a'
147- select json_array_get('["c", "b", "a"]', -2); => 'b'
157+ select json_array_get('["a", "b", "c"]', 0); => a
158+ select json_array_get('["a", "b", "c"]', 1); => b
159+ select json_array_get('["c", "b", "a"]', -1); => a
160+ select json_array_get('["c", "b", "a"]', -2); => b
148161select json_array_get('[]', 0); => null
149162select json_array_get('["a", "b", "c"]', 10); => null
150163select json_array_get('["c", "b", "a"]', -10); => null
0 commit comments