Information | Description(Optional) |
Function Type | Create functions in the pre-set function categories based on their nature. Categories include: Analytical Functions, Encryption Functions, Aggregate Functions, Logical Functions, Date and Time Functions, Mathematical Functions, Conversion Functions, String Functions, IP and Domain Functions, Window Functions, and Other Functions. |
Class Name | Enter the function's class name. |
Function File | Select the address of the source file for the function: Select resource file: Choose the function file from the jar or zip resources uploaded from the Resource Management feature. Specify COS path: Obtain the function file from the platform COS bucket path. |
Resource File | The function file option Select resource file requires selection of the desired function file in the resource management directory. |
COS Path | The function file option Specify COS Path requires entering the path where the function file is located in the platform's COS bucket. |
Command Format | Format: FunctionName(Input Parameters). For example, the sum function command format is sum(col) |
Usage Instructions | Instructions for using custom-defined functions. For example, the instructions for using the sum function are: Calculate the summary value. |
Parameter description | Parameter description for custom-defined functions. For example, the parameter description for the sum function is: col: Required. Column values can be of DOUBLE, DECIMAL, or BIGINT types. If the input is of STRING type, it will be implicitly converted to DOUBLE type for calculation. |
Returned values | Return value description for custom-defined functions. For example, the return value for the sum function is: returns DOUBLE type. |
Sample code | Example description for custom-defined functions. For example, the example for the sum function is: Calculate the total sales of all products, with the command example: select sum(sales) from table. |
mvn archetype:generate -DgroupId=com.example -DartifactId=demo-hive -Dveriosn=1.0-SNAPSHOT -Dpackage=com.example
<dependencies><dependency><groupId>org.apache.hive</groupId><artifactId>hive-exec</artifactId><version>2.3.8</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency></dependencies>
public class UppercaseUDF extends UDF {public String evaluate(String input) {return input.toUpperCase();}}
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin><!--(start) for package jar with dependencies --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-assembly-plugin</artifactId><version>3.0.0</version><configuration><archive><!--Specify the class where the main method is located--><manifest><mainClass>com.example.UppercaseUDF</mainClass></manifest></archive><!--Do not change jar-with-dependencies--><descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs><appendAssemblyId>false</appendAssemblyId></configuration><executions><execution><id>make-assembly</id> <!-- this is used for inheritance merges --><phase>package</phase> <!-- bind to the packaging phase --><goals><goal>single</goal></goals></execution></executions></plugin><!--(end) for package jar with dependencies --></plugins></build><repositories><repository><id>alimaven</id><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/groups/public/</url></repository></repositories>
mvn package -Dmaven.test.skip=true
Information | Content |
Function Type | Other Functions |
Class Name | com.example.UppercaseUDF |
Function File | Select the resource file |
Resource File | demo-hive-1.0-SNAPSHOT.jar |
Command Format | UppercaseUDF(col) |
Usage Instructions | Enter the string to be converted to uppercase format |
Parameter description | Enter string type parameter |
Returned values | Output string in uppercase format |
public class MyDiff extends UDF {public ArrayList<Integer> evaluate(ArrayList<Integer> input) {ArrayList<Integer> result = new ArrayList<Integer>();result.add(0, 0);for (int i = 1; i < input.size(); i++) {result.add(i, input.get(i) - input.get(i - 1));}return result;}}
<dependencies><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.16</version><scope>test</scope></dependency><dependency><groupId>org.apache.hive</groupId><artifactId>hive-exec</artifactId><version>1.2.1</version></dependency></dependencies>
Was this page helpful?