当前位置:网站首页>[untitled] user defined function
[untitled] user defined function
2022-06-30 05:33:00 【m0_ sixty-two million two hundred and ninety-five thousand nine】
UDF(user defined function) Custom function 1:1
Customize a class
Inherit UDF class
rewrite evaluate Method
Put the project package To hdfs, Then imported into the hive
Add jar hdfs:///user/mazhichao/..jar
stay hive Can be used by creating temporary functions in
Create temporary function name as ‘ Package name . Method name ’
public class ValueMaskUDF extends UDF{
public String evaluate(String input,int maxSaveStringLength,String replaceSign) {
if(input.length()<=maxSaveStringLength){
return input;
}
return input.substring(0,maxSaveStringLength)+replaceSign;
}
public static void main(String[] args) {
System.out.println(new ValueMaskUDF().evaluate(" Hebei Province ",2,"..."));UDAF(user defined aggregation function) Custom aggregate functions n:1
Inherit UDAF class
Internally define a static class , Realization UDAFEvaluator Interface
Implementation method init,iterate,terminatePartial,merge,terminate5 A way
The same is add jar etc.
public class DIYCountUDAF extends UDAF {
// Log object initialization , Make the visiting class have the ability to output logs
public static Logger logger=Logger.getLogger(DIYCountUDAF.class);
// Static class implementation UDAFEvaluator
public static class Evaluator implements UDAFEvaluator {
// Set member variables , Store the total number of records in each statistical range
private int totalRecords;
// Initialization function ,map and reduce Will execute this function , Play the role of initializing the variables required
public Evaluator() {
init();
}
// initialization , The initial value is 0, And log the corresponding output
public void init() {
totalRecords = 0;
logger.info("init totalRecords="+totalRecords);
}
//map Stage , The return value is boolean type , When it comes to true Then the program continues , When it comes to false The program exits
public boolean iterate(String input) {
// When input When the input is not empty , That is, there is a value , That is, it exists 1 That's ok , So do +1 operation
if (input != null) {
totalRecords += 1;
}
// Output the number of data processed by the current group
logger.info("iterate totalRecords="+totalRecords);
return true;
}
/**
* Be similar to combiner, stay map Do partial aggregation within the scope , Pass the results on to merge Parameters in functions mapOutput
* If you need to aggregate , On the other hand iterator Processing of returned results , Otherwise go straight back to iterator As a result of
*/
public int terminatePartial() {
logger.info("terminatePartial totalRecords="+totalRecords);
return totalRecords;
}
// reduce Stage , For iterative processing map Each of them is different key Corresponding terminatePartial Result
public boolean merge(int mapOutput) {
totalRecords +=mapOutput;
logger.info("merge totalRecords="+totalRecords);
return true;
}
// Handle merge The result after calculation , At this time count stay merge Finish time , The results have come to , There is no need to deal with the overall results again , So just go back directly
public int terminate() {
logger.info("terminate totalRecords="+totalRecords);
return totalRecords;
}
}
} UDTF(User-Defined Table-Generating Functions) Customize 1:n Table generation
Commonly used lateral view explode+udf To replace
边栏推荐
- 《谁动了我的奶酪》读后感
- [learning notes] AssetBundle, xlua, hot update (use steps)
- The minecraft server address cannot be refreshed.
- [typescript] defines the return value type of promise
- [notes] unity webgl input Chinese
- PyGame. Why can't I exit when I click X in the window? I can only exit when I return idle
- Video summary of my station B
- [note] usage model tree of the unity resource tree structure virtualizingtreeview
- [typescript] cannot redeclare block range variables
- VFPBS在IIS下调用EXCEL遇到的Access is denied
猜你喜欢

Installation and getting started with pytoch

OpenCL线程代数库ViennaCL的使用

企事业单位源代码防泄露工作该如何进行

Vfpbs uploads excel and saves MSSQL to the database

如何制作CSR(Certificate Signing Request)文件?

East Tower attack and defense world - XSS bypasses the safety dog

遥感图像/UDA:Curriculum-Style Local-to-Global Adaptation for Cross-Domain Remote Sensing Image Segmentat

RedisTemplate 常用方法汇总

旋转框目标检测mmrotate v0.3.1 训练DOTA数据集(二)

Chinese pycharm changed to English pycharm
随机推荐
Rotating frame target detection mmrotate v0.3.1 learning configuration
Xi'an Jiaotong 21st autumn online expansion resources of online trade and marketing (III) [standard answer]
Revit secondary development - use panel function without opening the project
Rotation, translation and scaling of unity VR objects
Virtual and pure virtual destructions
14x1.5cm竖向标签有点难,VFP调用BarTender来打印
Vfpbs uploads excel and saves MSSQL to the database
D. Big Brush
Go Land no tests were Run: FMT cannot be used. Printf () & lt; BUG & gt;
【LeetCode】Easy | 225. Using queue to realize stack (pure C manual tearing queue)
Unity mobile end sliding screen rotation
2021-10-31
剑指 Offer 22. 链表中倒数第k个节点
OpenCL线程代数库ViennaCL的使用
Xi'an Jiaotong 21st autumn "computerized accounting" online homework answer sheet (I) [standard answer]
Basic operations of C language
【板栗糖GIS】global mapper—如何把栅格的高程值赋予给点
Visualization of 3D geological model based on borehole data by map flapping software
Terminal convenient SSH connection
虚析构和纯虚析构