Using UDFs
DLI allows you to query data by using the user-defined functions (Hive UDF).
Procedure
- Compile a UDF.
Create or modify the content of SumUdfDemo.java in the sample code based on service requirements.
- Generate a JAR package, set the output JAR package to TestUDF.jar, and run the Build Artifacts command.
A file named TestUDF.jar is generated in the corresponding path, for example, udfDemo\target\artifacts\TestUDF.
- Upload TestUDF.jar to OBS. For details about how to upload data to OBS, see Step 2: Upload Data to OBS in Submitting a SQL Job.
- Create a function.
Run the following command on the management console to create a function:
CREATE FUNCTION fun1 AS 'com.demo.SumUdfDemo' using jar 'obs://udf/TestUDF.jar';
- Use the created function.
Run the following statement to query using the function created in 4.
select fun1(ip) from ip_tables;
- Delete the created function.
If this function is no longer used, run the following statement to delete the function:
Drop FUNCTION fun1;
Sample Code
The sample code in SumUdfDemo.java is as follows:
package com.demo; import org.apache.hadoop.hive.ql.exec.UDF; public class SumUdfDemo extends UDF { public Int evaluate(Int a, Int b) { return a + b; } }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot