本地功能測試
UDF的測試應當儘量使用Junit/TestNG進行測試,Keep the bar green to keep your code clean.
每次開發後爲了保持代碼的兼容,需要保留original test case,在進入測試階段後,需要進行以下步驟:
- run original test case,如果通過,說明新的更新沒有對歷史數據造成bug
- wirte new test case,針對新的測試案例進行測試,多次修改後以同時能保證新老測試案例都通過爲驗收標準
線上數據驗證測試
採取自定義auxpath方法
[dcli@XX bin]$ hive --auxpath xxxx,file:///home/dcli/auxlib/VipshopHiveUDF.jar
紅色部分一般是配置在hive-site.xml文件中的,這裏採用自定義UDF JAR可以讓接下來引用你定義的jar文件
這樣就可以拿線上的數據測試剛開發完的UDF,測試分爲兩塊
- 原有function的更新
- 新增function
針對1沒有什麼問題,2的話按照原有步驟是需要在hiverc中增加function定義的,eg:
CREATE TEMPORARY FUNCTION udf_test as 'com.vipshop.curiosity.vipudf.UDFTest';
我會告訴你hive 會讀取用戶目錄的hiverc嗎?
源碼如下:cdh4-0.10.0_4.2.0/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
if(System.getProperty("user.home") != null) {
String hivercUser = System.getProperty("user.home") + File.separator +
HIVERCFILE;
if(System.getProperty("user.home") != null) {
String hivercUser = System.getProperty("user.home") + File.separator +
HIVERCFILE;
if(newFile(hivercUser).exists()) {
intrc = processFile(hivercUser);
if(rc != 0) {
System.exit(rc);
}
}
}
publicfinal class UDFTest extends UDF {
publicString evaluate(finalText s) {
returns.toString()+"=tony";
}
}
打包測試結果:
hive (default)> select udf_test("hive rc") from default.dual;
OK
_c0
hive rc=tony