diff --git a/README.md b/README.md index e356390..1b934ef 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pom.xml b/pom.xml index 43ee24b..d3d310f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cc.shanruifeng hive-third-functions - 2.1.1 + 2.1.2 UTF-8 diff --git a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardArea.java b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardArea.java index 15ee4bc..d47e1dc 100644 --- a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardArea.java +++ b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardArea.java @@ -20,6 +20,9 @@ public UDFChinaIdCardArea() { } public Text evaluate(Text idCard) { + if (idCard == null) { + return null; + } result.set(CardUtils.getIdCardArea(idCard.toString())); return result; } diff --git a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardBirthday.java b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardBirthday.java index 6e65fc8..56d274a 100644 --- a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardBirthday.java +++ b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardBirthday.java @@ -20,6 +20,9 @@ public UDFChinaIdCardBirthday() { } public Text evaluate(Text idCard) { + if (idCard == null) { + return null; + } result.set(CardUtils.getIdCardBirthday(idCard.toString())); return result; } diff --git a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardCity.java b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardCity.java index fc81038..807fa6a 100644 --- a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardCity.java +++ b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardCity.java @@ -20,6 +20,9 @@ public UDFChinaIdCardCity() { } public Text evaluate(Text idCard) { + if (idCard == null) { + return null; + } result.set(CardUtils.getIdCardCity(idCard.toString())); return result; } diff --git a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardGender.java b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardGender.java index f0c8ced..cba80c9 100644 --- a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardGender.java +++ b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardGender.java @@ -20,6 +20,9 @@ public UDFChinaIdCardGender() { } public Text evaluate(Text idCard) { + if (idCard == null) { + return null; + } result.set(CardUtils.getIdCardGender(idCard.toString())); return result; } diff --git a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardInfo.java b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardInfo.java index f5ed6c2..209a941 100644 --- a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardInfo.java +++ b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardInfo.java @@ -20,6 +20,9 @@ public UDFChinaIdCardInfo() { } public Text evaluate(Text idCard) { + if (idCard == null) { + return null; + } result.set(CardUtils.getJsonOfChinaIdCard(idCard.toString())); return result; } diff --git a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardProvince.java b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardProvince.java index efcffc6..a6fea25 100644 --- a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardProvince.java +++ b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardProvince.java @@ -20,6 +20,9 @@ public UDFChinaIdCardProvince() { } public Text evaluate(Text idCard) { + if (idCard == null) { + return null; + } result.set(CardUtils.getIdCardProvince(idCard.toString())); return result; } diff --git a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardValid.java b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardValid.java index 279a061..239a094 100644 --- a/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardValid.java +++ b/src/main/java/cc/shanruifeng/functions/card/UDFChinaIdCardValid.java @@ -21,6 +21,9 @@ public UDFChinaIdCardValid() { } public BooleanWritable evaluate(Text idCard) { + if (idCard == null) { + return null; + } result.set(CardUtils.isValidIdCard(idCard.toString())); return result; } diff --git a/src/main/java/cc/shanruifeng/functions/date/UDFZodiacSignCn.java b/src/main/java/cc/shanruifeng/functions/date/UDFZodiacSignCn.java index be3ee30..7a5bdd2 100644 --- a/src/main/java/cc/shanruifeng/functions/date/UDFZodiacSignCn.java +++ b/src/main/java/cc/shanruifeng/functions/date/UDFZodiacSignCn.java @@ -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); @@ -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; } diff --git a/src/main/java/cc/shanruifeng/functions/date/UDFZodiacSignEn.java b/src/main/java/cc/shanruifeng/functions/date/UDFZodiacSignEn.java index 3e8b2df..64281bd 100644 --- a/src/main/java/cc/shanruifeng/functions/date/UDFZodiacSignEn.java +++ b/src/main/java/cc/shanruifeng/functions/date/UDFZodiacSignEn.java @@ -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); @@ -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; } diff --git a/src/main/java/cc/shanruifeng/functions/json/UDFJsonSize.java b/src/main/java/cc/shanruifeng/functions/json/UDFJsonSize.java index 71e6cf8..4ed1dd2 100644 --- a/src/main/java/cc/shanruifeng/functions/json/UDFJsonSize.java +++ b/src/main/java/cc/shanruifeng/functions/json/UDFJsonSize.java @@ -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; } } } diff --git a/src/main/java/cc/shanruifeng/functions/url/UDFUrlDecode.java b/src/main/java/cc/shanruifeng/functions/url/UDFUrlDecode.java index 3eab3e9..21d1f2f 100644 --- a/src/main/java/cc/shanruifeng/functions/url/UDFUrlDecode.java +++ b/src/main/java/cc/shanruifeng/functions/url/UDFUrlDecode.java @@ -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; diff --git a/src/main/java/cc/shanruifeng/functions/url/UDFUrlEncode.java b/src/main/java/cc/shanruifeng/functions/url/UDFUrlEncode.java index 217e7e7..7c8a876 100644 --- a/src/main/java/cc/shanruifeng/functions/url/UDFUrlEncode.java +++ b/src/main/java/cc/shanruifeng/functions/url/UDFUrlEncode.java @@ -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; diff --git a/src/main/resources/china_day_type.config b/src/main/resources/china_day_type.config index 409a7c7..8ae306a 100644 --- a/src/main/resources/china_day_type.config +++ b/src/main/resources/china_day_type.config @@ -146,4 +146,57 @@ 2016-10-09 workday 2017-01-01 holiday 2017-01-02 holiday -2017-01-03 holiday \ No newline at end of file +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 \ No newline at end of file