User Tools

Site Tools


Sidebar

**HPL/SQL is included to Apache Hive since version 2.0** * [[home|Home]]\\ * [[why|Why HPL/SQL]]\\ * [[features|Key Features]]\\ * [[start|Get Started]]\\ * [[doc|HPL/SQL Reference]]\\ * [[download|Download]]\\ * [[new|What's New]]\\ * [[about|About]]

udf

Hive UDF to Run HPL/SQL Scripts from Hive CLI

HPL/SQL includes a Hive UDF function that allows you to execute HPL/SQL scripts (user-defined functions written in HPL/SQL language) in Hive queries.

For example, let's call the following function from a Hive query:

CREATE FUNCTION hello(text STRING)
 RETURNS STRING
BEGIN
 RETURN 'Hello, ' || text || '!';
END;

Running HPL/SQL from Hive CLI

Put this script to hplsqlrc file, then register HPL/SQL UDF in Hive as follows (set your path for jars and configuration files):

ADD JAR /home/pl/hplsql.jar;
ADD JAR /home/pl/antlr-runtime-4.5.jar;
 
ADD FILE /home/pl/hplsql-site.xml;
ADD FILE /home/pl/hplsqlrc;
 
CREATE TEMPORARY FUNCTION hplsql AS 'org.apache.hive.hplsql.Udf';

Now let's use hello function written in HPL/SQL language in Hive:

SELECT hplsql('hello(:1)', name) FROM users;

Running HPL/SQL from HPL/SQL CLI

When you run HPL/SQL scripts using HPL/SQL CLI tool you can just use user-defined functions the same way as you use built-in functions:

SELECT hello(name) FROM users;

HPL/SQL CLI tool automatically puts referenced HPL/SQL user-defined functions and stored procedures to Distributed Cache, registers the Hive UDF and modifies the function call in the SQL statements.

For more information, see User-Defined Functions and Stored Procedures.

Version: HPL/SQL 0.3.1