User Tools

Site Tools

A PCRE internal error occured. This might be caused by a faulty plugin


**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]]


====== 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: <code language=sql> CREATE FUNCTION hello(text STRING) RETURNS STRING BEGIN RETURN 'Hello, ' || text || '!'; END; </code> ===== 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): <code language=sql> 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'; </code> Now let's use //hello// function written in HPL/SQL language in Hive: <code language=sql> SELECT hplsql('hello(:1)', name) FROM users; </code> ===== 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: <code language=sql> SELECT hello(name) FROM users; </code> 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 [[udf-sproc|User-Defined Functions and Stored Procedures]]. **Version**: HPL/SQL 0.3.1 ~~NOTOC~~