Skip to content

Commit

Permalink
fix bug #2
Browse files Browse the repository at this point in the history
fix some uncheck null issue
add 2017,2018 holiday info
  • Loading branch information
aaronshan committed Nov 19, 2017
1 parent 55b76ac commit 050d440
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ It will generate hive-third-functions-${version}-shaded.jar in target directory.

You can also directly download file from [release page](https://github.com/aaronshan/hive-third-functions/releases).

> current latest version is `2.1.1`
> current latest version is `2.1.2`
## Functions

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cc.shanruifeng</groupId>
<artifactId>hive-third-functions</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public UDFChinaIdCardArea() {
}

public Text evaluate(Text idCard) {
if (idCard == null) {
return null;
}
result.set(CardUtils.getIdCardArea(idCard.toString()));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public UDFChinaIdCardBirthday() {
}

public Text evaluate(Text idCard) {
if (idCard == null) {
return null;
}
result.set(CardUtils.getIdCardBirthday(idCard.toString()));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public UDFChinaIdCardCity() {
}

public Text evaluate(Text idCard) {
if (idCard == null) {
return null;
}
result.set(CardUtils.getIdCardCity(idCard.toString()));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public UDFChinaIdCardGender() {
}

public Text evaluate(Text idCard) {
if (idCard == null) {
return null;
}
result.set(CardUtils.getIdCardGender(idCard.toString()));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public UDFChinaIdCardInfo() {
}

public Text evaluate(Text idCard) {
if (idCard == null) {
return null;
}
result.set(CardUtils.getJsonOfChinaIdCard(idCard.toString()));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public UDFChinaIdCardProvince() {
}

public Text evaluate(Text idCard) {
if (idCard == null) {
return null;
}
result.set(CardUtils.getIdCardProvince(idCard.toString()));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public UDFChinaIdCardValid() {
}

public BooleanWritable evaluate(Text idCard) {
if (idCard == null) {
return null;
}
result.set(CardUtils.isValidIdCard(idCard.toString()));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public UDFZodiacSignCn() {
}

public Text evaluate(Text birthday) {
if (birthday == null) {
return null;
}
DateTime dateTime = null;
try {
dateTime = DateTime.parse(birthday.toString(), DEFAULT_DATE_FORMATTER);
Expand All @@ -35,11 +38,17 @@ public Text evaluate(Text birthday) {
}

public Text evaluate(Date birthday) {
if (birthday == null) {
return null;
}
DateTime dateTime = new DateTime(birthday);
return evaluate(new IntWritable(dateTime.getMonthOfYear()), new IntWritable(dateTime.getDayOfMonth()));
}

public Text evaluate(IntWritable month, IntWritable day) {
if (month == null || day == null) {
return null;
}
result.set(getZodiac(month.get(), day.get()));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public UDFZodiacSignEn() {
}

public Text evaluate(String birthday) {
if (birthday == null) {
return null;
}
DateTime dateTime = null;
try {
dateTime = DateTime.parse(birthday, DEFAULT_DATE_FORMATTER);
Expand All @@ -35,11 +38,17 @@ public Text evaluate(String birthday) {
}

public Text evaluate(Date birthday) {
if (birthday == null) {
return null;
}
DateTime dateTime = new DateTime(birthday);
return evaluate(new IntWritable(dateTime.getMonthOfYear()), new IntWritable(dateTime.getDayOfMonth()));
}

public Text evaluate(IntWritable month, IntWritable day) {
if (month == null || day == null) {
return null;
}
result.set(getZodiac(month.get(), day.get()));
return result;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/cc/shanruifeng/functions/json/UDFJsonSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public LongWritable evaluate(Text json, Text path) {
result.set(size);
return result;
} catch (Exception e) {
e.printStackTrace();
return new LongWritable(-1234L);
return null;
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/cc/shanruifeng/functions/url/UDFUrlDecode.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class UDFUrlDecode extends UDF {
private Text result = new Text();

public Text evaluate(String value) {
if (value == null) {
return null;
}
try {
result.set(URLDecoder.decode(value, "UTF-8"));
return result;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/cc/shanruifeng/functions/url/UDFUrlEncode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class UDFUrlEncode extends UDF {
private Text result = new Text();

public Text evaluate(String value) {
if (value == null) {
return null;
}
Escaper escaper = UrlEscapers.urlFormParameterEscaper();
result.set(escaper.escape(value));
return result;
Expand Down
55 changes: 54 additions & 1 deletion src/main/resources/china_day_type.config
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,57 @@
2016-10-09 workday
2017-01-01 holiday
2017-01-02 holiday
2017-01-03 holiday
2017-01-03 holiday
2017-01-27 holiday
2017-01-28 holiday
2017-01-29 holiday
2017-01-30 holiday
2017-01-31 holiday
2017-02-01 holiday
2017-02-02 holiday
2017-04-01 workday
2017-05-01 holiday
2017-05-27 workday
2017-05-28 holiday
2017-05-29 holiday
2017-05-30 holiday
2017-09-30 workday
2017-10-01 holiday
2017-10-02 holiday
2017-10-03 holiday
2017-10-04 holiday
2017-10-05 holiday
2017-10-06 holiday
2017-10-07 holiday
2017-10-08 holiday
2018-01-01 holiday
2018-02-15 holiday
2018-02-16 holiday
2018-02-17 holiday
2018-02-18 holiday
2018-02-19 holiday
2018-02-20 holiday
2018-02-21 holiday
2018-04-05 holiday
2018-04-06 holiday
2018-04-07 holiday
2018-04-08 workday
2018-04-28 workday
2018-04-29 holiday
2018-04-30 holiday
2018-05-01 holiday
2018-06-16 holiday
2018-06-17 holiday
2018-06-18 holiday
2018-09-22 holiday
2018-09-23 holiday
2018-09-24 holiday
2018-09-29 workday
2018-09-30 workday
2018-10-01 holiday
2018-10-02 holiday
2018-10-03 holiday
2018-10-04 holiday
2018-10-05 holiday
2018-10-06 holiday
2018-10-07 holiday

0 comments on commit 050d440

Please sign in to comment.