From 9a091be90cb6899439f30b766d38b08f354c1c6d Mon Sep 17 00:00:00 2001 From: mdayakar Date: Thu, 13 Aug 2026 21:53:14 +0530 Subject: [PATCH] HIVE-29759: Add HPLSQL documentation to Apache Hive Official Documentation website --- content/docs/latest/user/hive-hpl-sql.md | 27 -- .../docs/latest/user/hive-hplsql/_index.md | 187 +++++++++++ .../hive-hplsql/built-in-variables/_index.md | 4 + .../built-in-variables/activity_count.md | 33 ++ .../built-in-variables/hostcode.md | 29 ++ .../hive-hplsql/built-in-variables/sqlcode.md | 39 +++ .../built-in-variables/sqlstate.md | 29 ++ .../user/hive-hplsql/compatibility/_index.md | 4 + .../user/hive-hplsql/compatibility/plsql.md | 88 +++++ .../docs/latest/user/hive-hplsql/features.md | 15 + .../latest/user/hive-hplsql/file-io/_index.md | 4 + .../user/hive-hplsql/file-io/utl-file.md | 199 +++++++++++ .../user/hive-hplsql/functions/_index.md | 4 + .../latest/user/hive-hplsql/functions/cast.md | 42 +++ .../latest/user/hive-hplsql/functions/char.md | 33 ++ .../user/hive-hplsql/functions/coalesce.md | 49 +++ .../user/hive-hplsql/functions/concat.md | 38 +++ .../hive-hplsql/functions/current-date.md | 30 ++ .../functions/current-timestamp.md | 46 +++ .../hive-hplsql/functions/current-user.md | 36 ++ .../latest/user/hive-hplsql/functions/date.md | 37 +++ .../user/hive-hplsql/functions/dbms-output.md | 46 +++ .../user/hive-hplsql/functions/decode.md | 38 +++ .../hive-hplsql/functions/from-unixtime.md | 48 +++ .../user/hive-hplsql/functions/instr.md | 70 ++++ .../latest/user/hive-hplsql/functions/len.md | 33 ++ .../user/hive-hplsql/functions/length.md | 33 ++ .../user/hive-hplsql/functions/lower.md | 32 ++ .../hive-hplsql/functions/max-part-date.md | 82 +++++ .../hive-hplsql/functions/max-part-int.md | 85 +++++ .../hive-hplsql/functions/max-part-string.md | 82 +++++ .../hive-hplsql/functions/min-part-date.md | 82 +++++ .../hive-hplsql/functions/min-part-int.md | 86 +++++ .../hive-hplsql/functions/min-part-string.md | 82 +++++ .../latest/user/hive-hplsql/functions/now.md | 40 +++ .../latest/user/hive-hplsql/functions/nvl.md | 49 +++ .../latest/user/hive-hplsql/functions/nvl2.md | 40 +++ .../hive-hplsql/functions/part-count-by.md | 72 ++++ .../user/hive-hplsql/functions/part-count.md | 72 ++++ .../user/hive-hplsql/functions/part-loc.md | 72 ++++ .../user/hive-hplsql/functions/replace.md | 38 +++ .../user/hive-hplsql/functions/substr.md | 54 +++ .../user/hive-hplsql/functions/substring.md | 58 ++++ .../user/hive-hplsql/functions/sysdate.md | 40 +++ .../hive-hplsql/functions/timestamp-iso.md | 50 +++ .../user/hive-hplsql/functions/to-char.md | 31 ++ .../hive-hplsql/functions/to-timestamp.md | 46 +++ .../latest/user/hive-hplsql/functions/trim.md | 30 ++ .../hive-hplsql/functions/unix-timestamp.md | 40 +++ .../user/hive-hplsql/functions/upper.md | 32 ++ .../latest/user/hive-hplsql/functions/user.md | 36 ++ .../hive-hplsql/language-elements/_index.md | 4 + .../hive-hplsql/language-elements/assign.md | 86 +++++ .../hive-hplsql/language-elements/case.md | 63 ++++ .../language-elements/cursor-attributes.md | 69 ++++ .../language-elements/data-types.md | 65 ++++ .../language-elements/date-literal.md | 25 ++ .../hive-hplsql/language-elements/declare.md | 62 ++++ .../language-elements/exceptions.md | 38 +++ .../hive-hplsql/language-elements/interval.md | 87 +++++ .../language-elements/rowtype-attribute.md | 59 ++++ .../language-elements/timestamp-literal.md | 33 ++ .../language-elements/type-attribute.md | 31 ++ content/docs/latest/user/hive-hplsql/new.md | 222 +++++++++++++ .../user/hive-hplsql/operators/_index.md | 4 + .../user/hive-hplsql/operators/equal.md | 44 +++ .../user/hive-hplsql/operators/minus.md | 34 ++ .../latest/user/hive-hplsql/operators/plus.md | 43 +++ .../user/hive-hplsql/operators/twopipes.md | 38 +++ content/docs/latest/user/hive-hplsql/start.md | 134 ++++++++ .../user/hive-hplsql/statements/_index.md | 4 + .../hive-hplsql/statements/allocate-cursor.md | 156 +++++++++ .../statements/associate-locator.md | 23 ++ .../user/hive-hplsql/statements/break.md | 27 ++ .../user/hive-hplsql/statements/call.md | 44 +++ .../user/hive-hplsql/statements/close.md | 38 +++ .../latest/user/hive-hplsql/statements/cmp.md | 47 +++ .../hive-hplsql/statements/copy-from-ftp.md | 32 ++ .../hive-hplsql/statements/copy-from-local.md | 45 +++ .../user/hive-hplsql/statements/copy.md | 75 +++++ .../hive-hplsql/statements/create-database.md | 32 ++ .../hive-hplsql/statements/create-function.md | 66 ++++ .../create-local-temporary-table.md | 51 +++ .../hive-hplsql/statements/create-package.md | 84 +++++ .../statements/create-procedure.md | 55 ++++ .../hive-hplsql/statements/create-table.md | 42 +++ .../statements/create-volatile-table.md | 51 +++ .../statements/declare-condition.md | 47 +++ .../hive-hplsql/statements/declare-cursor.md | 68 ++++ .../hive-hplsql/statements/declare-handler.md | 56 ++++ .../statements/declare-temporary-table.md | 61 ++++ .../user/hive-hplsql/statements/describe.md | 29 ++ .../hive-hplsql/statements/drop-database.md | 30 ++ .../user/hive-hplsql/statements/drop-table.md | 21 ++ .../user/hive-hplsql/statements/execute.md | 74 +++++ .../user/hive-hplsql/statements/exit.md | 37 +++ .../user/hive-hplsql/statements/fetch.md | 44 +++ .../user/hive-hplsql/statements/for-cursor.md | 38 +++ .../user/hive-hplsql/statements/for-range.md | 46 +++ .../hive-hplsql/statements/get-diagnostics.md | 37 +++ .../user/hive-hplsql/statements/host.md | 53 +++ .../latest/user/hive-hplsql/statements/if.md | 76 +++++ .../user/hive-hplsql/statements/include.md | 55 ++++ .../statements/insert-directory.md | 43 +++ .../user/hive-hplsql/statements/insert.md | 69 ++++ .../user/hive-hplsql/statements/leave.md | 38 +++ .../user/hive-hplsql/statements/loop.md | 40 +++ .../user/hive-hplsql/statements/map-object.md | 42 +++ .../user/hive-hplsql/statements/null.md | 28 ++ .../user/hive-hplsql/statements/open.md | 59 ++++ .../user/hive-hplsql/statements/print.md | 36 ++ .../user/hive-hplsql/statements/resignal.md | 114 +++++++ .../user/hive-hplsql/statements/return.md | 40 +++ .../hive-hplsql/statements/select-into.md | 23 ++ .../user/hive-hplsql/statements/select.md | 92 ++++++ .../hive-hplsql/statements/set-session.md | 39 +++ .../user/hive-hplsql/statements/signal.md | 45 +++ .../user/hive-hplsql/statements/truncate.md | 29 ++ .../user/hive-hplsql/statements/update.md | 20 ++ .../latest/user/hive-hplsql/statements/use.md | 32 ++ .../hive-hplsql/statements/values-into.md | 32 ++ .../user/hive-hplsql/statements/while.md | 42 +++ .../user/hive-hplsql/troubleshooting.md | 12 + .../user/hive-hplsql/user-guide/_index.md | 4 + .../latest/user/hive-hplsql/user-guide/cli.md | 71 ++++ .../hive-hplsql/user-guide/configuration.md | 311 ++++++++++++++++++ .../hive-hplsql/user-guide/connections.md | 99 ++++++ .../user/hive-hplsql/user-guide/conversion.md | 93 ++++++ .../hive-hplsql/user-guide/error-handling.md | 35 ++ .../user/hive-hplsql/user-guide/hive.md | 41 +++ .../user-guide/multiple-databases.md | 48 +++ .../user-guide/temporary-tables.md | 49 +++ .../user/hive-hplsql/user-guide/udf-sproc.md | 65 ++++ .../latest/user/hive-hplsql/user-guide/udf.md | 52 +++ content/docs/latest/user/hive-hplsql/why.md | 40 +++ 135 files changed, 7113 insertions(+), 27 deletions(-) delete mode 100644 content/docs/latest/user/hive-hpl-sql.md create mode 100644 content/docs/latest/user/hive-hplsql/_index.md create mode 100644 content/docs/latest/user/hive-hplsql/built-in-variables/_index.md create mode 100644 content/docs/latest/user/hive-hplsql/built-in-variables/activity_count.md create mode 100644 content/docs/latest/user/hive-hplsql/built-in-variables/hostcode.md create mode 100644 content/docs/latest/user/hive-hplsql/built-in-variables/sqlcode.md create mode 100644 content/docs/latest/user/hive-hplsql/built-in-variables/sqlstate.md create mode 100644 content/docs/latest/user/hive-hplsql/compatibility/_index.md create mode 100644 content/docs/latest/user/hive-hplsql/compatibility/plsql.md create mode 100644 content/docs/latest/user/hive-hplsql/features.md create mode 100644 content/docs/latest/user/hive-hplsql/file-io/_index.md create mode 100644 content/docs/latest/user/hive-hplsql/file-io/utl-file.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/_index.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/cast.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/char.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/coalesce.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/concat.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/current-date.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/current-timestamp.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/current-user.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/date.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/dbms-output.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/decode.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/from-unixtime.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/instr.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/len.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/length.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/lower.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/max-part-date.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/max-part-int.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/max-part-string.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/min-part-date.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/min-part-int.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/min-part-string.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/now.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/nvl.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/nvl2.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/part-count-by.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/part-count.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/part-loc.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/replace.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/substr.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/substring.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/sysdate.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/timestamp-iso.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/to-char.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/to-timestamp.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/trim.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/unix-timestamp.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/upper.md create mode 100644 content/docs/latest/user/hive-hplsql/functions/user.md create mode 100644 content/docs/latest/user/hive-hplsql/language-elements/_index.md create mode 100644 content/docs/latest/user/hive-hplsql/language-elements/assign.md create mode 100644 content/docs/latest/user/hive-hplsql/language-elements/case.md create mode 100644 content/docs/latest/user/hive-hplsql/language-elements/cursor-attributes.md create mode 100644 content/docs/latest/user/hive-hplsql/language-elements/data-types.md create mode 100644 content/docs/latest/user/hive-hplsql/language-elements/date-literal.md create mode 100644 content/docs/latest/user/hive-hplsql/language-elements/declare.md create mode 100644 content/docs/latest/user/hive-hplsql/language-elements/exceptions.md create mode 100644 content/docs/latest/user/hive-hplsql/language-elements/interval.md create mode 100644 content/docs/latest/user/hive-hplsql/language-elements/rowtype-attribute.md create mode 100644 content/docs/latest/user/hive-hplsql/language-elements/timestamp-literal.md create mode 100644 content/docs/latest/user/hive-hplsql/language-elements/type-attribute.md create mode 100644 content/docs/latest/user/hive-hplsql/new.md create mode 100644 content/docs/latest/user/hive-hplsql/operators/_index.md create mode 100644 content/docs/latest/user/hive-hplsql/operators/equal.md create mode 100644 content/docs/latest/user/hive-hplsql/operators/minus.md create mode 100644 content/docs/latest/user/hive-hplsql/operators/plus.md create mode 100644 content/docs/latest/user/hive-hplsql/operators/twopipes.md create mode 100644 content/docs/latest/user/hive-hplsql/start.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/_index.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/allocate-cursor.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/associate-locator.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/break.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/call.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/close.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/cmp.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/copy-from-ftp.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/copy-from-local.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/copy.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/create-database.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/create-function.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/create-local-temporary-table.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/create-package.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/create-procedure.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/create-table.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/create-volatile-table.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/declare-condition.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/declare-cursor.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/declare-handler.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/declare-temporary-table.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/describe.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/drop-database.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/drop-table.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/execute.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/exit.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/fetch.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/for-cursor.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/for-range.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/get-diagnostics.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/host.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/if.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/include.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/insert-directory.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/insert.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/leave.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/loop.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/map-object.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/null.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/open.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/print.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/resignal.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/return.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/select-into.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/select.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/set-session.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/signal.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/truncate.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/update.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/use.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/values-into.md create mode 100644 content/docs/latest/user/hive-hplsql/statements/while.md create mode 100644 content/docs/latest/user/hive-hplsql/troubleshooting.md create mode 100644 content/docs/latest/user/hive-hplsql/user-guide/_index.md create mode 100644 content/docs/latest/user/hive-hplsql/user-guide/cli.md create mode 100644 content/docs/latest/user/hive-hplsql/user-guide/configuration.md create mode 100644 content/docs/latest/user/hive-hplsql/user-guide/connections.md create mode 100644 content/docs/latest/user/hive-hplsql/user-guide/conversion.md create mode 100644 content/docs/latest/user/hive-hplsql/user-guide/error-handling.md create mode 100644 content/docs/latest/user/hive-hplsql/user-guide/hive.md create mode 100644 content/docs/latest/user/hive-hplsql/user-guide/multiple-databases.md create mode 100644 content/docs/latest/user/hive-hplsql/user-guide/temporary-tables.md create mode 100644 content/docs/latest/user/hive-hplsql/user-guide/udf-sproc.md create mode 100644 content/docs/latest/user/hive-hplsql/user-guide/udf.md create mode 100644 content/docs/latest/user/hive-hplsql/why.md diff --git a/content/docs/latest/user/hive-hpl-sql.md b/content/docs/latest/user/hive-hpl-sql.md deleted file mode 100644 index 63b52b0b..00000000 --- a/content/docs/latest/user/hive-hpl-sql.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: "Apache Hive : Hive HPL/SQL" -date: 2024-12-12 ---- - -# Apache Hive : Hive HPL/SQL - -Hive Hybrid Procedural SQL On Hadoop (HPL/SQL) is a tool that implements procedural SQL for Hive. It is available in Hive 2.0.0 ([HIVE-11055](https://issues.apache.org/jira/browse/HIVE-11055)). - -*HPL/SQL is an open source tool (Apache License 2.0) that implements procedural SQL language for Apache Hive, SparkSQL, Impala as well as any other SQL-on-Hadoop implementation, any NoSQL and any RDBMS.* - -*HPL/SQL is a hybrid and heterogeneous language that understands syntaxes and semantics of almost any existing procedural SQL dialect, and you can use with any database, for example, running existing Oracle PL/SQL code on Apache Hive and Microsoft SQL Server, or running Transact-SQL on Oracle, Cloudera Impala or Amazon Redshift.* - -*HPL/SQL language is compatible to a large extent with Oracle PL/SQL, ANSI/ISO SQL/PSM (IBM DB2, MySQL, Teradata i.e), PostgreSQL PL/pgSQL (Netezza), Transact-SQL (Microsoft SQL Server and Sybase) that allows you leveraging existing SQL/DWH skills and familiar approach to implement data warehouse solutions on Hadoop. It also facilitates migration of existing business logic to Hadoop.* - -*HPL/SQL is an efficient way to implement ETL processes in Hadoop.* - -HPL/SQL language is compatible to a large extent with Oracle PL/SQL, ANSI/ISO SQL/PSM (IBM DB2, MySQL, Teradata), PostgreSQL PL/pgSQL (PostgreSQL, Netezza) and Transact-SQL (Microsoft SQL Server and Sybase) that facilitates migration of existing business logic to Hadoop. - -See [HPL/SQL Reference](http://www.hplsql.org/doc) for documentation. - -  - - - - - diff --git a/content/docs/latest/user/hive-hplsql/_index.md b/content/docs/latest/user/hive-hplsql/_index.md new file mode 100644 index 00000000..576d5dcd --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/_index.md @@ -0,0 +1,187 @@ +--- +title: "Apache Hive : Hive HPL/SQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : Hive HPL/SQL Reference + +Hive Hybrid Procedural SQL On Hadoop (HPL/SQL) is a tool that implements procedural SQL for Hive. It is available in Hive 2.0.0 ([HIVE-11055](https://issues.apache.org/jira/browse/HIVE-11055)). + +HPL/SQL is an open source tool (Apache License 2.0) that implements procedural SQL language for Apache Hive, SparkSQL, Impala as well as any other SQL-on-Hadoop implementation, any NoSQL and any RDBMS. + +HPL/SQL is a hybrid and heterogeneous language that understands syntaxes and semantics of almost any existing procedural SQL dialect, and you can use with any database, for example, running existing Oracle PL/SQL code on Apache Hive and Microsoft SQL Server, or running Transact-SQL on Oracle, Cloudera Impala or Amazon Redshift. + +HPL/SQL language is compatible to a large extent with Oracle PL/SQL, ANSI/ISO SQL/PSM (IBM DB2, MySQL, Teradata i.e), PostgreSQL PL/pgSQL (Netezza), Transact-SQL (Microsoft SQL Server and Sybase) that allows you leveraging existing SQL/DWH skills and familiar approach to implement data warehouse solutions on Hadoop. It also facilitates migration of existing business logic to Hadoop. + +HPL/SQL is an efficient way to implement ETL processes in Hadoop. + +## Getting Started + +- [Why HPL/SQL]({{< ref "why" >}}) +- [Key Features]({{< ref "features" >}}) +- [Get Started]({{< ref "start" >}}) +- [What's New]({{< ref "new" >}}) + +## User Guide + +- [Command Line]({{< ref "cli" >}}) +- [Configuration]({{< ref "configuration" >}}) +- [Connections]({{< ref "connections" >}}) +- [Working with Multiple Databases]({{< ref "multiple-databases" >}}) +- [User-Defined Functions and Stored Procedures]({{< ref "udf-sproc" >}}) +- [On-the-Fly SQL Conversion]({{< ref "conversion" >}}) +- [UDF to Run HPL/SQL Scripts from Hive Queries]({{< ref "udf" >}}) +- [Error Handling]({{< ref "error-handling" >}}) +- [Native and Managed Temporary Tables]({{< ref "temporary-tables" >}}) + +## Language Elements + +- [Data Types]({{< ref "data-types" >}}) +- [Declaration]({{< ref "declare" >}}) +- [Assignment]({{< ref "assign" >}}) +- [DATE Literal]({{< ref "date-literal" >}}) +- [TIMESTAMP Literal]({{< ref "timestamp-literal" >}}) +- [INTERVAL Expressions]({{< ref "interval" >}}) +- [CASE Expressions]({{< ref "case" >}}) +- [%TYPE Attribute]({{< ref "type-attribute" >}}) +- [%ROWTYPE Attribute]({{< ref "rowtype-attribute" >}}) +- [%ISOPEN, %FOUND and %NOTFOUND Cursor Attributes]({{< ref "cursor-attributes" >}}) +- [Exceptions]({{< ref "exceptions" >}}) + +## Operators + +- [Addition +]({{< ref "plus" >}}) +- [Subtraction -]({{< ref "minus" >}}) +- [Equality and Comparison =, <>, !=, <, >, <=, >=]({{< ref "equal" >}}) +- [String Concatenation ||]({{< ref "twopipes" >}}) + +## Attributes and Built-in Variables + +| Name | Description | +| --- | --- | +| [ACTIVITY_COUNT]({{< ref "activity_count" >}}) | Number of rows affected by last SQL statement | +| [HOSTCODE]({{< ref "hostcode" >}}) | Return code of the last OS command | +| [SQLCODE]({{< ref "sqlcode" >}}) | Return code of the last SQL statement | +| [SQLSTATE]({{< ref "sqlstate" >}}) | Return status of the last SQL statement | + +## Statements + +| Statement | Description | +| --- | --- | +| [ALLOCATE CURSOR]({{< ref "allocate-cursor" >}}) | Allocate cursor for procedure result set | +| [ASSOCIATE RESULT SET LOCATOR]({{< ref "associate-locator" >}}) | Define locators for procedure result sets | +| [BREAK]({{< ref "break" >}}) | Exit a loop | +| [CALL]({{< ref "call" >}}) | Execute a stored procedure | +| [CLOSE]({{< ref "close" >}}) | Close a cursor | +| [CMP]({{< ref "cmp" >}}) | Compare data in tables | +| [COPY]({{< ref "copy" >}}) | Copy data between tables and files | +| [COPY FROM FTP]({{< ref "copy-from-ftp" >}}) | Copy FTP files to Hadoop compatible file system | +| [COPY FROM LOCAL]({{< ref "copy-from-local" >}}) | Copy local files to Hadoop compatible file system | +| [CREATE DATABASE]({{< ref "create-database" >}}) | Create a database | +| [CREATE FUNCTION]({{< ref "create-function" >}}) | Create a user-defined SQL function | +| [CREATE LOCAL TEMPORARY TABLE]({{< ref "create-local-temporary-table" >}}) | Create a session-level temporary table | +| [CREATE PACKAGE]({{< ref "create-package" >}}) | Create a program package | +| [CREATE PROCEDURE]({{< ref "create-procedure" >}}) | Create a user-defined SQL procedure | +| [CREATE TABLE]({{< ref "create-table" >}}) | Create a table | +| [CREATE VOLATILE TABLE]({{< ref "create-volatile-table" >}}) | Create a session-level temporary table | +| [DECLARE]({{< ref "declare" >}}) | Declare a variable | +| [DECLARE CONDITION]({{< ref "declare-condition" >}}) | Declare a condition | +| [DECLARE CURSOR]({{< ref "declare-cursor" >}}) | Declare a cursor | +| [DECLARE HANDLER]({{< ref "declare-handler" >}}) | Declare a condition handler | +| [DECLARE TEMPORARY TABLE]({{< ref "declare-temporary-table" >}}) | Declare a temporary table | +| [DESCRIBE]({{< ref "describe" >}}) | Describe a database object | +| [DROP DATABASE]({{< ref "drop-database" >}}) | Drop a database | +| [DROP TABLE]({{< ref "drop-table" >}}) | Drop a table | +| [EXEC]({{< ref "execute" >}}) / [EXECUTE]({{< ref "execute" >}}) / [EXECUTE IMMEDIATE]({{< ref "execute" >}}) | Execute a dynamic SQL statement or procedure | +| [EXIT WHEN]({{< ref "exit" >}}) | Exit a loop | +| [FETCH]({{< ref "fetch" >}}) | Fetch the next row from a cursor | +| [FOR cursor]({{< ref "for-cursor" >}}) | FOR statement (Cursor loop) | +| [FOR range]({{< ref "for-range" >}}) | FOR statement (Integer range) | +| [GET DIAGNOSTICS]({{< ref "get-diagnostics" >}}) | Get execution information | +| [HOST]({{< ref "host" >}}) | Execute an OS command or run an external process | +| [IF]({{< ref "if" >}}) | IF statement | +| [INCLUDE]({{< ref "include" >}}) | Include statements from another script | +| [INSERT]({{< ref "insert" >}}) | INSERT statement | +| [INSERT DIRECTORY]({{< ref "insert-directory" >}}) | Write query results to a file | +| [LEAVE]({{< ref "leave" >}}) | Exit a loop | +| [OPEN]({{< ref "open" >}}) | Open a cursor | +| [LOOP]({{< ref "loop" >}}) | Unconditional loop | +| [MAP OBJECT]({{< ref "map-object" >}}) | Map object name to a connection profile | +| [NULL]({{< ref "null" >}}) | No operation (no-op) statement | +| [PRINT]({{< ref "print" >}}) | Print a line | +| [RESIGNAL]({{< ref "resignal" >}}) | Resignal the exception | +| [RETURN]({{< ref "return" >}}) | Return from a routine | +| [SELECT]({{< ref "select" >}}) | SELECT statement | +| [SELECT INTO]({{< ref "select-into" >}}) | Assign values from a query | +| [SIGNAL]({{< ref "signal" >}}) | Raise a condition or exception | +| [SET]({{< ref "assign" >}}) | Assign a value to a variable | +| [SET Session Option]({{< ref "set-session" >}}) | Set a session option | +| [TRUNCATE]({{< ref "truncate" >}}) | Truncate a table | +| [UPDATE]({{< ref "update" >}}) | UPDATE statement | +| [USE]({{< ref "use" >}}) | Change the default database | +| [VALUES INTO]({{< ref "values-into" >}}) | Assign a value to a variable | +| [WHILE]({{< ref "while" >}}) | While loop | + +## Functions + +| Function | Description | +| --- | --- | +| [CAST]({{< ref "cast" >}}) | Convert to data type | +| [CHAR]({{< ref "char" >}}) | Convert to string | +| [COALESCE]({{< ref "coalesce" >}}) | Return first non-NULL value | +| [CONCAT]({{< ref "concat" >}}) | Concatenate two or more strings | +| [CURRENT_DATE]({{< ref "current-date" >}}) | Get the current date (year, month and day) | +| [CURRENT_TIMESTAMP]({{< ref "current-timestamp" >}}) | Get the current date and time | +| [CURRENT_USER]({{< ref "current-user" >}}) | Get the current user name | +| [DATE]({{< ref "date" >}}) | Convert to date | +| [DECODE]({{< ref "decode" >}}) | Implement IF-THEN-ELSE logic | +| [DBMS_OUTPUT.PUT_LINE]({{< ref "dbms-output" >}}) | Print a line | +| [FROM_UNIXTIME]({{< ref "from-unixtime" >}}) | Convert number of seconds since 1970-01-01 to timestamp | +| [INSTR]({{< ref "instr" >}}) | Find index of substring in a string | +| [LOWER]({{< ref "lower" >}}) | Convert a string to lower case | +| [LEN]({{< ref "len" >}}) | String length excluding trailing blanks | +| [LENGTH]({{< ref "length" >}}) | String length | +| [MAX_PART_STRING]({{< ref "max-part-string" >}}) | Get max partition value (string) | +| [MIN_PART_STRING]({{< ref "min-part-string" >}}) | Get min partition value (string) | +| [MAX_PART_INT]({{< ref "max-part-int" >}}) | Get max partition value (int) | +| [MIN_PART_INT]({{< ref "min-part-int" >}}) | Get min partition value (int) | +| [MAX_PART_DATE]({{< ref "max-part-date" >}}) | Get max partition value (date) | +| [MIN_PART_DATE]({{< ref "min-part-date" >}}) | Get min partition value (date) | +| [NOW]({{< ref "now" >}}) | Get the current date and time | +| [NVL]({{< ref "nvl" >}}) | Return first non-NULL value | +| [NVL2]({{< ref "nvl2" >}}) | If 1st operand is null return 3rd otherwise 2nd operand | +| [PART_LOC]({{< ref "part-loc" >}}) | Get the location of a partition | +| [PART_COUNT]({{< ref "part-count" >}}) | Get the number of partitions | +| [PART_COUNT_BY]({{< ref "part-count-by" >}}) | Get the number of partitions (group by) | +| [REPLACE]({{< ref "replace" >}}) | Replace a string | +| [SUBSTR]({{< ref "substr" >}}) | Return a substring | +| [SUBSTRING]({{< ref "substring" >}}) | Return a substring | +| [SYSDATE]({{< ref "sysdate" >}}) | Get the current date and time | +| [TIMESTAMP_ISO]({{< ref "timestamp-iso" >}}) | Convert string to timestamp | +| [TO_CHAR]({{< ref "to-char" >}}) | Convert to string | +| [TO_TIMESTAMP]({{< ref "to-timestamp" >}}) | Convert string to timestamp | +| [TRIM]({{< ref "trim" >}}) | Remove leading and trailing characters | +| [UNIX_TIMESTAMP]({{< ref "unix-timestamp" >}}) | Get the current date and time in seconds since 1970-01-01 | +| [UPPER]({{< ref "upper" >}}) | Convert a string to upper case | +| [USER]({{< ref "functions/user.md" >}}) | Get the current user name | + +## Commands + +| Command | Description | +| --- | --- | +| [hive]({{< ref "hive" >}}) | Invoke Hive CLI | +| [! cmd;]({{< ref "host" >}}) | Execute an OS command or run an external process | + +## File I/O Operations + +- [UTL_FILE Package]({{< ref "utl-file" >}}) + +## Troubleshooting + +- [Troubleshooting]({{< ref "troubleshooting" >}}) + +## Compatibility + +- [Oracle PL/SQL]({{< ref "plsql" >}}) + + \ No newline at end of file diff --git a/content/docs/latest/user/hive-hplsql/built-in-variables/_index.md b/content/docs/latest/user/hive-hplsql/built-in-variables/_index.md new file mode 100644 index 00000000..3c08452c --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/built-in-variables/_index.md @@ -0,0 +1,4 @@ +--- +title: "Attributes and Built-in Variables" +date: 2026-08-12 +--- diff --git a/content/docs/latest/user/hive-hplsql/built-in-variables/activity_count.md b/content/docs/latest/user/hive-hplsql/built-in-variables/activity_count.md new file mode 100644 index 00000000..eb979f21 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/built-in-variables/activity_count.md @@ -0,0 +1,33 @@ +--- +title: "Apache Hive : ACTIVITY_COUNT Variable - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : ACTIVITY_COUNT Variable - PL/HQL + +ACTIVITY_COUNT built-in variable contains the number of rows affected by the last SQL statement. + +**Important Note:** Currently Hive does not support JDBC Statement.getUpdateCount(), so for INSERT statements ACTIVITY_COUNT will return 0 for Hive 0.13 and earlier and -1 for Hive 0.14 and later. See [HIVE-7680](https://issues.apache.org/jira/browse/HIVE-7680) for more details. + +Currently you can use ACTIVITY_COUNT only with SELECT statements in Hive. If SELECT INTO returns a row ACTIVITY_COUNT is set to 1. Also if you use a cursor each FETCH statement increments ACTIVITY_COUNT by 1. + +**Example**: + +``` +DECLARE var INT; + +SELECT id INTO var FROM default.dual; + +IF ACTIVITY_COUNT = 1 THEN + PRINT 'id = ' || var; +END IF; +``` + +**Compatibility:** Teradata + +**Version**: PL/HQL 0.3.1 + +**See also:** +- [GET DIAGNOSTICS ROW_COUNT]({{< ref "get-diagnostics" >}}) +- [SQLCODE]({{< ref "sqlcode" >}}) +- [SQLSTATE]({{< ref "sqlstate" >}}) diff --git a/content/docs/latest/user/hive-hplsql/built-in-variables/hostcode.md b/content/docs/latest/user/hive-hplsql/built-in-variables/hostcode.md new file mode 100644 index 00000000..32ccf625 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/built-in-variables/hostcode.md @@ -0,0 +1,29 @@ +--- +title: "Apache Hive : HOSTCODE - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : HOSTCODE - PL/HQL Reference + +HOSTCODE built-in variable contains the return code of the last OS command. + +``` +SET plhql.onerror = SETERROR; + +HOST 'echo hello, world'; +IF HOSTCODE <> 0 THEN + PRINT 'Error'; +END IF; +``` + +**Notes**: + +- Typically HOSTCODE is 0 when the process terminated successfully, and 1 if it terminated with an error. +- By default [plhql.onerror]({{< ref "configuration#plhqlonerror" >}}) is set to EXCEPTION, so if the OS command cannot be executed (the process does not exist, no permissions i.e.) the exception is raised and you are not be able to check HOSTCODE in IF statement. + +For more information, see [Error Handling]({{< ref "error-handling" >}}). + +**Compatibility:** PL/HQL Extension. + +**See also:** +- [SQLCODE]({{< ref "sqlcode" >}}) diff --git a/content/docs/latest/user/hive-hplsql/built-in-variables/sqlcode.md b/content/docs/latest/user/hive-hplsql/built-in-variables/sqlcode.md new file mode 100644 index 00000000..55da6205 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/built-in-variables/sqlcode.md @@ -0,0 +1,39 @@ +--- +title: "Apache Hive : SQLCODE - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : SQLCODE - PL/HQL Reference + +SQLCODE built-in variable contains the return code of the last SQL statement. The code can be zero (0), negative or positive: + +| **SQLCODE** | **Result** | +| --- | --- | +| 0 | Successful execution | +| Positive values | Warning | +| Negative values | Error | + +Note: + +- SQLCODE 100 means row not found or end of cursor + +``` +DECLARE id INT; +DECLARE cur CURSOR FOR 'SELECT id FROM db.orders'; +OPEN cur; +FETCH cur INTO id; +WHILE SQLCODE = 0 THEN + FETCH cur INTO id; +END WHILE; +CLOSE cur; +``` + +**Compatibility:** IBM DB2. + +**Version:** PL/HQL 0.01 + +**See also:** +- [Error Handling]({{< ref "error-handling" >}}) +- [SQLSTATE]({{< ref "sqlstate" >}}) +- [GET DIAGNOSTICS]({{< ref "get-diagnostics" >}}) +- [RESIGNAL]({{< ref "resignal" >}}) diff --git a/content/docs/latest/user/hive-hplsql/built-in-variables/sqlstate.md b/content/docs/latest/user/hive-hplsql/built-in-variables/sqlstate.md new file mode 100644 index 00000000..3a0d6ac3 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/built-in-variables/sqlstate.md @@ -0,0 +1,29 @@ +--- +title: "Apache Hive : SQLSTATE - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : SQLSTATE - PL/HQL Reference + +SQLSTATE built-in variable contains a 5-character return status of the last SQL statement. + +SQLSTATE status code consists of a 2-character class code followed by a 3-character subclass code. Class code 00 (SQLSTATE '00000' i.e.) means the successful completion. + +**Example:** + +``` +SET plhql.onerror = seterror; -- Prevent raising an exception + +SELECT 1 FROM abc.abc; +PRINT SQLSTATE; +``` + +**Compatibility:** IBM DB2. + +**Version:** PL/HQL 0.03 + +**See also:** +- [Error Handling]({{< ref "error-handling" >}}) +- [SQLCODE]({{< ref "sqlcode" >}}) +- [GET DIAGNOSTICS]({{< ref "get-diagnostics" >}}) +- [RESIGNAL]({{< ref "resignal" >}}) diff --git a/content/docs/latest/user/hive-hplsql/compatibility/_index.md b/content/docs/latest/user/hive-hplsql/compatibility/_index.md new file mode 100644 index 00000000..7ac48ebb --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/compatibility/_index.md @@ -0,0 +1,4 @@ +--- +title: "Compatibility" +date: 2026-08-12 +--- diff --git a/content/docs/latest/user/hive-hplsql/compatibility/plsql.md b/content/docs/latest/user/hive-hplsql/compatibility/plsql.md new file mode 100644 index 00000000..44f98f2f --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/compatibility/plsql.md @@ -0,0 +1,88 @@ +--- +title: "Apache Hive : Oracle PL/SQL Compatibility" +date: 2026-08-12 +--- + +# Apache Hive : Oracle PL/SQL Compatibility + +HPL/SQL compatibility with Oracle PL/SQL and SQL. + +## Language Elements + +Oracle PL/SQL language elements supported by HPL/SQL: + +| Feature | Description | Supported | Since | +| --- | --- | --- | --- | +| TRUE and FALSE | Boolean literals | Yes | 0.3.13 | +| -- comment | Single line comment | Yes | 0.1 | +| /* comment */ | Multi line comment | Yes | 0.1 | +| NOT NULL | Variable constraint | Parser only | 0.3.13 | +| CONSTANT | Constant variable | Yes | 0.3.13 | +| := or DEFAULT | Default clause | Yes | 0.1 | +| [%TYPE]({{< ref "type-attribute" >}}) | Data type attribute | Yes | 0.3.13 | +| SUBTYPE *subtype* IS *type* | Subtype | No | | + +## Data Types and Declarations + +Oracle PL/SQL data types supported by HPL/SQL: + +| Data Type | Description | Supported | Since | +| --- | --- | --- | --- | +| BIGINT | 64-bit integer | Yes | 0.3.13 | +| BINARY_DOUBLE | Double precision floating-point number | Yes | 0.3.13 | +| BINARY_FLOAT | Single precision floating-point number | Yes | 0.3.13 | +| BINARY_INTEGER | 32-bit integer | Yes | 0.3.13 | +| BLOB | Binary long data | No | | +| BOOLEAN | True or false | Yes | 0.3.13 | +| CHAR(*n*) | Fixed-length string | Yes | 0.1 | +| CHARACTER(*n*) | Fixed-length string | Yes | 0.1 | +| CLOB | Character long data | No | | +| DECIMAL(*p,s*) | Fixed-point number | Yes | 0.1 | +| DATE | Date (year, month, day and time) | Yes | 0.1 | +| INT | 32-bit integer | Yes | 0.1 | +| INTEGER | 32-bit integer | Yes | 0.1 | +| LONG | Long string | No | | +| LONG RAW | Long binary string | No | | +| NATURAL | Nonnegative 32-bit integer | No | | +| NATURALN | Nonnegative non-null 32-bit integer | No | | +| NCHAR(*n*) | Fixed-length string | Yes | 0.1 | +| NCLOB | Character long data | No | | +| NVARCHAR(*n*) | Variable-length string | Yes | 0.1 | +| NUMBER(*p,s*) | Fixed-point number | Yes | 0.1 | +| PLS_INTEGER | 32-bit integer | Yes | 0.3.13 | +| POSITIVE | Positive 32-bit integer | No | | +| POSITIVEN | Positive non-null 32-bit integer | No | | +| RAW | Binary data | No | | +| ROWID | Row address | No | | +| SIGNTYPE | -1, 0 or 1 | No | | +| SIMPLE_DOUBLE | Double precision floating-point number | Yes | 0.3.13 | +| SIMPLE_FLOAT | Single precision floating-point number | Yes | 0.3.13 | +| SIMPLE_INTEGER | 32-bit integer | Yes | 0.3.13 | +| SMALLINT | 16-bit integer | Yes | 0.1 | +| SYS_REFCURSOR | Cursor variable | Yes | 0.3.11 | +| TIMESTAMP | Date and time | Yes | 0.3.7 | +| VARCHAR(*n*) | Variable-length string | Yes | 0.1 | +| VARCHAR2(*n*) | Variable-length string | Yes | 0.1 | +| UROWID | Row address | No | | +| UTL_FILE.FILE_TYPE | File handle | Yes | 0.1 | + +## Operators and Expressions + +Oracle PL/SQL operators and expressions supported by HPL/SQL: + +| Operator | Description | Supported | Since | +| --- | --- | --- | --- | +| [|| Operator]({{< ref "twopipes" >}}) | String concatenation | Yes | 0.1 | + +## Statements + +Oracle PL/SQL statements supported by HPL/SQL: + +| Statement | Description | Supported | Since | +| --- | --- | --- | --- | +| [:=]({{< ref "assign" >}}) | Assignment statement | Yes | 0.1 | +| [CREATE FUNCTION]({{< ref "create-function" >}}) | Create a user-defined function | Yes | 0.3.1 | +| [CREATE PACKAGE]({{< ref "create-package" >}}) | Create a package | Yes | 0.3.13 | +| [CREATE PROCEDURE]({{< ref "create-procedure" >}}) | Create a stored procedure | Yes | 0.3.1 | +| [NULL]({{< ref "null" >}}) | No operation | Yes | 0.3.13 | +| [SELECT INTO]({{< ref "select-into" >}}) | Assign values from query | Yes | 0.1 | diff --git a/content/docs/latest/user/hive-hplsql/features.md b/content/docs/latest/user/hive-hplsql/features.md new file mode 100644 index 00000000..e7287c60 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/features.md @@ -0,0 +1,15 @@ +--- +title: "Apache Hive : Key Features" +date: 2026-08-12 +--- + +# Apache Hive : Key Features + +HPL/SQL key features: + +- Flow of Control Statements +- Built-in Functions +- Stored Procedures, Functions and Packages +- Exception and Condition Handling +- On-the-fly SQL Conversion +- Polyglot Persistence diff --git a/content/docs/latest/user/hive-hplsql/file-io/_index.md b/content/docs/latest/user/hive-hplsql/file-io/_index.md new file mode 100644 index 00000000..2eee5694 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/file-io/_index.md @@ -0,0 +1,4 @@ +--- +title: "File I/O Operations" +date: 2026-08-12 +--- diff --git a/content/docs/latest/user/hive-hplsql/file-io/utl-file.md b/content/docs/latest/user/hive-hplsql/file-io/utl-file.md new file mode 100644 index 00000000..5122934f --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/file-io/utl-file.md @@ -0,0 +1,199 @@ +--- +title: "Apache Hive : UTL_FILE Package - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : UTL_FILE Package - PL/HQL Reference + +UTL_FILE package allows you to read and write HDFS files: + +**Example:** + +``` +DECLARE + f UTL_FILE.FILE_TYPE; +BEGIN + f := UTL_FILE.FOPEN('/user/dm', 'hello.txt', 'w'); + UTL_FILE.PUT_LINE(f, 'Hello, world!'); + UTL_FILE.FCLOSE(f); +END; +``` + +In this example we create */user/dm/hello.txt* in HDFS, write a single line and close the file. + +## UTL_FILE.FILE_TYPE Type + +Before you can work with a file using UTL_FILE package you have to declare a variable of UTL_FILE.FILE_TYPE. You assign a value to this variable using UTL_FILE.FOPEN function and then use it in all other functions as an argument. + +Declaring UTL_FILE.FILE_TYPE variables: + +``` +DECLARE + f UTL_FILE.FILE_TYPE; + f2 UTL_FILE.FILE_TYPE; +``` + +## FOPEN Function + +FOPEN function opens a file. + +**Syntax:** + +``` +file_handle: = FOPEN(directory, file, mode); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Description** | +| --- | --- | --- | +| directory | VARCHAR | Directory name | +| file | VARCHAR | File name | +| mode | VARCHAR | Open mode: 'w' | + +**File Open Modes:** + +- 'r' - Open file for reading. +- 'w' - Open file for writing. If the file does not exist it is created. If the file already exists its content is overwritten. + +**Return Value:** + +FOPEN returns UTL_FILE.FILE_TYPE file handle that you have to pass to all other functions operating on the file. + +**Example:** + +``` +DECLARE + f UTL_FILE.FILE_TYPE; +BEGIN + f := UTL_FILE.FOPEN('/user/dm', 'hello.txt', 'w'); +END; +``` + +## GET_LINE Function + +GET_LINE function reads a text string from an open file. The function reads until a new line (not included to the output string), end of file or the specified maximum length. + +**Syntax:** + +``` +UTL_FILE.GET_LINE(file_handle, var [, len]); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Description** | +| --- | --- | --- | +| file_handle | UTL_FILE.FILE_TYPE | Open file handle | +| var | VARCHAR | Variable to store the line | +| len | INT | Maximum line length, optional | + +**Return Value:** + +No. + +**Example:** + +``` +DECLARE + f UTL_FILE.FILE_TYPE; + s VARCHAR(100); +BEGIN + f := UTL_FILE.FOPEN('/user/dm', 'hello.txt', 'r'); + UTL_FILE.GET_LINE(f, s, 100); +END; +``` + +## PUT_LINE Function + +PUT_LINE function writes a text string to the file. The function appends a line terminator. + +**Syntax:** + +``` +UTL_FILE.PUT_LINE(file_handle, text); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Description** | +| --- | --- | --- | +| file_handle | UTL_FILE.FILE_TYPE | Open file handle | +| text | VARCHAR | Text string to write | + +**Return Value:** + +No. + +**Example:** + +``` +DECLARE + f UTL_FILE.FILE_TYPE; +BEGIN + f := UTL_FILE.FOPEN('/user/dm', 'hello.txt', 'w'); + UTL_FILE.PUT_LINE(f, 'Hello, world!'); +END; +``` +## PUT Function + +PUT_LINE function writes a text string to the file. Unlike PUT_LINE this function **does not** append a line terminator. + +**Syntax:** + +``` +UTL_FILE.PUT(file_handle, text); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Description** | +| --- | --- | --- | +| file_handle | UTL_FILE.FILE_TYPE | Open file handle | +| text | VARCHAR | Text string to write | + +**Return Value:** + +No. + +**Example:** + +``` +DECLARE + f UTL_FILE.FILE_TYPE; +BEGIN + f := UTL_FILE.FOPEN('/user/dm', 'hello.txt', 'w'); + UTL_FILE.PUT(f, 'Hello, world!'); +END; +``` + +## FCLOSE Function + +FCLOSE function closes an open file identified by a file handle. + +**Syntax:** + +``` +UTL_FILE.FCLOSE(file_handle); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Description** | +| --- | --- | --- | +| file_handle | UTL_FILE.FILE_TYPE | Open file handle | + +**Return Value:** + +No. + +**Example:** + +``` +DECLARE + f UTL_FILE.FILE_TYPE; +BEGIN + f := UTL_FILE.FOPEN('/user/dm', 'hello.txt', 'w'); + UTL_FILE.FCLOSE(f); +END; +``` diff --git a/content/docs/latest/user/hive-hplsql/functions/_index.md b/content/docs/latest/user/hive-hplsql/functions/_index.md new file mode 100644 index 00000000..febfa53a --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/_index.md @@ -0,0 +1,4 @@ +--- +title: "Functions" +date: 2026-08-12 +--- diff --git a/content/docs/latest/user/hive-hplsql/functions/cast.md b/content/docs/latest/user/hive-hplsql/functions/cast.md new file mode 100644 index 00000000..5a9aad3f --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/cast.md @@ -0,0 +1,42 @@ +--- +title: "Apache Hive : CAST Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : CAST Function - PL/HQL Reference + +CAST function converts an expression to the specified data type. + +**Syntax**: + +``` +CAST(expression AS datatype[(length)]); +``` + +Notes: + +- If *length* is specified for CAST as CHAR or VARCHAR function, the resulting string is truncated to this length. + +**Example 1:** + +Convert to a string with the specified length: + +``` +CAST('Abc' AS CHAR(1)); +-- +A +``` + +**Example 2:** + +Truncate a timestamp string: + +``` +CAST(TIMESTAMP '2015-03-12 10:58:34.111' AS CHAR(10)); +-- +2015-03-12 +``` + +**Compatibility**: Oracle, Microsoft SQL Server, IBM DB2, Teradata, PostgreSQL, MySQL and Netezza + +**Version**: PL/HQL 0.03 diff --git a/content/docs/latest/user/hive-hplsql/functions/char.md b/content/docs/latest/user/hive-hplsql/functions/char.md new file mode 100644 index 00000000..1fc2571b --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/char.md @@ -0,0 +1,33 @@ +--- +title: "Apache Hive : CHAR Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : CHAR Function - PL/HQL Reference + +CHAR function converts a number to string. + +**Syntax**: + +``` +CHAR(num_expression); +``` + +**Return Type:** + +STRING + +**Example 1:** + +``` +CHAR(1000); +-- +1000 +``` + +**Compatibility**: IBM DB2 + +**Version**: PL/HQL 0.03 + +See also: +- [TO_CHAR Function]({{< ref "to-char" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/coalesce.md b/content/docs/latest/user/hive-hplsql/functions/coalesce.md new file mode 100644 index 00000000..79aab23e --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/coalesce.md @@ -0,0 +1,49 @@ +--- +title: "Apache Hive : COALESCE Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : COALESCE Function - PL/HQL Reference + +COALESCE function returns first non-NULL expression. + +**Syntax**: + +``` +COALESCE(expr1, expr2 [, expr3, ...]); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | +| --- | --- | --- | +| exprN | Any | Variable or expression | + +**Notes**: + +- When first non-NULL expression is found the following expressions are not evaluated +- COALESCE and [NVL]({{< ref "nvl" >}}) functions are synonyms + +**Return Value:** + +- First non-NULL expression +- NULL if all expressions evaluate to NULL + +**Return Type:** + +The data type of first non-NULL expression. + +**Example 1:** + +``` +COALESCE(NULL, 1, 2, 3); +``` + +Result: 1 + +**Compatibility**: Oracle, IBM DB2, Teradata, Microsoft SQL Server, PostgreSQL, MySQL and Netezza + +**Version**: PL/HQL 0.03 + +See also: +- [NVL]({{< ref "nvl" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/concat.md b/content/docs/latest/user/hive-hplsql/functions/concat.md new file mode 100644 index 00000000..b37d9fac --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/concat.md @@ -0,0 +1,38 @@ +--- +title: "Apache Hive : CONCAT Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : CONCAT Function - PL/HQL Reference + +CONCAT function concatenates two or more strings. + +**Syntax**: + +``` +CONCAT(expr, expr2 [, expr3, ...]); +``` + +**Notes**: + +- If an expression evaluates to NULL it is treated as an empty string +- CONCAT returns NULL only if all expressions evaluate to NULL + +**Return Type:** + +STRING + +**Example:** + +``` +CONCAT('a', 'b', NULL, 'c'); +``` + +Result: abc + +**Compatibility**: Oracle, IBM DB2, Teradata, Microsoft SQL Server, PostgreSQL, MySQL and Netezza + +**Version**: PL/HQL 0.3.1 + +See also: +- [|| Operator]({{< ref "twopipes" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/current-date.md b/content/docs/latest/user/hive-hplsql/functions/current-date.md new file mode 100644 index 00000000..c913ce3e --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/current-date.md @@ -0,0 +1,30 @@ +--- +title: "Apache Hive : CURRENT_DATE Function" +date: 2026-08-12 +--- + +# Apache Hive : CURRENT_DATE Function + +CURRENT_DATE function return the current date (year, month and day). + +**Syntax**: + +``` +CURRENT_DATE | CURRENT DATE +``` + +**Return Type:** + +DATE + +**Compatibility**: IBM DB2, Teradata, MySQL. + +**Version:** HPL/SQL 0.01 + +See also: + +- [CURRENT_TIMESTAMP]({{< ref "current-timestamp" >}}) +- [FROM_UNIXTIME]({{< ref "from-unixtime" >}}) +- [NOW]({{< ref "now" >}}) +- [SYSDATE]({{< ref "sysdate" >}}) +- [UNIX_TIMESTAMP]({{< ref "unix-timestamp" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/current-timestamp.md b/content/docs/latest/user/hive-hplsql/functions/current-timestamp.md new file mode 100644 index 00000000..651db949 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/current-timestamp.md @@ -0,0 +1,46 @@ +--- +title: "Apache Hive : CURRENT_TIMESTAMP Function" +date: 2026-08-12 +--- + +# Apache Hive : CURRENT_TIMESTAMP Function + +CURRENT_TIMESTAMP function returns the current date and time (year, month, day, hour, minute, seconds and fractional seconds). + +**Syntax**: + +``` +CURRENT_TIMESTAMP | CURRENT TIMESTAMP [(precision)] +``` + +**Parameters:** + +| **Parameter** | **Value** | **Description** || +| --- | --- | --- | --- | +| *precision* | Variable or expression | Fractional seconds precision, from 0 to 3 | Default 3 | + +**Return Type:** + +TIMESTAMP + +**Example**: + +Get the current and date and time without fraction: + +``` +CURRENT_TIMESTAMP(0) +-- +2015-03-02 13:04:42 +``` + +**Compatibility**: Oracle, IBM DB2, Teradata, MySQL. + +**Version:** HPL/SQL 0.1 + +See also: + +- [CURRENT_DATE]({{< ref "current-date" >}}) +- [FROM_UNIXTIME]({{< ref "from-unixtime" >}}) +- [NOW]({{< ref "now" >}}) +- [SYSDATE]({{< ref "sysdate" >}}) +- [UNIX_TIMESTAMP]({{< ref "unix-timestamp" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/current-user.md b/content/docs/latest/user/hive-hplsql/functions/current-user.md new file mode 100644 index 00000000..115c3705 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/current-user.md @@ -0,0 +1,36 @@ +--- +title: "Apache Hive : CURRENT_USER Function - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : CURRENT_USER Function - PL/HQL + +CURRENT_USER function returns the name of the user executing the current PL/HQL script. + +**Syntax**: + +``` +CURRENT_USER | CURRENT USER +``` + +**Return Type:** + +STRING + +**Example**: + +Get the current user: + +``` +CURRENT_USER +-- +paul +``` + +**Compatibility**: IBM DB2, Teradata. + +**Version:** PL/HQL 0.3.11 + +See also: + +- [USER]({{< ref "user" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/date.md b/content/docs/latest/user/hive-hplsql/functions/date.md new file mode 100644 index 00000000..ddb87e09 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/date.md @@ -0,0 +1,37 @@ +--- +title: "Apache Hive : DATE Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : DATE Function - PL/HQL Reference + +DATE function converts an expression to DATE data type. + +**Syntax**: + +``` +DATE(expression); +``` + +**Return Data Type:** + +DATE + +**Example:** + +Convert a string and timestamp to DATE: + +``` +DATE('2015-03-12'); +DATE('2015' || '-03-' || '12'); +DATE(TIMESTAMP '2015-03-12 10:58:34.111'); +``` + +**Compatibility**: IBM DB2 + +**Version**: PL/HQL 0.03 + +See also: +- [DATE Literal]({{< ref "date-literal" >}}) +- [TIMESTAMP Literal]({{< ref "timestamp-literal" >}}) +- [TIMESTAMP_ISO Function]({{< ref "timestamp-iso" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/dbms-output.md b/content/docs/latest/user/hive-hplsql/functions/dbms-output.md new file mode 100644 index 00000000..9e36fb7c --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/dbms-output.md @@ -0,0 +1,46 @@ +--- +title: "Apache Hive : DBMS_OUTPUT Package - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : DBMS_OUTPUT Package - PL/HQL Reference + +DBMS_OUTPUT package allows you to send messages and can be helpful to debug programs + +**Example:** + +``` +BEGIN + DBMS_OUTPUT.PUT_LINE('Hello, world!'); +END; +``` + +**Compatibility**: Oracle + +## PUT_LINE Function + +PUT_LINE function writes a text string to the standard output (screen, by default). The function appends a line terminator. + +**Syntax:** + +``` +DBMS_OUTPUT.PUT_LINE(text); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Description** | +| --- | --- | --- | +| text | VARCHAR | Text string or expression | + +**Return Value:** + +No. + +**Example:** + +``` +BEGIN + DBMS_OUTPUT.PUT_LINE('Hello, world!'); +END; +``` diff --git a/content/docs/latest/user/hive-hplsql/functions/decode.md b/content/docs/latest/user/hive-hplsql/functions/decode.md new file mode 100644 index 00000000..1ebe2853 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/decode.md @@ -0,0 +1,38 @@ +--- +title: "Apache Hive : DECODE Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : DECODE Function - PL/HQL Reference + +DECODE function allows you to implement IF-THEN-ELSE logic. + +**Syntax:** + +``` +DECODE(expr, when_exp1, then_expr1 [, ...n] [, else_expr]) +``` + +**Notes**: + +- If *expr* is NULL it will match the first *when_exprN* that is NULL +- If *when_exprN* is not matched *then_exprN* is not evaluated + +**Examples**: + +``` +DECLARE var1 INT DEFAULT 3; + +PRINT DECODE (var1, 1, 'A', 2, 'B', 3, 'C'); -- Result: C +PRINT DECODE (var1, 1, 'A', 2, 'B', 'C'); -- Result: C + +SET var1 = NULL; +PRINT DECODE (var1, 1, 'A', 2, 'B', NULL, 'C'); -- Result: C +``` + +**Compatibility:** Oracle, IBM DB2 and Teradata + +**Version**: PL/HQL 0.3.1 + +See also: +- [CASE Expression]({{< ref "case" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/from-unixtime.md b/content/docs/latest/user/hive-hplsql/functions/from-unixtime.md new file mode 100644 index 00000000..25a50b24 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/from-unixtime.md @@ -0,0 +1,48 @@ +--- +title: "Apache Hive : FROM_UNIXTIME Function" +date: 2026-08-12 +--- + +# Apache Hive : FROM_UNIXTIME Function + +FROM_UNIXTIME function converts the specified number of seconds since 1970-01-01 00:00:00 to timestamp value. + +**Syntax**: + +``` +FROM_UNIXTIME(epoch, [format]) +``` + +**Parameters**: +- *epoch* is the number of seconds since 1970-01-01 00:00:00 +- *format* is the timestamp format, optional. The default format is yyyy-MM-dd HH:mm:ss + +**Return Type:** + +STRING + +**Example**: + +Convert the number of seconds to timestamp value: + +``` +from_unixtime(1447141681); +--- +2015-11-10 04:48:01 + +from_unixtime(1447141681, 'yyyy-MM-dd'); +--- +2015-11-10 +``` + +**Compatibility**: Hive. + +**Version:** HPL/SQL 0.3.17 + +See also: + +- [CURRENT_DATE]({{< ref "current-date" >}}) +- [CURRENT_TIMESTAMP]({{< ref "current-timestamp" >}}) +- [NOW]({{< ref "now" >}}) +- [SYSDATE]({{< ref "sysdate" >}}) +- [UNIX_TIMESTAMP]({{< ref "unix-timestamp" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/instr.md b/content/docs/latest/user/hive-hplsql/functions/instr.md new file mode 100644 index 00000000..ca692b5e --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/instr.md @@ -0,0 +1,70 @@ +--- +title: "Apache Hive : INSTR Function - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : INSTR Function - PL/HQL + +INSTR function returns the starting position of a substring within a string. + +**Syntax**: + +``` +INSTR(string, substring [, position [, occurrence]]) +``` + +**Notes**: + +- *position* specifies the staring position for search, the default is 1 (the beginning of *string*) +- If *position* is negative INSTR counts and searches backward from the end of string +- *occurrence* specifies which occurrence of *substring* to search, the default is 1 (finds the first occurrence) +- If *string* is NULL the return value is NULL +- if *string* is not NULL and *substring* not found the return value is 0 + +**Return Type:** + +INT + +**Example 1**: + +Find the first occurrence starting from the beginning: + +``` +INSTR('abc', 'b') -- Result 2 +``` + +**Example 2**: + +Find the first occurrence starting from the 3rd position: + +``` +INSTR('abcabc', 'b', 3) -- Result 5 +``` + +**Example 3**: + +Find the second occurrence starting from the 3rd position: + +``` +INSTR('abcabcabc', 'b', 3, 2) -- Result 8 +``` + +**Example 4**: + +Find the first occurrence starting from the 3rd position from the end: + +``` +INSTR('abcabcabc', 'b', -3) -- Result 5 +``` + +**Example 5**: + +Find the second occurrence starting from the 3rd position from the end: + +``` +INSTR('abcabcabc', 'b', -3, 2) -- Result 2 +``` + +**Compatibility**: Oracle, IBM DB2 and Teradata. + +**Version:** PL/HQL 0.3.11 diff --git a/content/docs/latest/user/hive-hplsql/functions/len.md b/content/docs/latest/user/hive-hplsql/functions/len.md new file mode 100644 index 00000000..350890da --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/len.md @@ -0,0 +1,33 @@ +--- +title: "Apache Hive : LEN Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : LEN Function - PL/HQL Reference + +LEN function returns the length of the specified string expression in characters, **excluding** the trailing blanks. + +**Syntax**: + +``` +LEN(string_expression); +``` + +**Return Data Type:** + +STRING + +**Example:** + +``` +LEN('Abc '); +--- +3 +``` + +**Compatibility**: Microsoft SQL Server + +**Version**: PL/HQL 0.03 + +See also: +- [LENGTH]({{< ref "length" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/length.md b/content/docs/latest/user/hive-hplsql/functions/length.md new file mode 100644 index 00000000..5bcec1b2 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/length.md @@ -0,0 +1,33 @@ +--- +title: "Apache Hive : LENGTH Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : LENGTH Function - PL/HQL Reference + +LENGTH function returns the length of the specified string expression in characters. + +**Syntax**: + +``` +LENGTH(string_expression); +``` + +**Return Data Type:** + +STRING + +**Example:** + +``` +LENGTH('Abc '); +--- +4 +``` + +**Compatibility**: Oracle, IBM DB2, Teradata, PostgreSQL, MySQL and Netezza + +**Version**: PL/HQL 0.03 + +See also: +- [LEN]({{< ref "len" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/lower.md b/content/docs/latest/user/hive-hplsql/functions/lower.md new file mode 100644 index 00000000..6aae8b93 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/lower.md @@ -0,0 +1,32 @@ +--- +title: "Apache Hive : LOWER Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : LOWER Function - PL/HQL Reference + +LOWER function converts a string expression to lower case. + +**Syntax**: + +``` +LOWER(expression); +``` + +**Return Data Type:** + +STRING + +**Example:** + +Convert a string to lower case: + +``` +LOWER('ABC'); +--- +abc +``` + +**Compatibility**: Oracle, Microsoft SQL Server, IBM DB2, Teradata, PostgreSQL, MySQL and Netezza + +**Version**: PL/HQL 0.03 diff --git a/content/docs/latest/user/hive-hplsql/functions/max-part-date.md b/content/docs/latest/user/hive-hplsql/functions/max-part-date.md new file mode 100644 index 00000000..c3e53bb7 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/max-part-date.md @@ -0,0 +1,82 @@ +--- +title: "Apache Hive : MAX_PART_DATE Function - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : MAX_PART_DATE Function - PL/HQL + +MAX_PART_DATE function finds the maximum value for the specified partition column of type DATE. + +**Syntax**: + +``` +MAX_PART_DATE([db_name.]table_name [, column_name [, part_col=filter, ...]]); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| [dbname.]table_name | VARCHAR | Identifier, variable or expression | Table name | +| column_name | VARCHAR | Identifier, variable or expression | Partition column name | +| part_col=filter | | | Partition filter | + +**Notes**: + +- If column name is not specified, the first partition column is used +- Partition filter applied before finding the maximum value + +**Return Value:** + +- The maximum date for the specified partition +- NULL if the table or partition do not exist, or the table is empty + +**Return Type:** + +DATE. + +**Example 1:** + +Table *db.orders* is partitioned by *local_date* and has the following partitions: + +| local_date=2014-12-02 | +| --- | +| local_date=2014-12-03 | +| local_date=2014-12-04 | + +Find the maximum value of the partition: + +``` +MAX_PART_DATE(db.orders); +``` + +Result: 2014-12-04 + +**Example 2:** + +Table *db.sales* is partitioned by *country* and *local_date* and has the following partitions: + +| country=US/local_date=2014-12-02 | +| --- | +| country=US/local_date=2014-12-03 | +| country=UK/local_date=2014-12-04 | + +Find the maximum value for *local_date* partition column for country US: + +``` +MAX_PART_DATE(db.sales, local_date, country='US'); +``` + +Result: 2014-12-03 + +**Compatibility**: PL/HQL extension. + +**Version:** PL/HQL 0.01 + +See also: + +- [MIN_PART_DATE(table, colname, partition_spec)]({{< ref "min-part-date" >}}) +- [MAX_PART_STRING(table, colname, partition_spec)]({{< ref "max-part-string" >}}) +- [MIN_PART_STRING(table, colname, partition_spec)]({{< ref "min-part-string" >}}) +- [MAX_PART_INT(table, colname, partition_spec)]({{< ref "max-part-int" >}}) +- [MIN_PART_INT(table, colname, partition_spec)]({{< ref "min-part-int" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/max-part-int.md b/content/docs/latest/user/hive-hplsql/functions/max-part-int.md new file mode 100644 index 00000000..d01fb22a --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/max-part-int.md @@ -0,0 +1,85 @@ +--- +title: "Apache Hive : MAX_PART_INT Function - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : MAX_PART_INT Function - PL/HQL + +MAX_PART_INT function finds the maximum value for the specified partition column of type INT. + +**Syntax**: + +``` +MAX_PART_INT([db_name.]table_name [, column_name [, part_col=filter, ...]]); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| [dbname.]table_name | VARCHAR | Identifier, variable or expression | Table name | +| column_name | VARCHAR | Identifier, variable or expression | Partition column name | +| part_col=filter | | | Partition filter | + +**Notes**: + +- If column name is not specified, the first partition column is used +- Partition filter applied before finding the maximum value +- If the partition contains non-integer values they are ignored + +**Return Value:** + +- The maximum INT value for the specified partition +- NULL if the table or partition do not exist, or the table is empty + +**Return Type:** + +INT. + +**Example 1:** + +Table *db.orders* is partitioned by *country*, *local_dt* and *hour* and has the following partitions: + +| country=US/local_dt=2014-12-05/hour=1 | +| --- | +| country=US/local_dt=2014-12-05/hour=2 | +| country=US/local_dt=2014-12-05/hour=3 | +| country=US/local_dt=2014-12-05/hour=UNKNOWN | + +Find the maximum value of the partition *hour*: + +``` +MAX_PART_INT(db.orders, hour); +``` + +Result: 3 + +**Example 2:** + +Table *db.sales* is partitioned by *country*, *local_date* and *hour* has the following partitions: + +| country=US/local_dt=2014-12-06/hour=1 | +| --- | +| country=US/local_dt=2014-12-07/hour=2 | +| country=US/local_dt=2014-12-07/hour=UNKNOWN | +| country=US/local_dt=2014-12-08/hour=3 | + +Find the maximum value for *hour* partition for local_date '2014-12-07': + +``` +MAX_PART_INT(db.sales, hour, local_date='2014-12-07'); +``` + +Result: 2 + +**Compatibility**: PL/HQL extension. + +**Version:** PL/HQL 0.01 + +See also: + +- [MIN_PART_INT(table, colname, partition_spec)]({{< ref "min-part-int" >}}) +- [MAX_PART_STRING(table, colname, partition_spec)]({{< ref "max-part-string" >}}) +- [MIN_PART_STRING(table, colname, partition_spec)]({{< ref "min-part-string" >}}) +- [MAX_PART_DATE(table, colname, partition_spec)]({{< ref "max-part-date" >}}) +- [MIN_PART_DATE(table, colname, partition_spec)]({{< ref "min-part-date" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/max-part-string.md b/content/docs/latest/user/hive-hplsql/functions/max-part-string.md new file mode 100644 index 00000000..4265c607 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/max-part-string.md @@ -0,0 +1,82 @@ +--- +title: "Apache Hive : MAX_PART_STRING Function - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : MAX_PART_STRING Function - PL/HQL + +MAX_PART_STRING function finds the maximum value (last in alphabetical order) for the specified partition column of type STRING (VARCHAR/CHAR). + +**Syntax**: + +``` +MAX_PART_STRING([db_name.]table_name [, column_name [, part_col=filter, ...]]); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| [dbname.]table_name | VARCHAR | Identifier, variable or expression | Table name | +| column_name | VARCHAR | Identifier, variable or expression | Partition column name | +| part_col=filter | | | Partition filter | + +**Notes**: + +- If column name is not specified, the first partition column is used +- Partition filter applied before finding the maximum value + +**Return Value:** + +- The maximum string for the specified partition +- NULL if the table or partition do not exist, or the table is empty + +**Return Type:** + +STRING (VARCHAR/CHAR). + +**Example 1:** + +Table *db.orders* is partitioned by *country* and has the following partitions: + +| country=US | +| --- | +| country=UK | +| country=DE | + +Find the maximum value of the partition: + +``` +MAX_PART_STRING(db.orders); +``` + +Result: US + +**Example 2:** + +Table *db.sales* is partitioned by *country* and *local_date* and has the following partitions: + +| country=US/local_date=2014-12-02 | +| --- | +| country=DE/local_date=2014-12-04 | +| country=UK/local_date=2014-12-04 | + +Find the maximum value for *country* partition column for local_date '2014-12-04': + +``` +MAX_PART_STRING(db.sales, country, local_date='2014-12-04'); +``` + +Result: UK + +**Compatibility**: PL/HQL extension. + +**Version:** PL/HQL 0.01 + +See also: + +- [MIN_PART_STRING(table, colname, partition_spec)]({{< ref "min-part-string" >}}) +- [MAX_PART_INT(table, colname, partition_spec)]({{< ref "max-part-int" >}}) +- [MIN_PART_INT(table, colname, partition_spec)]({{< ref "min-part-int" >}}) +- [MAX_PART_DATE(table, colname, partition_spec)]({{< ref "max-part-date" >}}) +- [MIN_PART_DATE(table, colname, partition_spec)]({{< ref "min-part-date" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/min-part-date.md b/content/docs/latest/user/hive-hplsql/functions/min-part-date.md new file mode 100644 index 00000000..367af9e9 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/min-part-date.md @@ -0,0 +1,82 @@ +--- +title: "Apache Hive : MIN_PART_DATE Function - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : MIN_PART_DATE Function - PL/HQL + +MIN_PART_DATE function finds the minimum value for the specified partition column of type DATE. + +**Syntax**: + +``` +MIN_PART_DATE([db_name.]table_name [, column_name [, part_col=filter, ...]]); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| [dbname.]table_name | VARCHAR | Identifier, variable or expression | Table name | +| column_name | VARCHAR | Identifier, variable or expression | Partition column name | +| part_col=filter | | | Partition filter | + +**Notes**: + +- If column name is not specified, the first partition column is used +- Partition filter applied before finding the minimum value + +**Return Value:** + +- The minimum date for the specified partition +- NULL if the table or partition do not exist, or the table is empty + +**Return Type:** + +DATE. + +**Example 1:** + +Table *db.orders* is partitioned by *local_date* and has the following partitions: + +| local_date=2014-12-02 | +| --- | +| local_date=2014-12-03 | +| local_date=2014-12-04 | + +Find the minimum value of the partition: + +``` +MIN_PART_DATE(db.orders); +``` + +Result: 2014-12-02 + +**Example 2:** + +Table *db.sales* is partitioned by *country* and *local_date* and has the following partitions: + +| country=US/local_date=2014-12-02 | +| --- | +| country=US/local_date=2014-12-03 | +| country=UK/local_date=2014-12-04 | + +Find the minimum value for *local_date* partition column for country US: + +``` +MIN_PARTITION_DATE(db.sales, local_date, country='US'); +``` + +Result: 2014-12-02 + +**Compatibility**: PL/HQL extension. + +**Version:** PL/HQL 0.01 + +See also: + +- [MAX_PART_DATE(table, colname, partition_spec)]({{< ref "max-part-date" >}}) +- [MAX_PART_STRING(table, colname, partition_spec)]({{< ref "max-part-string" >}}) +- [MIN_PART_STRING(table, colname, partition_spec)]({{< ref "min-part-string" >}}) +- [MAX_PART_INT(table, colname, partition_spec)]({{< ref "max-part-int" >}}) +- [MIN_PART_INT(table, colname, partition_spec)]({{< ref "min-part-int" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/min-part-int.md b/content/docs/latest/user/hive-hplsql/functions/min-part-int.md new file mode 100644 index 00000000..ab3ef577 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/min-part-int.md @@ -0,0 +1,86 @@ +--- +title: "Apache Hive : MIN_PART_INT Function - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : MIN_PART_INT Function - PL/HQL + +MIN_PART_INT function finds the minimum value for the specified partition column of type INT. + +**Syntax**: + +``` +MIN_PART_INT([db_name.]table_name [, column_name [, part_col=filter, ...]]); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| [dbname.]table_name | VARCHAR | Identifier, variable or expression | Table name | +| column_name | VARCHAR | Identifier, variable or expression | Partition column name | +| part_col=filter | | | Partition filter | + +**Notes**: + +- If column name is not specified, the first partition column is used +- Partition filter applied before finding the minimum value +- If the partition contains non-integer values they are ignored + +**Return Value:** + +- The minimum INT value for the specified partition +- NULL if the table or partition do not exist, or the table is empty + +**Return Type:** + +INT. + +**Example 1:** + +Table *db.orders* is partitioned by *country*, *local_dt* and *hour* and has the following partitions: + +| country=US/local_dt=2014-12-05/hour=1 | +| --- | +| country=US/local_dt=2014-12-05/hour=2 | +| country=US/local_dt=2014-12-05/hour=3 | +| country=US/local_dt=2014-12-05/hour=UNKNOWN | + +Find the minimum value of the partition *hour*: + +``` +MIN_PART_INT(db.orders, hour); +``` + +Result: 1 + +**Example 2:** + +Table *db.sales* is partitioned by *country*, *local_date* and *hour* has the following partitions: + +| country=US/local_dt=2014-12-06/hour=1 | +| --- | +| country=US/local_dt=2014-12-07/hour=4 | +| country=US/local_dt=2014-12-07/hour=5 | +| country=US/local_dt=2014-12-07/hour=UNKNOWN | +| country=US/local_dt=2014-12-08/hour=3 | + +Find the maximum value for *hour* partition for local_date '2014-12-07': + +``` +MIN_PART_IN(db.sales, hour, local_date='2014-12-07'); +``` + +Result: 4 + +**Compatibility**: PL/HQL extension. + +**Version:** PL/HQL 0.01 + +See also: + +- [MAX_PART_INT(table, colname, partition_spec)]({{< ref "max-part-int" >}}) +- [MAX_PART_STRING(table, colname, partition_spec)]({{< ref "max-part-string" >}}) +- [MIN_PART_STRING(table, colname, partition_spec)]({{< ref "min-part-string" >}}) +- [MAX_PART_DATE(table, colname, partition_spec)]({{< ref "max-part-date" >}}) +- [MIN_PART_DATE(table, colname, partition_spec)]({{< ref "min-part-date" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/min-part-string.md b/content/docs/latest/user/hive-hplsql/functions/min-part-string.md new file mode 100644 index 00000000..3ff851a7 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/min-part-string.md @@ -0,0 +1,82 @@ +--- +title: "Apache Hive : MIN_PART_STRING Function - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : MIN_PART_STRING Function - PL/HQL + +MIN_PART_STRING function finds the minimum value (first in alphabetical order) for the specified partition column of type STRING (VARCHAR/CHAR). + +**Syntax**: + +``` +MIN_PART_STRING([db_name.]table_name [, column_name [, part_col=filter, ...]]); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| [dbname.]table_name | VARCHAR | Identifier, variable or expression | Table name | +| column_name | VARCHAR | Identifier, variable or expression | Partition column name | +| part_col=filter | | | Partition filter | + +**Notes**: + +- If column name is not specified, the first partition column is used +- Partition filter applied before finding the minimum value + +**Return Value:** + +- The minimum string for the specified partition +- NULL if the table or partition do not exist, or the table is empty + +**Return Type:** + +STRING (VARCHAR/CHAR). + +**Example 1:** + +Table *db.orders* is partitioned by *country* and has the following partitions: + +| country=US | +| --- | +| country=UK | +| country=DE | + +Find the minimum value of the partition: + +``` +MIN_PART_STRING(db.orders); +``` + +Result: DE + +**Example 2:** + +Table *db.sales* is partitioned by *country* and *local_date* and has the following partitions: + +| country=US/local_date=2014-12-02 | +| --- | +| country=DE/local_date=2014-12-04 | +| country=UK/local_date=2014-12-04 | + +Find the minimum value for *country* partition column for local_date '2014-12-04': + +``` +MIN_PARTITION_STRING(db.sales, country, local_date='2014-12-04'); +``` + +Result: DE + +**Compatibility**: PL/HQL extension. + +**Version:** PL/HQL 0.01 + +See also: + +- [MAX_PART_STRING(table, colname, partition_spec)]({{< ref "max-part-string" >}}) +- [MAX_PART_INT(table, colname, partition_spec)]({{< ref "max-part-int" >}}) +- [MIN_PART_INT(table, colname, partition_spec)]({{< ref "min-part-int" >}}) +- [MAX_PART_DATE(table, colname, partition_spec)]({{< ref "max-part-date" >}}) +- [MIN_PART_DATE(table, colname, partition_spec)]({{< ref "min-part-date" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/now.md b/content/docs/latest/user/hive-hplsql/functions/now.md new file mode 100644 index 00000000..75f2818e --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/now.md @@ -0,0 +1,40 @@ +--- +title: "Apache Hive : NOW Function" +date: 2026-08-12 +--- + +# Apache Hive : NOW Function + +NOW function returns the current date and time (year, month, day, hour, minute, seconds and fractional seconds). + +**Syntax**: + +``` +NOW() +``` + +**Return Type:** + +TIMESTAMP + +**Example**: + +Get the current and date and time: + +``` +NOW() +-- +2015-11-02 07:59:25.833 +``` + +**Compatibility**: PostgreSQL and MySQL. + +**Version:** HPL/SQL 0.3.17 + +See also: + +- [CURRENT_DATE]({{< ref "current-date" >}}) +- [CURRENT_TIMESTAMP]({{< ref "current-timestamp" >}}) +- [FROM_UNIXTIME]({{< ref "from-unixtime" >}}) +- [UNIX_TIMESTAMP]({{< ref "unix-timestamp" >}}) +- [SYSDATE]({{< ref "sysdate" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/nvl.md b/content/docs/latest/user/hive-hplsql/functions/nvl.md new file mode 100644 index 00000000..2ef9f745 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/nvl.md @@ -0,0 +1,49 @@ +--- +title: "Apache Hive : NVL Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : NVL Function - PL/HQL Reference + +NVL function returns first non-NULL expression. + +**Syntax**: + +``` +NVL(expr1, expr2 [, expr3, ...]); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | +| --- | --- | --- | +| exprN | Any | Variable or expression | + +**Notes**: + +- When first non-NULL expression is found the following expressions are not evaluated +- NVL and [COALESCE]({{< ref "coalesce" >}}) functions are synonyms + +**Return Value:** + +- First non-NULL expression +- NULL if all expressions evaluate to NULL + +**Return Type:** + +The data type of first non-NULL expression. + +**Example 1:** + +``` +NVL(NULL, 1); +``` + +Result: 1 + +**Compatibility**: Oracle, IBM DB2 and Netezza. + +**Version**: PL/HQL 0.01 + +See also: +- [COALESCE]({{< ref "coalesce" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/nvl2.md b/content/docs/latest/user/hive-hplsql/functions/nvl2.md new file mode 100644 index 00000000..d30df1ce --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/nvl2.md @@ -0,0 +1,40 @@ +--- +title: "Apache Hive : NVL2 Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : NVL2 Function - PL/HQL Reference + +If the first expression is NOT NULL, NVL2 function returns the result of the second expression, otherwise it returns the result of the third expression. + +**Syntax**: + +``` +NVL2(expr1, expr2, expr3); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | +| --- | --- | --- | +| exprN | Any | Variable or expression | + +**Notes**: + +- If expr1 is not NULL, expr2 is only evaluated; and if expr1 is NULL, expr3 is only evaluated + +**Return Type:** + +The data type of the returned expression by expr2 or expr3 depending whether expr1 is NULL or not. + +**Example 1:** + +``` +NVL2(NULL, 1, 2); +``` + +Result: 2 + +**Compatibility**: Oracle and IBM DB2. + +**Version**: PL/HQL 0.01 diff --git a/content/docs/latest/user/hive-hplsql/functions/part-count-by.md b/content/docs/latest/user/hive-hplsql/functions/part-count-by.md new file mode 100644 index 00000000..fa34a100 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/part-count-by.md @@ -0,0 +1,72 @@ +--- +title: "Apache Hive : PART_COUNT_BY Function" +date: 2026-08-12 +--- + +# Apache Hive : PART_COUNT_BY Function + +PART_COUNT_BY function returns the number partitions grouped by specified partition columns in the table. + +**Syntax**: + +``` +PART_COUNT_BY([db_name.]table_name, [part_col, ...]); +``` + +**Parameters:** + +| [dbname.]table_name | Identifier, variable or expression | +| --- | --- | +| part_col | One or more partition columns used for aggregation | + +**Return Value:** + +- The number of top-level partitions if *part_col* is not specified +- Partition value and total number of existing partitions with the same value if *part_col* is not specified + +**Examples:** + +Table *db.orders* is partitioned by *dt* and *region* columns and has the following partitions: + +| dt=2015-09-01/region=1 | +| --- | +| dt=2015-09-01/region=2 | +| dt=2015-09-02/region=1 | +| dt=2015-09-03/region=3 | +| dt=2015-09-03/region=2 | + +Get the total number of distinct top-level partitions (dt=2015-09-01, dt=2015-09-02 and dt=2015-09-03): + +``` +part_count_by(db.orders); +-- +3 +``` + +Get the top level partitions and the number of its sub-partitions: + +``` +part_count_by(db.orders, dt); +-- +dt=2015-09-01 2 +dt=2015-09-02 1 +dt=2015-09-03 2 +``` + +Get the number of specified partitions: + +``` +part_count_by(db.orders, region); +-- +region=1 2 +region=2 2 +region=3 1 +``` + +**Compatibility**: HPL/SQL extension. + +**Version:** HPL/SQL 0.3.13 + +See also: +- [PART_COUNT]({{< ref "part-count" >}}) - Get the number of partitions +- [PART_LOC]({{< ref "part-loc" >}}) - Get the location of a partition diff --git a/content/docs/latest/user/hive-hplsql/functions/part-count.md b/content/docs/latest/user/hive-hplsql/functions/part-count.md new file mode 100644 index 00000000..3de80453 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/part-count.md @@ -0,0 +1,72 @@ +--- +title: "Apache Hive : PART_COUNT Function" +date: 2026-08-12 +--- + +# Apache Hive : PART_COUNT Function + +PART_COUNT function returns the number partitions in the specified table. + +**Syntax**: + +``` +PART_COUNT([db_name.]table_name, part_col=filter, ...); +``` + +**Parameters:** + +| [dbname.]table_name | Identifier, variable or expression | +| --- | --- | +| part_col=filter | One or more partition filters | + +**Notes**: + +- HPL/SQL uses the following Hive statement to get the partition information: + +``` +SHOW PARTITIONS db_name.tab_name [PARTITION (part_col=filter, ...)] +``` + +**Return Value:** + +- The number of partitions +- NULL if the table does not exist or an error occurs + +**Return Type:** + +INT + +**Examples:** + +Table *db.orders* is partitioned by *dt* and *region* columns and has the following partitions: + +| dt=2015-09-01/region=1 | +| --- | +| dt=2015-09-01/region=2 | +| dt=2015-09-02/region=1 | +| dt=2015-09-03/region=3 | +| dt=2015-09-03/region=2 | + +Get the total number of partitions: + +``` +part_count(db.orders); +-- +5 +``` + +Get the number of partitions in *region 1*: + +``` +part_count(db.orders, region='1'); +-- +2 +``` + +**Compatibility**: HPL/SQL extension. + +**Version:** HPL/SQL 0.3.13 + +See also: +- [PART_COUNT_BY]({{< ref "part-count-by" >}}) - Get the number of partitions (group by) +- [PART_LOC]({{< ref "part-loc" >}}) - Get the location of a partition diff --git a/content/docs/latest/user/hive-hplsql/functions/part-loc.md b/content/docs/latest/user/hive-hplsql/functions/part-loc.md new file mode 100644 index 00000000..7e889840 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/part-loc.md @@ -0,0 +1,72 @@ +--- +title: "Apache Hive : PART_LOC Function" +date: 2026-08-12 +--- + +# Apache Hive : PART_LOC Function + +PART_LOC function returns the location of the specified table partition in HDFS or other storage. + +**Syntax**: + +``` +PART_LOC([db_name.]table_name, part_col=filter, ... [, with_hostname]); +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| [dbname.]table_name | VARCHAR | Identifier, variable or expression | Table name | +| part_col=filter | | | One or more partition filters | +| with_hostname | INT | Variable or expression | 1 - return path with host name \\ 0 - without host name (default) | + +**Notes**: + +- HPL/SQL uses the following Hive statement to get the partition information: + +``` +DESCRIBE EXTENDED db_name.tab_name PARTITION (part_col=filter, ...) +``` + +**Return Value:** + +- The partition directory +- NULL if the table or partition do not exist + +**Return Type:** + +STRING (VARCHAR/CHAR). + +**Example:** + +Table *db.orders* is partitioned by *country* and has the following partitions: + +| **Partition** | **Directory** | +| --- | --- | +| country='US' | /data/db/orders/country=US | +| country='UK' | /data/db/orders/country=UK | +| country='DE' | /data/db/orders/country=DE | +| country='BY' | /data/db/orders/country=BY | + +Get the location of country=US partition: + +``` +PART_LOC(db.orders, country='US', 1); + +Result: +hdfs://hostname:8020/data/db/orders/country=US +``` + +Return the path without host name: + +``` +PART_LOC(db.orders, country='US'); + +Result: +/data/db/orders/country=US +``` + +**Compatibility**: HPL/SQL extension. + +**Version:** HPL/SQL 0.1 diff --git a/content/docs/latest/user/hive-hplsql/functions/replace.md b/content/docs/latest/user/hive-hplsql/functions/replace.md new file mode 100644 index 00000000..ff08576d --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/replace.md @@ -0,0 +1,38 @@ +--- +title: "Apache Hive : REPLACE Function - HPL/SQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : REPLACE Function - HPL/SQL Reference + +REPLACE function replaces all occurrences of the specified substring with another substring. + +**Syntax**: + +``` +REPLACE(string, what, with) +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| *string* | String | Variable or expression | Original string | +| *what* | String | Variable or expression | Which substring to replace | +| *with* | String | Variable or expression | Replacement | + +**Return Type:** + +String. + +**Example:** + +``` +replace('2016-03-03', '-', ''); +-- +20160303 +``` + +**Compatibility**: Oracle, Microsoft SQL Server, IBM DB2 and MySQL. + +**Version**: HPL/SQL 0.3.17 diff --git a/content/docs/latest/user/hive-hplsql/functions/substr.md b/content/docs/latest/user/hive-hplsql/functions/substr.md new file mode 100644 index 00000000..7d91d3e9 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/substr.md @@ -0,0 +1,54 @@ +--- +title: "Apache Hive : SUBSTR Function - HPL/SQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : SUBSTR Function - HPL/SQL Reference + +SUBSTR function returns a substring from string. + +**Syntax**: + +``` +SUBSTR(string, start_pos [, substring_len]) +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| string | String | Variable or expression | Original string | +| start_pos | Integer | Variable or expression | Start position of substring (starts from 1) | +| substring_len | Integer | Variable or expression | Length of substring | + +**Notes**: + +- If start_pos is 0 then it is treated as 1 +- SUBSTR and [SUBSTRING]({{< ref "substring" >}}) functions are synonyms + +**Return Type:** + +String. + +**Example:** + +``` +SUBSTR('Remark', 3); +``` + +Result: 'mark' + +**Example:** + +``` +SUBSTR('Remark', 3, 3); +``` + +Result: 'mar' + +**Compatibility**: Oracle, IBM DB2 and MySQL. + +**See also**: +- [SUBSTRING]({{< ref "substring" >}}) + +**Version**: HPL/SQL 0.1 diff --git a/content/docs/latest/user/hive-hplsql/functions/substring.md b/content/docs/latest/user/hive-hplsql/functions/substring.md new file mode 100644 index 00000000..9a895b6a --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/substring.md @@ -0,0 +1,58 @@ +--- +title: "Apache Hive : SUBSTRING Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : SUBSTRING Function - PL/HQL Reference + +SUBSTRING function returns a substring from string. + +**Syntax**: + +``` +SUBSTRING(string, start_pos [, substring_len]) +| +SUBSTRING(string FROM start_pos [FOR substring_len]) +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| string | String | Variable or expression | Original string | +| start_pos | Integer | Variable or expression | Start position of substring (starts from 1) | +| substring_len | Integer | Variable or expression | Length of substring | + +**Notes**: + +- If start_pos is 0 then it is treated as 1 +- SUBSTRING and [SUBSTR]({{< ref "substr" >}}) functions are synonyms + +**Return Type:** + +String. + +**Example:** + +``` +SUBSTRING('Remark', 3); +``` + +Result: 'mark' + +**Example:** + +``` +SUBSTRING('Remark', 3, 3); +``` + +Result: 'mar' + +**Compatibility**: IBM DB2, Teradata and Microsoft SQL Server. + +**See also**: +- [SUBSTR]({{< ref "substr" >}}) + +**Version**: +- PL/HQL 0.3.11 SUBSTRING FROM FOR syntax added +- PL/HQL 0.01 introduced diff --git a/content/docs/latest/user/hive-hplsql/functions/sysdate.md b/content/docs/latest/user/hive-hplsql/functions/sysdate.md new file mode 100644 index 00000000..bfb44ff5 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/sysdate.md @@ -0,0 +1,40 @@ +--- +title: "Apache Hive : SYSDATE Function" +date: 2026-08-12 +--- + +# Apache Hive : SYSDATE Function + +SYSDATE function returns the current date and time (year, month, day, hour, minute and seconds). + +**Syntax**: + +``` +SYSDATE +``` + +**Return Type:** + +TIMESTAMP + +**Example**: + +Get the current and date and time: + +``` +SYSDATE +-- +2015-03-03 11:06:31 +``` + +**Compatibility**: Oracle + +**Version:** HPL/SQL 0.3 + +See also: + +- [CURRENT_DATE]({{< ref "current-date" >}}) +- [CURRENT_TIMESTAMP]({{< ref "current-timestamp" >}}) +- [FROM_UNIXTIME]({{< ref "from-unixtime" >}}) +- [NOW]({{< ref "now" >}}) +- [UNIX_TIMESTAMP]({{< ref "unix-timestamp" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/timestamp-iso.md b/content/docs/latest/user/hive-hplsql/functions/timestamp-iso.md new file mode 100644 index 00000000..86f925c9 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/timestamp-iso.md @@ -0,0 +1,50 @@ +--- +title: "Apache Hive : TIMESTAMP_ISO Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : TIMESTAMP_ISO Function - PL/HQL Reference + +TIMESTAMP_ISO function converts a string or date expression to TIMESTAMP data type. + +The string must be in 'YYYY-MM-DD HH24:MI:SS.FF' or 'YYYY-MM-DD' format. + +**Syntax**: + +``` +TIMESTAMP_ISO(expression); +``` + +**Return Data Type:** + +TIMESTAMP + +**Example 1:** + +Convert a string to TIMESTAMP: + +``` +TIMESTAMP_ISO('2015-03-12'); +-- +2015-03-12 00:00:00 +``` + +**Example 2:** + +Convert a date to TIMESTAMP: + +``` +TIMESTAMP_ISO(DATE '2015-03-12'); +-- +2015-03-12 00:00:00 +``` + +**Compatibility**: IBM DB2 + +**Version**: PL/HQL 0.03 + +See also: +- [DATE Literal]({{< ref "date-literal" >}}) +- [TIMESTAMP Literal]({{< ref "timestamp-literal" >}}) +- [DATE Function]({{< ref "date" >}}) +- [TO_TIMESTAMP Function]({{< ref "to-timestamp" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/to-char.md b/content/docs/latest/user/hive-hplsql/functions/to-char.md new file mode 100644 index 00000000..66d6a774 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/to-char.md @@ -0,0 +1,31 @@ +--- +title: "Apache Hive : TO_CHAR Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : TO_CHAR Function - PL/HQL Reference + +TO_CHAR function converts an expression to string. + +**Syntax**: + +``` +TO_CHAR(expression); +``` + +**Return Type:** + +STRING + +**Example:** + +``` +TO_CHAR(CURRENT_DATE); +``` + +**Compatibility**: Oracle, IBM DB2 and Teradata + +**Version**: PL/HQL 0.3.1 + +See also: +- [CHAR Function]({{< ref "char" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/to-timestamp.md b/content/docs/latest/user/hive-hplsql/functions/to-timestamp.md new file mode 100644 index 00000000..0cedeba8 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/to-timestamp.md @@ -0,0 +1,46 @@ +--- +title: "Apache Hive : TO_TIMESTAMP Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : TO_TIMESTAMP Function - PL/HQL Reference + +TO_TIMESTAMP function converts a string to TIMESTAMP data type using the specified format. + +**Syntax**: + +``` +TO_TIMESTAMP(string_expression, format_expression); +``` + +**Return Data Type:** + +TIMESTAMP + +**Format Elements**: + +| YYYY | 4-digit year | +| --- | --- | +| MM | Month (1-12) | +| DD | Day (1-31) | +| HH24 | Hour of the day (0-23) | +| MI | Minute (0-59) | +| SS | Second (0-59) | + +**Examples:** + +``` +TO_TIMESTAMP('2015-04-02', 'YYYY-MM-DD'); +TO_TIMESTAMP('04/02/2015', 'mm/dd/yyyy'); +TO_TIMESTAMP('2015-04-02 13:51:31', 'YYYY-MM-DD HH24:MI:SS'); +``` + +**Compatibility**: Oracle, IBM DB2, Teradata + +**Version**: PL/HQL 0.3.1 + +See also: +- [DATE Literal]({{< ref "date-literal" >}}) +- [TIMESTAMP Literal]({{< ref "timestamp-literal" >}}) +- [DATE Function]({{< ref "date" >}}) +- [TIMESTAMP_ISO]({{< ref "timestamp-iso" >}}) function diff --git a/content/docs/latest/user/hive-hplsql/functions/trim.md b/content/docs/latest/user/hive-hplsql/functions/trim.md new file mode 100644 index 00000000..f024b401 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/trim.md @@ -0,0 +1,30 @@ +--- +title: "Apache Hive : TRIM Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : TRIM Function - PL/HQL Reference + +TRIM function removes leading and trailing characters from a string. + +**Syntax**: + +``` +TRIM(string_expression); +``` + +**Return Type:** + +STRING + +**Example 1:** + +``` +'#' || TRIM(' Hello ') || '#'; +-- +#Hello# +``` + +**Compatibility**: Oracle, IBM DB2, Teradata, Microsoft SQL Server, PostgreSQL, MySQL and Netezza + +**Version**: PL/HQL 0.03 diff --git a/content/docs/latest/user/hive-hplsql/functions/unix-timestamp.md b/content/docs/latest/user/hive-hplsql/functions/unix-timestamp.md new file mode 100644 index 00000000..6b9792e3 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/unix-timestamp.md @@ -0,0 +1,40 @@ +--- +title: "Apache Hive : UNIX_TIMESTAMP Function" +date: 2026-08-12 +--- + +# Apache Hive : UNIX_TIMESTAMP Function + +UNIX_TIMESTAMP function returns the current date and time in seconds since 1970-01-01 00:00:00. + +**Syntax**: + +``` +UNIX_TIMESTAMP() +``` + +**Return Type:** + +INT + +**Example**: + +Get the current and date and time in seconds: + +``` +UNIX_TIMESTAMP() +-- +1446631617 +``` + +**Compatibility**: Hive. + +**Version:** HPL/SQL 0.3.17 + +See also: + +- [CURRENT_DATE]({{< ref "current-date" >}}) +- [CURRENT_TIMESTAMP]({{< ref "current-timestamp" >}}) +- [FROM_UNIXTIME]({{< ref "from-unixtime" >}}) +- [NOW]({{< ref "now" >}}) +- [SYSDATE]({{< ref "sysdate" >}}) diff --git a/content/docs/latest/user/hive-hplsql/functions/upper.md b/content/docs/latest/user/hive-hplsql/functions/upper.md new file mode 100644 index 00000000..1d0d4f0d --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/upper.md @@ -0,0 +1,32 @@ +--- +title: "Apache Hive : UPPER Function - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : UPPER Function - PL/HQL Reference + +UPPER function converts a string expression to upper case. + +**Syntax**: + +``` +UPPER(expression); +``` + +**Return Data Type:** + +STRING + +**Example:** + +Convert a string to upper case: + +``` +UPPER('abc'); +--- +ABC +``` + +**Compatibility**: Oracle, Microsoft SQL Server, IBM DB2, Teradata, PostgreSQL, MySQL and Netezza + +**Version**: PL/HQL 0.03 diff --git a/content/docs/latest/user/hive-hplsql/functions/user.md b/content/docs/latest/user/hive-hplsql/functions/user.md new file mode 100644 index 00000000..40c6e45b --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/functions/user.md @@ -0,0 +1,36 @@ +--- +title: "Apache Hive : USER Function - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : USER Function - PL/HQL + +USER function returns the name of the user executing the current PL/HQL script. + +**Syntax**: + +``` +USER +``` + +**Return Type:** + +STRING + +**Example**: + +Get the current user: + +``` +USER +-- +paul +``` + +**Compatibility**: Oracle, IBM DB2 and Teradata. + +**Version:** PL/HQL 0.3.11 + +See also: + +- [CURRENT_USER]({{< ref "current-user" >}}) diff --git a/content/docs/latest/user/hive-hplsql/language-elements/_index.md b/content/docs/latest/user/hive-hplsql/language-elements/_index.md new file mode 100644 index 00000000..2bfea2ee --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/language-elements/_index.md @@ -0,0 +1,4 @@ +--- +title: "Language Elements" +date: 2026-08-12 +--- diff --git a/content/docs/latest/user/hive-hplsql/language-elements/assign.md b/content/docs/latest/user/hive-hplsql/language-elements/assign.md new file mode 100644 index 00000000..94803cd4 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/language-elements/assign.md @@ -0,0 +1,86 @@ +--- +title: "Apache Hive : Assignment" +date: 2026-08-12 +--- + +# Apache Hive : Assignment + +You can use the assignment operator or statement to set a new value to variable in HPL/SQL. + +If the variable was not explicitly declared before the assignment, a new variable is created and its data type is derived from the assignment expression. + +## Assignment Operator + +Values can be set using the assignment operator := or = + +Syntax: + +``` +var [:= | = ] expression; +``` + +Example: + +``` +code := 'A'; +status := 1; +count = 0; +``` + +**Compatibility:** Oracle PL/SQL, PostgreSQL PL/pgSQL and Netezza NZPLSQL. + +**Version**: PL/HQL 0.01 + +## Assignment Statement + +You can also use the SET statement to assign value to variables. + +Syntax: + +``` +SET var = expression [, ...]; +| +SET (var [, var2, ...]) = (expression [, expression2, ...]) +``` + +Example: + +``` +SET code = 'A'; +SET status = 1, count = 0; +SET (count, limit) = (0, 100); +``` + +**Compatibility:** IBM DB2, Teradata, Microsoft SQL Server and MySQL. + +**Version**: PL/HQL 0.01 + +## Assignment From a SELECT Statement + +You can also use the SET statement to assign value from the first row of a query result: + +Syntax: + +``` +SET var = (SELECT col FROM ...); +| +SET (var [, var2, ...]) = (SELECT col [, col2, ... ] FROM ...); +| +SELECT var = col [, var2 = col2, ...] FROM ... -- since HPL/SQL 0.3.11 +``` + +Example: + +``` +SET code = (SELECT code FROM conf WHERE name = 'A'); +SET (count, limit) = (SELECT count, limit FROM conf WHERE name = 'A'); +SELECT @count = count, @limit = limit FROM conf WHERE name = 'A'; +``` + +**Compatibility:** IBM DB2, Teradata, Microsoft SQL Server and MySQL. + +**Version**: PL/HQL 0.3.7 + +See also: +- [SELECT INTO]({{< ref "select-into" >}}) +- [VALUES INTO]({{< ref "values-into" >}}) diff --git a/content/docs/latest/user/hive-hplsql/language-elements/case.md b/content/docs/latest/user/hive-hplsql/language-elements/case.md new file mode 100644 index 00000000..7c73618f --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/language-elements/case.md @@ -0,0 +1,63 @@ +--- +title: "Apache Hive : CASE Expression - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : CASE Expression - PL/HQL Reference + +CASE expression allows you to implement IF-THEN-ELSE logic in expressions. + +**Syntax:** + +Simple CASE expression: + +``` +CASE expr + WHEN expr THEN expr + ... + [ELSE expr] +END +``` + +Searched CASE expression: + +``` +CASE + WHEN boolean_expr THEN expr + ... + [ELSE expr] +END +``` + +**Notes**: + +- NULL is returned if none of the WHEN expressions is matched and ELSE clause is not specified + +**Examples**: + +Simple CASE expression: + +``` + CASE state + WHEN 'AZ' THEN 'Arizona' + WHEN 'CA' THEN 'California' + ELSE 'N/A' + END +``` + +Searched CASE expression: + +``` + CASE + WHEN state = 'AZ' THEN 'Arizona' + WHEN state = 'CA' THEN 'California' + ELSE 'N/A' + END +``` + +**Compatibility:** Oracle, IBM DB2, SQL Server, Teradata, MySQL, PostgreSQL and Netezza. + +**Version**: PL/HQL 0.01 + +See also: +- [DECODE Function]({{< ref "decode" >}}) diff --git a/content/docs/latest/user/hive-hplsql/language-elements/cursor-attributes.md b/content/docs/latest/user/hive-hplsql/language-elements/cursor-attributes.md new file mode 100644 index 00000000..e9ac64f7 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/language-elements/cursor-attributes.md @@ -0,0 +1,69 @@ +--- +title: "Apache Hive : Cursor Attributes" +date: 2026-08-12 +--- + +# Apache Hive : Cursor Attributes + +Cursor attributes allow you to get information about the current cursor state. + +**Syntax**: + +``` +cursor_name%ISOPEN + +cursor_name%FOUND + +cursor_name%NOTFOUND +``` + +- *cursor_name* is the name of a declared cursor or cursor variable. + +## %ISOPEN Attribute + +%ISOPEN returns *true* if the cursor is open, otherwise it returns *false*; + +## %FOUND Attribute + +%FOUND returns NULL before the first fetch from the cursor, *true* if the last fetch returned a row, and *false* otherwise. + +## %NOTFOUND Attribute + +%NOTFOUND returns NULL before the first fetch from the cursor, *false* if the last fetch returned a row, and *true* otherwise. + +**Example:** + +``` +DECLARE + CURSOR c1 IS SELECT name FROM users LIMIT 1; + v1 VARCHAR(30); +BEGIN + OPEN c1; + IF c1%ISOPEN THEN + DBMS_OUTPUT.PUT_LINE('Cursor open'); + END IF; + + FETCH c1 INTO v1; + + IF c1%FOUND THEN + DBMS_OUTPUT.PUT_LINE('Row found'); + END IF; + + FETCH c1 INTO v1; + + IF c1%NOTFOUND THEN + DBMS_OUTPUT.PUT_LINE('Row not found'); + END IF; + + CLOSE c1; +END; +``` + +**Compatibility:** Oracle + +**Version:** HPL/SQL 0.3.11 + +**See also:** +- [OPEN]({{< ref "open" >}}) +- [FETCH]({{< ref "fetch" >}}) +- [CLOSE]({{< ref "close" >}}) diff --git a/content/docs/latest/user/hive-hplsql/language-elements/data-types.md b/content/docs/latest/user/hive-hplsql/language-elements/data-types.md new file mode 100644 index 00000000..26eb8e26 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/language-elements/data-types.md @@ -0,0 +1,65 @@ +--- +title: "Apache Hive : Data Types" +date: 2026-08-12 +--- + +# Apache Hive : Data Types + +You can use the following data types in HPL/SQL programs: + +| Data Type | Aliases | Description | +| --- | --- | --- | +| BIGINT | INT8 | 64-bit integer | +| BINARY_DOUBLE | | Double precision floating-point number | +| BINARY_FLOAT | | Single precision floating-point number | +| BINARY_INTEGER | | 32-bit integer | +| BIT | | 0, 1 or NULL | +| BOOL | BOOLEAN | True or false | +| CHAR(*n*) | CHARACTER(*n*) | Fixed-length string | +| DECIMAL(*p,s*) | | Fixed-point number | +| DATE | | Date (year, month and day) | +| DATETIME | | Date and time | +| DOUBLE | DOUBLE PRECISION | Double precision floating-point number | +| FLOAT | | Single precision floating-point number | +| INT | INTEGER, INT4 | 32-bit integer | +| NCHAR(*n*) | | Fixed-length string | +| NVARCHAR(*n*) | | Variable-length string | +| NUMERIC(*p,s*) | | Fixed-point number | +| NUMBER(*p,s*) | | Fixed-point number | +| PLS_INTEGER | | 32-bit integer | +| REAL | | Single precision floating-point number | +| RECORD | | Arbitrary record | +| SIMPLE_DOUBLE | | Double precision floating-point number | +| SIMPLE_FLOAT | | Single precision floating-point number | +| SIMPLE_INTEGER | | 32-bit integer | +| SMALLINT | INT2 | 16-bit integer | +| SYS_REFCURSOR | | Cursor variable | +| TIMESTAMP | | Date and time | +| TINYINT | | 8-bit integer | +| VARCHAR(*n*) | VARCHAR(max) | Variable-length string | +| VARCHAR2(*n*) | | Variable-length string | +| UTL_FILE.FILE_TYPE | | File handle | + +## Data Type Conversion + +If CREATE TABLE contains a data type that is not supported by Hive, it is automatically converted by HPL/SQL. + +Currently HPL/SQL performs the following conversions: + +| Source | Hive SQL | +| --- | --- | +| BIT | TINYINT | +| DATETIME | TIMESTAMP | +| INT(n) | INT | +| INT2 | SMALLINT | +| INT4 | INT | +| INT8 | BIGINT | +| NCHAR(n) | STRING | +| NVARCHAR(n) | STRING | +| NUMBER(p,s) | DECIMAL(p,s) | +| NUMERIC(p,s) | DECIMAL(p,s) | +| TEXT | STRING | +| VARCHAR(MAX) | STRING | +| VARCHAR2(n) | STRING | + +For more information, see [On-the-Fly Conversion]({{< ref "conversion" >}}) diff --git a/content/docs/latest/user/hive-hplsql/language-elements/date-literal.md b/content/docs/latest/user/hive-hplsql/language-elements/date-literal.md new file mode 100644 index 00000000..0d6b0460 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/language-elements/date-literal.md @@ -0,0 +1,25 @@ +--- +title: "Apache Hive : DATE Literal - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : DATE Literal - PL/HQL Reference + +DATE literal allows you to specify a date constant using a string in 'YYYY-MM-DD' format. Then you can use this date value in any expression that expects a DATE data type. + +**Examples**: + +``` +DATE '2014-12-20' +DATE '2014-12-20' + 1 -- Result: 2014-12-21 of type DATE +DATE '2014-12-20' - 1 -- 2014-12-19 +``` + +**Compatibility:** Oracle, IBM DB2 and Teradata + +**Version**: PL/HQL 0.01 + +See also: + +- [TIMESTAMP Literal]({{< ref "timestamp-literal" >}}) +- [INTERVAL Expressions]({{< ref "interval" >}}) diff --git a/content/docs/latest/user/hive-hplsql/language-elements/declare.md b/content/docs/latest/user/hive-hplsql/language-elements/declare.md new file mode 100644 index 00000000..718cac6f --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/language-elements/declare.md @@ -0,0 +1,62 @@ +--- +title: "Apache Hive : Declarations - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : Declarations - PL/HQL Reference + +You can declare variables using DECLARE block or statement. + +Note that you can mix both syntaxes in a single program. DECLARE blocks and statements can appear in any part of the program. + +## DECLARE Block + +DECLARE block has the following syntax: + +``` +DECLARE + var datatype [NOT NULL] [:= | = | DEFAULT expression]; + ... +BEGIN + ... +END; +``` + +HPL/SQL also allows you to define a constant: + +``` + var CONSTANT datatype := | DEFAULT expression +``` + +Example: + +``` +DECLARE + code CHAR(10); + status INT := 1; + count SMALLINT = 0; + limit INT DEFAULT 100; + max_limit CONSTANT INT := 1000; +BEGIN + ... +END; +``` + +**Compatibility:** Declaration block syntax is similar to Oracle PL/SQL, PostgreSQL PL/pgSQL and Netezza NZPLSQL. +## DECLARE Statement + +DECLARE statement has the following syntax: + +``` +DECLARE var [, var2, ...] [AS] datatype [:= | = | DEFAULT expression] [, ...]; +``` + +Example: + +``` +DECLARE code CHAR(10); +DECLARE status, status2 INT DEFAULT 1; +DECLARE count SMALLINT, limit INT DEFAULT 100; +``` + +**Compatibility:** Declaration statement syntax is similar to IBM DB2 SQL PL, Teradata, Microsoft SQL Server Transact-SQL and MySQL. diff --git a/content/docs/latest/user/hive-hplsql/language-elements/exceptions.md b/content/docs/latest/user/hive-hplsql/language-elements/exceptions.md new file mode 100644 index 00000000..3f9af7a4 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/language-elements/exceptions.md @@ -0,0 +1,38 @@ +--- +title: "Apache Hive : Exceptions - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : Exceptions - PL/HQL Reference + +PL/HQL allows you to handle exceptions in your programs. + +**Syntax:** + +``` +BEGIN + -- Statements that can raise an exception +EXCEPTION + WHEN condition THEN + -- Statements + WHEN condition2 THEN + -- Statements2 + ... +END +``` + +**Example**: + +``` +DECLARE + v VARCHAR(200); +BEGIN + OPEN cur FOR 'SELECT c1 FROM t1'; + FETCH cur INTO v; + CLOSE cur; +EXCEPTION WHEN OTHERS THEN + DBMS_OUTPUT.PUT_LINE('Error'); +END +``` + +**Compatibility**: Oracle, PostgreSQL and Netezza. diff --git a/content/docs/latest/user/hive-hplsql/language-elements/interval.md b/content/docs/latest/user/hive-hplsql/language-elements/interval.md new file mode 100644 index 00000000..4c60e382 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/language-elements/interval.md @@ -0,0 +1,87 @@ +--- +title: "Apache Hive : Interval Expressions" +date: 2026-08-12 +--- + +# Apache Hive : Interval Expressions + +Interval expressions allow you to add or subtract interval values to DATE and TIMESTAMP values. + +**Syntax**: + +``` +[INTERVAL] expression DAYS | DAY | MICROSECONDS | MICROSECOND +``` + +Notes: + +- MICROSECOND expressions are converted to millisecond expressions due to Java limitations. + +**Example 1**: + +Add 1 day to DATE and TIMESTAMP values: + +``` +DATE '2015-03-12' + 1 DAY; +-- +2015-03-13 + +TIMESTAMP '2015-03-12' + 1 DAY; +-- +2015-03-13 00:00:00 +``` + +**Example 2**: + +Add the result of expression to to DATE and TIMESTAMP values: + +``` +DATE '2015-03-12' + NVL(NULL, 3) DAYS; +-- +2015-03-15 + +TIMESTAMP '2015-03-12' + NVL(NULL, 3) DAYS; +-- +2015-03-15 00:00:00 +``` + +**Example 3**: + +Subtract a millisecond fom TIMESTAMP value (microseconds is not supported): + +``` +TIMESTAMP '2015-03-12 10:10:10.000' - 1 MICROSECOND; /* Treated as millisecond */ +-- +2015-03-12 10:10:09.999 +``` + +**Example 4**: + +Subtract multiple interval fields: + +``` +TIMESTAMP '2015-03-12' - 1 DAY - 1 MICROSECOND; +-- +2015-03-10 23:59:59 +``` + +**Example 5**: + +Using INTERVAL keyword: + +``` +date '2016-01-27' - interval '3' day; +-- +2016-01-24 +``` + +**Compatibility:** IBM DB2, Oracle, Teradata + +**Version**: +- INTERVAL keyword - HPL/SQL 0.3.17 +- Introduced - HPL/HQL 0.3 + +See also: + +- [DATE Literal]({{< ref "date-literal" >}}) +- [TIMESTAMP Literal]({{< ref "timestamp-literal" >}}) diff --git a/content/docs/latest/user/hive-hplsql/language-elements/rowtype-attribute.md b/content/docs/latest/user/hive-hplsql/language-elements/rowtype-attribute.md new file mode 100644 index 00000000..16099418 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/language-elements/rowtype-attribute.md @@ -0,0 +1,59 @@ +--- +title: "Apache Hive : %ROWTYPE Attribute" +date: 2026-08-12 +--- + +# Apache Hive : %ROWTYPE Attribute + +%ROWTYPE attribute lets you declare a record variable that has the same columns and data types as the specified database table. + +**Syntax**: + +``` +var_name [schema.]table_name%ROWTYPE +``` + +**Examples:** + +``` +DECLARE + v orders%ROWTYPE; +BEGIN + SELECT * INTO v FROM orders LIMIT 1; + DBMS_OUTPUT.PUT_LINE('Item: ' || v.name || ' - ' || v.description); +END; +``` + +``` +DECLARE + v orders%ROWTYPE; + CURSOR c IS SELECT * FROM orders; +BEGIN + OPEN c1; + FETCH c1 INTO v1; + DBMS_OUTPUT.PUT_LINE('Item: ' || v.name || ' - ' || v.description); + CLOSE c1; +END; +``` + +``` +BEGIN + FOR v IN (SELECT * FROM orders) + LOOP + DBMS_OUTPUT.PUT_LINE('Item: ' || v.name || ' - ' || v.description); + END LOOP; +END; +``` + +``` +DECLARE + v orders%ROWTYPE; +BEGIN + EXECUTE IMMEDIATE 'SELECT * FROM orders LIMIT 1' INTO v; + DBMS_OUTPUT.PUT_LINE('Item: ' || v.name || ' - ' || v.description); +END; +``` + +**Compatibility:** Oracle + +**Version:** HPL/SQL 0.3.13 diff --git a/content/docs/latest/user/hive-hplsql/language-elements/timestamp-literal.md b/content/docs/latest/user/hive-hplsql/language-elements/timestamp-literal.md new file mode 100644 index 00000000..71083015 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/language-elements/timestamp-literal.md @@ -0,0 +1,33 @@ +--- +title: "Apache Hive : TIMESTAMP Literal - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : TIMESTAMP Literal - PL/HQL Reference + +TIMESTAMP literal allows you to specify a timestamp constant using a string in 'YYYY-MM-DD HH:MI:SS.FFF' or 'YYYY-MM-DD-HH.MI.SS.FFF' format. + +You can use this timestamp value in any expression that expects a TIMESTAMP data type. + +**Examples**: + +``` +TIMESTAMP '2015-03-03 11:39:31.123' + +TIMESTAMP '2015-03-03-11.39.31.123' -- DB2 syntax +``` + +**Notes:** + +- Fractional part is optional + +**Compatibility:** Oracle, IBM DB2. + +**Version**: PL/HQL 0.03 + +See also: + +- [DATE Literal]({{< ref "date-literal" >}}) +- [INTERVAL Expressions]({{< ref "interval" >}}) +- [TIMESTAMP_ISO Function]({{< ref "timestamp-iso" >}}) +- [TO_TIMESTAMP Function]({{< ref "to-timestamp" >}}) diff --git a/content/docs/latest/user/hive-hplsql/language-elements/type-attribute.md b/content/docs/latest/user/hive-hplsql/language-elements/type-attribute.md new file mode 100644 index 00000000..352ff7d0 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/language-elements/type-attribute.md @@ -0,0 +1,31 @@ +--- +title: "Apache Hive : %TYPE Attribute" +date: 2026-08-12 +--- + +# Apache Hive : %TYPE Attribute + +%TYPE attribute lets you declare a variable that has the same data type as the specified referenced column. + +**Syntax**: + +``` +var_name [schema.]table.column_name%TYPE +``` + +- If *table.column_name* cannot be found, the data type is derived from the first assignment expression. + +**Example:** + +``` +DECLARE + i orders.item%TYPE; +BEGIN + SELECT item INTO i FROM orders LIMIT 1; + DBMS_OUTPUT.PUT_LINE('Item: ' || i); +END; +``` + +**Compatibility:** Oracle + +**Version:** HPL/SQL 0.3.13 diff --git a/content/docs/latest/user/hive-hplsql/new.md b/content/docs/latest/user/hive-hplsql/new.md new file mode 100644 index 00000000..fdfaa2ed --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/new.md @@ -0,0 +1,222 @@ +--- +title: "Apache Hive : What's New" +date: 2026-08-12 +--- + +# Apache Hive : What's New + +New HPL/SQL features: + +## HPL/SQL 0.3.17 - March 28, 2016 + +- [COPY FROM FTP]({{< ref "copy-from-ftp" >}}) statement +- [CREATE DATABASE]({{< ref "create-database" >}}) statement +- [DROP DATABASE]({{< ref "drop-database" >}}) statement +- [TRUNCATE]({{< ref "truncate" >}}) statement +- [DESCRIBE]({{< ref "describe" >}}) statement +- [INSERT DIRECTORY]({{< ref "insert-directory" >}}) statement +- [REPLACE]({{< ref "replace" >}}) function +- [NOW]({{< ref "now" >}}) function +- [UNIX_TIMESTAMP]({{< ref "unix-timestamp" >}}) function +- [FROM_UNIXTIME]({{< ref "from-unixtime" >}}) function +- [+ Operator]({{< ref "plus#concatenate_two_strings" >}}) to concatenate two strings +- [INT(n) to INT]({{< ref "data-types#data_type_conversion" >}}) data type conversion (MySQL compatibility) +- [TEXT to STRING]({{< ref "data-types#data_type_conversion" >}}) data type conversion (MySQL compatibility) +- [INT2 to SMALLINT]({{< ref "data-types#data_type_conversion" >}}) data type conversion (PostgreSQL compatibility) +- [INT4 to INT]({{< ref "data-types#data_type_conversion" >}}) data type conversion (PostgreSQL compatibility) +- [INT8 to BIGINT]({{< ref "data-types#data_type_conversion" >}}) data type conversion (PostgreSQL compatibility) +- [INTERVAL]({{< ref "interval" >}}) keyword in interval expressions +- AUTO_INCREMENT, ENGINE, CHARSET, COMMENT clauses parser (MySQL compatibility) +- BEGIN TRANSACTION and END TRANSACTION statements parser (Teradata compatibility) +- ALTER TABLE ADD CONSTRAINT parser +- WHERE clause in UPDATE clause of MERGE statement (Parser fix) +- Allow expressions in PARTITION BY clause of window functions (Parser fix) +- SET QUERY_BAND statement parser (Teradata compatibility) +- ENABLE constraint keyword parser (Oracle compatibility) +- Removing [dbo] schema when executing SQL (Microsoft SQL Server compatibility) +- By default, not adding FROM [hplsql.dual.table]({{< ref "configuration#hplsqldualtable" >}}) to SELECT without FROM +- INNER keyword is optional in join (Parser fix) +- RAISE statement (Parser fix) +- Variable declaration block in procedures and functions (Bug fix) +- Subtraction ('-') operator (Bug fix) +- Multiplication ('*') and division ('/') operators in SQL statements (Bug fix) +- OVERWRITE keyword missed in INSERT statements (Bug fix) +- PL/SQL-style stored procedure without parameters (Bug fix) +- FOR cursor columns values (Bug fix) +- EXCEPTION block in functions (Bug fix) +## HPL/SQL 0.3.13 - October 30, 2015 + +- [CREATE PACKAGE]({{< ref "create-package" >}}) statement +- [%TYPE]({{< ref "type-attribute" >}}) attribute +- [%ROWTYPE]({{< ref "rowtype-attribute" >}}) attribute +- [PART_COUNT]({{< ref "part-count" >}}) function +- [PART_COUNT_BY]({{< ref "part-count-by" >}}) function +- [PLS_INTEGER]({{< ref "data-types" >}}), [BINARY_INTEGER]({{< ref "data-types" >}}) and [SIMPLE_INTEGER]({{< ref "data-types" >}}) data types +- [REAL]({{< ref "data-types" >}}), [FLOAT]({{< ref "data-types" >}}) and [DOUBLE]({{< ref "data-types" >}}) data types +- [BINARY_FLOAT]({{< ref "data-types" >}}) and [BINARY_DOUBLE]({{< ref "data-types" >}}) data types +- [SIMPLE_FLOAT]({{< ref "data-types" >}}) and [SIMPLE_DOUBLE]({{< ref "data-types" >}}) data types +- [BOOL]({{< ref "data-types" >}}) and [BOOLEAN]({{< ref "data-types" >}}) data types +- [CMP]({{< ref "cmp" >}}) statement to compare data in tables +- [COPY TO HDFS]({{< ref "copy" >}}) statement to copy JDBC query results to HDFS +- [NULL]({{< ref "null" >}}) statement (no operation) +- TRUE and FALSE boolean literals +- CONSTANT declarations +- Support expressions in [INCLUDE]({{< ref "include" >}}) statement +- BYTE and CHAR column length semantics (Parser) +- FOREIGN KEY and UNIQUE constraint in CREATE TABLE (Parser) +- Oracle storage clause in CREATE TABLE (Parser) +- NOT NULL constraint in variable declaration (Parser) +- XML data type (Parser) +- Calling stored procedures without parameters (Bug fix) +- AS alias in SELECT list (Bug fix) +- Subselect in FROM clause (Bug fix) +- Multiplication * and division / operators for integers (Bug fix) +- NOT boolean expression (Bug fix) +- Invoke built-in functions in lower case (Bug fix) +- Compare DECIMAL values, DECIMAL and integer values (Bug fix) +- NUMBER data type (Bug fix) +- Variable scope when calling functions or procedures (Bug fix) +- Using parameters in JDBC connection URL to specify advanced options such as Kerberos authentication (Bug fix) +## HPL/SQL 0.3.11 - July 30, 2015 + +- [SYS_REFCURSOR]({{< ref "data-types" >}}) cursor variable +- [%ISOPEN, %FOUND and %NOTFOUND]({{< ref "cursor-attributes" >}}) cursor attributes +- Named parameters in procedure call +- SELECT @var = col, ... FROM assignment syntax +- [ALLOCATE CURSOR]({{< ref "allocate-cursor" >}}) statement +- [ASSOCIATE RESULT SET LOCATOR]({{< ref "associate-locator" >}}) statement +- [SET CURRENT SCHEMA]({{< ref "set-session#current-schema" >}}) statement +- [CURRENT_USER]({{< ref "current-user" >}}) function +- [CURRENT USER]({{< ref "current-user" >}}) function +- [INSTR]({{< ref "instr" >}}) function +- [SUBSTRING(str FROM start FOR len)]({{< ref "substring" >}}) function +- [USER]({{< ref "functions/user.md" >}}) function +- [VARCHAR(MAX) to STRING]({{< ref "data-types#data-type-conversion" >}}) data type conversion +- [DATETIME and SMALLDATETIME to TIMESTAMP]({{< ref "data-types#data-type-conversion" >}}) data type conversion +- [NUMERIC to DECIMAL]({{< ref "data-types#data-type-conversion" >}}) data type conversion +- [NCHAR and NVARCHAR to STRING]({{< ref "data-types#data-type-conversion" >}}) data type conversion +- [BIT to TINYINT]({{< ref "data-types#data-type-conversion" >}}) data type conversion +- [Identifier]({{< ref "conversion#language-elements-and-operators" >}}) conversion ("" and [] to ``) +- UPDATE ELSE INSERT statement parser (UPSERT) +- LIKE, RLIKE and REGEXP parser +- CUME_DIST function parser +- CHARACTER SET data type attribute +- CASESPECIFIC data type attribute +- DYNAMIC RESULT SETS clause parser in CREATE PROCEDURE +- TITLE 'alias' clause parser in SELECT +- WITH RETURN TO CALLER/CLIENT clause parser in DECLARE CURSOR +- IDENTITY clause parser +- SET ANSI_NULLS, ANSI_PADDING, NOCOUNT, QUOTED_IDENTIFIER and XACT_ABORT parser +- OPEN cursor FOR SELECT (Bug fix) +- SELECT INTO a DECIMAL, BIGINT, SMALLINT or TINYINT variable (Bug fix) +- NULL in +/- operations (Bug fix) +- Initialize missing parameters to NULL in -main procedure call (Bug fix) +- Calling stored procedure without parameters (Bug fix) +- Do not throw NOT FOUND exception in FETCH statement (Bug fix) +- Division operator for integer values (Bug fix) +- Assign an integer value to decimal variable (Bug fix) +- Catch exceptions thrown during expression evaluation (Bug fix) +## HPL/SQL 0.3.7 - May 19, 2015 + +- [COPY]({{< ref "copy" >}}) statement +- [COPY FROM LOCAL]({{< ref "copy-from-local" >}}) statement +- [SET v = (SELECT c FROM ...)]({{< ref "assign#assignment-from-a-select-statement" >}}) assignment +- [plhql.conn.db2conn]({{< ref "configuration#plhqlconndb2conn" >}}) option +- [plhql.conn.tdconn]({{< ref "configuration#plhqlconntdconn" >}}) option +- DATE data type +- TIMESTAMP data type +- CURRENT_DATE, CURRENT DATE to TO_DATE(FROM_UNIXTIME(UNIX_TIMESTAMP())) conversion in executable SQL for Hive +- CURRENT_TIMESTAMP, CURRENT TIMESTAMP to FROM_UNIXTIME(UNIX_TIMESTAMP()) conversion in executable SQL for Hive +- TOP *n* to LIMIT *n* conversion in SELECT statement for Hive +- LIMIT clause in SELECT +- UPDATE statement parser +- DELETE statement parser +- MERGE statement parser +- Common table expression (CTE) parser +- ROW FORMAT DELIMITED, FIELDS TERMINATED, LINES TERMINATED clauses for Hive +- Default values parser in procedure parameters +- LANGUAGE SQL clause in CREATE PROCEDURE +- SQL SECURITY clause in CREATE PROCEDURE +- Procedure label in CREATE PROCEDURE +- WITH UR, RR, RS, CS clause in SELECT +- CREATE INDEX parser +- GRANT EXECUTE ON PROCEDURE parser +- #, @ and / characters can be used as the statement terminators +- CASE expressions in SQL statements (Bug fix) +- BETWEEN clause in boolean expressions and SQL statements (Bug fix) +- IS NOT NULL clause in boolean expressions and SQL statements (Bug fix) +- NOT IN clause in SQL statements (Bug fix) +- GROUP BY parser (Bug fix) +- ORDER BY parser (Bug fix) +- Windows-style file path parser (Bug fix) +## HPL/SQL 0.3.1 - April 30, 2015 + +- [Hive UDF]({{< ref "udf" >}}) to run PL/HQL scripts from Hive CLI queries +- Automatically put functions referenced in Hive queries to Distributed Cache, register [UDF]({{< ref "udf" >}}) and modify SQL statements +- [Multiple connections]({{< ref "connections" >}}) to different systems from a single script +- [ACTIVITY_COUNT]({{< ref "activity_count" >}}) built-in variable +- [CONCAT]({{< ref "concat" >}}) function +- [DECODE]({{< ref "decode" >}}) function +- [TO_CHAR]({{< ref "to-char" >}}) function +- [TO_TIMESTAMP]({{< ref "to-timestamp" >}}) function +- [CALL]({{< ref "call" >}}) statement +- [CREATE FUNCTION]({{< ref "create-function" >}}) statement +- [CREATE LOCAL TEMPORARY TABLE]({{< ref "create-local-temporary-table" >}}) statement +- [CREATE PROCEDURE]({{< ref "create-procedure" >}}) statement +- [CREATE VOLATILE TABLE]({{< ref "create-volatile-table" >}}) statement +- [DECLARE CONDITION]({{< ref "declare-condition" >}}) statement +- [DECLARE HANDLER]({{< ref "declare-handler" >}}) statement - user-defined condition +- [INCLUDE]({{< ref "include" >}}) statement +- [MAP OBJECT]({{< ref "map-object" >}}) statement +- [SIGNAL]({{< ref "signal" >}}) statement +- [.plhqlrc]({{< ref "configuration##plhqlrc-file" >}}) configuration file +- [|| operator to CONCAT]({{< ref "twopipes" >}}) function conversion in SQL queries +- Parser for column list in [INSERT]({{< ref "insert" >}}) statement +- [plhql.conn.hiveconn]({{< ref "configuration#plhqlconnhiveconn" >}}) option +- [plhql.conn.init.hiveconn]({{< ref "configuration#plhqlconninithiveconn" >}}) option +- [plhql.conn.convert.hiveconn]({{< ref "configuration#plhqlconnconverthiveconn" >}}) option +- [plhql.conn.hive2conn]({{< ref "configuration#plhqlconnhive2conn" >}}) option +- [plhql.conn.init.hive2conn]({{< ref "configuration#plhqlconninithive2conn" >}}) option +- [plhql.conn.convert.hive2conn]({{< ref "configuration#plhqlconnconverthive2conn" >}}) option +- [plhql.conn.]({{< ref "configuration#plhqlconn-connection_profile" >}}) option +- [plhql.conn.init.]({{< ref "configuration#plhqlconninit-connection_profile" >}}) option +- [plhql.conn.mysqlconn]({{< ref "configuration#plhqlconnmysqlconn" >}}) option +- [SET]({{< ref "assign" >}}) statement - assigning NULL to a variable (Bug fix) +- Boolean expressions and predicates (Bug fix) +## HPL/SQL 0.3 - March 31, 2015 + +- [TIMESTAMP]({{< ref "timestamp-literal" >}}) literal +- [INTERVAL]({{< ref "interval" >}}) expressions +- [SQLSTATE]({{< ref "sqlstate" >}}) built-in variable +- [CAST]({{< ref "cast" >}}) function +- [CHAR]({{< ref "char" >}}) function +- [COALESCE]({{< ref "coalesce" >}}) function +- [CURRENT_TIMESTAMP]({{< ref "current-timestamp" >}}) function +- [DATE]({{< ref "date" >}}) function +- [LEN]({{< ref "len" >}}) function +- [LENGTH]({{< ref "length" >}}) function +- [LOWER]({{< ref "lower" >}}) function +- [SYSDATE]({{< ref "sysdate" >}}) function +- [TIMESTAMP_ISO]({{< ref "timestamp-iso" >}}) function +- [TRIM]({{< ref "trim" >}}) function +- [UPPER]({{< ref "upper" >}}) function +- [CREATE TABLE]({{< ref "create-table" >}}) statement +- [DECLARE TEMPORARY TABLE]({{< ref "declare-temporary-table" >}}) statement +- [DROP TABLE]({{< ref "drop-table" >}}) statement +- [FOR cursor]({{< ref "for-cursor" >}}) statement +- [FROM TABLE (VALUES ...)]({{< ref "select" >}}) in SELECT statement +- [INSERT]({{< ref "insert" >}}) statement +- [GET DIAGNOSTICS EXCEPTION]({{< ref "get-diagnostics" >}}) statement +- [RESIGNAL]({{< ref "resignal" >}}) statement +- [VALUES INTO]({{< ref "values-into" >}}) statement +- [plhql.conn.convert.default]({{< ref "configuration#plhqlconnconvertdefault" >}}) option +- [plhql.dual.table]({{< ref "configuration#plhqldualtable" >}}) option +- [plhql.insert.values]({{< ref "configuration#plhqlinsertvalues" >}}) option +- [plhql.temp.tables]({{< ref "configuration#plhqltemptables" >}}) option +- [plhql.temp.tables.schema]({{< ref "configuration#plhqltemptablesschema" >}}) option +- [plhql.temp.tables.location]({{< ref "configuration#plhqltemptableslocation" >}}) option +- [VARCHAR2 to STRING]({{< ref "data-types#data-type-conversion" >}}) conversion in CREATE TABLE +- [NUMBER to DECIMAL]({{< ref "data-types#data-type-conversion" >}}) conversion in CREATE TABLE +## HPL/SQL 0.1 - February 27, 2015 + +- Initial release diff --git a/content/docs/latest/user/hive-hplsql/operators/_index.md b/content/docs/latest/user/hive-hplsql/operators/_index.md new file mode 100644 index 00000000..48f4e8d9 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/operators/_index.md @@ -0,0 +1,4 @@ +--- +title: "Operators" +date: 2026-08-12 +--- diff --git a/content/docs/latest/user/hive-hplsql/operators/equal.md b/content/docs/latest/user/hive-hplsql/operators/equal.md new file mode 100644 index 00000000..647ab207 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/operators/equal.md @@ -0,0 +1,44 @@ +--- +title: "Apache Hive : Equality and Comparison Operators - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : Equality and Comparison Operators - PL/HQL + +You can use equality and comparison operators `=, ==, <>, !=, <, >, >=, <=` to determine if one operand is equal, not equal, less or greater than another operand. + +| = | == | Equal | +| --- | --- | --- | +| <> | != | Not equal | +| > || Greater than | +| < || Less than | +| `>=` || Greater than or equal | +| `<=` || Less than or equal | + +**Syntax:** + +``` +expr = expr +expr == expr +expr <> expr +expr != expr +expr > expr +expr < expr +expr >= expr +expr <= expr +``` + +**Examples:** + +| **Expression** | **Result** | **Result Type** | +| --- | --- | --- | +| 3 = 3 | True | Boolean | +| 3 = 1 | False | Boolean | +| 'CA' = NULL | NULL | Boolean | +| 3 == 3 | True | Boolean | +| 3 <> 3 | False | Boolean | +| 3 != 3 | False | Boolean | +| 3 > 1 | True | Boolean | +| 3 < 1 | False | Boolean | +| 3 `>=` 1 | True | Boolean | +| 3 `<=` 1 | False | Boolean | diff --git a/content/docs/latest/user/hive-hplsql/operators/minus.md b/content/docs/latest/user/hive-hplsql/operators/minus.md new file mode 100644 index 00000000..8afcd10f --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/operators/minus.md @@ -0,0 +1,34 @@ +--- +title: "Apache Hive : Subtraction Operator (-) PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : Subtraction Operator (-) PL/HQL + +You can use (-) arithmetic operator to subtract two numbers, or subtract the number of days from a DATE value. + +**Syntax:** + +``` +expr - expr +``` + +## Subtract Two Integers + +When you subtract two integer values the result of the operation also has an integer value. + +**Example:** + +| **Expression** | **Result** | **Result Type** | +| --- | --- | --- | +| 3 - 1 | 2 | Integer | + +## Subtract Integer from Date + +When you subtract an integer from a DATE value, PL/HQL subtracts the number of days from the DATE and the result of the operation is a DATE value. + +**Example:** + +| **Expression** | **Result** | **Result Type** | +| --- | --- | --- | +| DATE '2015-01-01' - 1 | DATE '2014-12-31' | DATE | diff --git a/content/docs/latest/user/hive-hplsql/operators/plus.md b/content/docs/latest/user/hive-hplsql/operators/plus.md new file mode 100644 index 00000000..c9c4cbcb --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/operators/plus.md @@ -0,0 +1,43 @@ +--- +title: "Apache Hive : Addition Operator (+)" +date: 2026-08-12 +--- + +# Apache Hive : Addition Operator (+) + +You can use + arithmetic operator to add two numbers, concatenate two strings, or add an interval to a DATE value. + +**Syntax:** + +``` +expr + expr +``` + +## Add Two Integers + +When you add two integer values the result of the operation also has an integer value. + +**Example:** + +| **Expression** | **Result** | **Result Type** | +| --- | --- | --- | +| 3 + 1 | 4 | Integer | + +## Concatenate Two Strings + +When you use + for string operand the result of the operation is the concatenated string. + +**Example:** + +| **Expression** | **Result** | **Result Type** | +| --- | --- | --- | +| 'Ab' + 'c' | 'Abc' | String | +## Add an Integer to Date + +When you add an integer to a DATE value, PL/HQL adds the number of days to the DATE and the result of the operation is a DATE value. + +**Example:** + +| **Expression** | **Result** | **Result Type** | +| --- | --- | --- | +| DATE '2014-12-31' + 1 | DATE '2015-01-01' | DATE | diff --git a/content/docs/latest/user/hive-hplsql/operators/twopipes.md b/content/docs/latest/user/hive-hplsql/operators/twopipes.md new file mode 100644 index 00000000..8306d985 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/operators/twopipes.md @@ -0,0 +1,38 @@ +--- +title: "Apache Hive : String Concatenation ||" +date: 2026-08-12 +--- + +# Apache Hive : String Concatenation || + +You can use || operator to concatenate two or more strings. + +**Syntax:** + +``` +expr || expr [|| expr ...] +``` + +The result of the operation is always a string. If an operand is a number, it is implicitly converted to string before concatenation. + +If an operand is NULL, it is treated as an empty string '' in the concatenation. If all operands are NULL, the result is NULL. + +**Examples:** + +| **Concatenation** | **Result** | **Result Type** | +| --- | --- | --- | +| 'a' `\|\|` 'b' `\|\|` 'c' | 'abc' | String | +| 'a' `\|\|` 1 `\|\|` 'c' | 'a1c' | String | +| 'a' `\|\|` NULL `\|\|` 'c' | 'ac' | String | +| NULL `\|\|` NULL | NULL | String | + +**On-the-fly SQL Conversion** + +Hive does not support || operator, so PL/HQL automatically converts in to [CONCAT]({{< ref "concat" >}}) function in SQL SELECT statements. + +**Compatibility:** Oracle, IBM DB2, Teradata, PostgreSQL and Netezza + +**Version:** HPL/SQL 0.1 + +See also: +- [CONCAT Function]({{< ref "concat" >}}) diff --git a/content/docs/latest/user/hive-hplsql/start.md b/content/docs/latest/user/hive-hplsql/start.md new file mode 100644 index 00000000..bcd1b208 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/start.md @@ -0,0 +1,134 @@ +--- +title: "Apache Hive : HPL/SQL - Get Started" +date: 2026-08-12 +--- + +# Apache Hive : HPL/SQL - Get Started + +Quick guide how to start using HPL/SQL. + +## Installation + +You can install HPL/SQL by [Apache Hive downloads](https://hive.apache.org/general/downloads/) .tar.gz or .zip file, or build it from the [Apache Hive downloads](https://hive.apache.org/general/downloads/). + +### Requirements + +- Java 1.6 or higher +- Hadoop 1.x. and 2.x + +### Installing HPL/SQL from Binaries = + +**1. Download** + +[Apache Hive downloads](https://hive.apache.org/general/downloads/) a HPL/SQL release and uncompress to the preferred location, for example ~/hplsql/ directory. The HPL/SQL program directory includes the following files: + +- hplsql - Shell script to launch HPL/SQL on Linux +- hplsql.cmd - Shell script to launch the tool on Windows +- hplsql-x.x.x.jar - HPL/SQL executable (x.x.x contains the version) +- hplsql-site.xml - HPL/SQL [configuration]({{< ref "configuration" >}}) file +- antlr-runtime-4.5.jar - ANTLR parser runtime + +On Linux/UNIX make sure *hplsql* is an executable file (if you uncompress the tool from .zip file): + +``` +chmod +x /hplsql +``` + +**2. Configure CLASSPATH** (Optional) + +For Cloudera distributions, you can edit *hplsql* file, remove all lines containing + +``` +export "HADOOP_CLASSPATH=..." +``` + +and add the following line + +``` +export "HADOOP_CLASSPATH=/opt/cloudera/parcels/CDH/jars/*" +``` + +For Hortonworks distributions check if Hadoop jars are located in /usr/hdp/x.x.x.x-x/ directory and change all paths in *hplsql* file accordingly. + +For other distributions check whether Hadoop jars are located in /usr/lib/, and make necessary changes in *hplsql* file. + +**3. Test installation** + +Run the following command to test HPL/SQL installation: + +``` +/hplsql --version +HPL/SQL x.x.x +``` + +Or when executed from the current directory: + +``` +./hplsql --version +HPL/SQL x.x.x +``` + +If the version number is printed the tool is installed correctly. + +**4. Add to PATH variable** (Optional) + +You may add HPL/SQL directory to PATH variable: + +``` +export PATH=$PATH: +``` + +Then you can invoke HPL/SQL by running: + +``` +hplsql +``` + +## Configuration + +HPL/SQL uses [hplsql-site.xml]({{< ref "configuration" >}}) configuration file located in the HPL/SQL program directory where hplsql.jar is located. + +To run Hive queries from HPL/SQL you may need to specify the YARN job queue, for example: + +``` + + hplsql.conn.init.hive2conn + + set mapred.job.queue.name=dev; + set hive.execution.engine=mr; + use sales_db; + + +``` + +Note that [hplsql-site.xml]({{< ref "configuration" >}}) located in the current directory takes precedence over the configuration file in HPL/SQL program directory. + +### Running HPL/SQL = + +Now you can specify [options]({{< ref "cli" >}}) and run HPL/SQL, for example: + +``` +hplsql -e "CURRENT_DATE+1" + +hplsql -e "SELECT * FROM src LIMIT 1" +``` + +or + +``` +hplsql -f script.sql +``` + +## Use HPL/SQL in Shell Scripts + +Get a value from HPL/SQL script: + +``` +MDATE=$(hplsql -e "NVL(MIN_PARTITION_DATE(sales, local_dt, code='A'), '1970-01-01')") +``` + +``` +START=$(hplsql -e 'CURRENT_DATE - 1') +``` + +Read [HPL/SQL Reference]({{< ref "hive-hplsql" >}}) for more information how to use the tool. diff --git a/content/docs/latest/user/hive-hplsql/statements/_index.md b/content/docs/latest/user/hive-hplsql/statements/_index.md new file mode 100644 index 00000000..fd17c068 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/_index.md @@ -0,0 +1,4 @@ +--- +title: "Statements" +date: 2026-08-12 +--- diff --git a/content/docs/latest/user/hive-hplsql/statements/allocate-cursor.md b/content/docs/latest/user/hive-hplsql/statements/allocate-cursor.md new file mode 100644 index 00000000..04d3489c --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/allocate-cursor.md @@ -0,0 +1,156 @@ +--- +title: "Apache Hive : ALLOCATE CURSOR Statement" +date: 2026-08-12 +--- + +# Apache Hive : ALLOCATE CURSOR Statement + +ALLOCATE CURSOR statement allows you to declare a cursor and associate it with a result set returned from a stored procedure. + +**Syntax**: + +``` +ALLOCATE cursor_name CURSOR FOR PROCEDURE procedure_name; -- Teradata compatibility +| +ALLOCATE cursor_name CURSOR FOR RESULT SET locator_name; -- DB2 compatibility +``` + +**Example 1:** + +Sample stored procedure returning a single result set: + +``` +CREATE PROCEDURE spOpenIssues + DYNAMIC RESULT SETS 1 +BEGIN + DECLARE cur CURSOR WITH RETURN FOR + SELECT id, name FROM issues; + OPEN cur; +END; +``` + +Call a stored procedure and process the returned result set (Teradata compatibility): + +``` +DECLARE id INT; +DECLARE name VARCHAR(30); + +CALL spOpenIssues; +ALLOCATE c1 CURSOR FOR PROCEDURE spOpenIssues; + +FETCH c1 INTO id, name; +WHILE (SQLCODE = 0) +DO + PRINT id || ' - ' || name; + FETCH c1 INTO id, name; +END WHILE; +CLOSE c1; +``` + +Call a stored procedure and process the returned result set (IBM DB2 compatibility): + +``` +DECLARE id INT; +DECLARE name VARCHAR(30); +DECLARE loc RESULT_SET_LOCATOR VARYING; + +CALL spOpenIssues; +ASSOCIATE RESULT SET LOCATOR (loc) WITH PROCEDURE spOpenIssues; +ALLOCATE c1 CURSOR FOR RESULT SET loc; + +FETCH c1 INTO id, name; +WHILE (SQLCODE = 0) +DO + PRINT id || ' - ' || name; + FETCH c1 INTO id, name; +END WHILE; +CLOSE c1; +``` + +**Example 2:** + +Sample stored procedure returning multiple result sets: + +``` +CREATE PROCEDURE spOpenIssues2 + DYNAMIC RESULT SETS 2 +BEGIN + DECLARE cur CURSOR WITH RETURN FOR + SELECT id, name FROM issues; + DECLARE cur2 CURSOR WITH RETURN FOR + SELECT id, name FROM issues_hold; + OPEN cur; + OPEN cur2; +END; +``` + +Call a stored procedure and process 2 result sets (Teradata compatibility): + +``` +DECLARE id INT; +DECLARE name VARCHAR(30); + +CALL spOpenIssues2; + +-- First result set +ALLOCATE c1 CURSOR FOR PROCEDURE spOpenIssues2; +FETCH c1 INTO id, name; +WHILE (SQLCODE = 0) +DO + -- ... + FETCH c1 INTO id, name; +END WHILE; +CLOSE c1; + +-- Second result set +ALLOCATE c2 CURSOR FOR PROCEDURE spOpenIssues2; +FETCH c2 INTO id, name; +WHILE (SQLCODE = 0) +DO + -- ... + FETCH c2 INTO id, name; +END WHILE; +CLOSE c2; +``` + +Call a stored procedure and process 2 result sets (IBM DB2 compatibility): + +``` +DECLARE id INT; +DECLARE name VARCHAR(30); +DECLARE loc1 RESULT_SET_LOCATOR VARYING; +DECLARE loc2 RESULT_SET_LOCATOR VARYING; + +CALL spOpenIssues2; +ASSOCIATE RESULT SET LOCATOR (loc1, loc2) WITH PROCEDURE spOpenIssues2; + +-- First result set +ALLOCATE c1 CURSOR FOR RESULT SET loc1; +FETCH c1 INTO id, name; +WHILE (SQLCODE = 0) +DO + -- ... + FETCH c1 INTO id, name; +END WHILE; +CLOSE c1; + +-- Second result set +ALLOCATE c2 CURSOR FOR RESULT SET loc2; +FETCH c2 INTO id, name; +WHILE (SQLCODE = 0) +DO + -- ... + FETCH c2 INTO id, name; +END WHILE; +CLOSE c2; +``` + +**Compatibility:** IBM DB2 and Teradata + +**Version:** HPL/SQL 0.3.11 + +**See also:** +- [OPEN]({{< ref "open" >}}) +- [FETCH]({{< ref "fetch" >}}) +- [CLOSE]({{< ref "close" >}}) +- [SQLCODE]({{< ref "sqlcode" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/associate-locator.md b/content/docs/latest/user/hive-hplsql/statements/associate-locator.md new file mode 100644 index 00000000..c36a4d64 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/associate-locator.md @@ -0,0 +1,23 @@ +--- +title: "Apache Hive : ASSOCIATE LOCATOR Statement" +date: 2026-08-12 +--- + +# Apache Hive : ASSOCIATE LOCATOR Statement + +ASSOCIATE LOCATOR statement allows you to associate locator variable with a result set returned from a stored procedure. + +Then you can use [ALLOCATE CURSOR]({{< ref "allocate-cursor" >}}) statement to assign a cursor for the locator and fetch data. + +**Syntax**: + +``` +ASSOCIATE [RESULT SET] LOCATOR | LOCATORS (loc [, locN, ...]) + WITH PROCEDURE procedure_name +``` + +For examples, see [ALLOCATE CURSOR]({{< ref "allocate-cursor" >}}) statement. + +**Compatibility:** IBM DB2 + +**Version:** HPL/SQL 0.3.11 diff --git a/content/docs/latest/user/hive-hplsql/statements/break.md b/content/docs/latest/user/hive-hplsql/statements/break.md new file mode 100644 index 00000000..01ce7993 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/break.md @@ -0,0 +1,27 @@ +--- +title: "Apache Hive : BREAK Statement - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : BREAK Statement - PL/HQL Reference + +BREAK statement exits the innermost loop. + +Syntax: + +``` +BREAK; +``` + +**Example:** + +``` +DECLARE count INT DEFAULT 3; +WHILE 1=1 BEGIN + SET count = count - 1; + IF count = 0 + BREAK; +END +``` + +**Compatibility:** Microsoft SQL Server. diff --git a/content/docs/latest/user/hive-hplsql/statements/call.md b/content/docs/latest/user/hive-hplsql/statements/call.md new file mode 100644 index 00000000..88a10a8f --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/call.md @@ -0,0 +1,44 @@ +--- +title: "Apache Hive : CALL Statement - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : CALL Statement - PL/HQL + +CALL statement allows you to execute a stored procedure. + +**Syntax**: + +``` +CALL procedure_name [(parameter, ...)]; +``` + +**Example**: + +Define a procedure and then call passing a parameter: + +``` +CREATE PROCEDURE set_message(IN name STRING, OUT result STRING) +BEGIN + SET result = 'Hello, ' || name || '!'; +END; + +-- Now call the procedure and print the results +DECLARE str STRING; +CALL set_message('world', str); +PRINT str; + +Result: +-- +Hello, world! +``` + +**Compatibility:** Teradata, IBM DB2 and MySQL + +**Version**: PL/HQL 0.3.1 + +See also: +- [User-Defined Functions and Stored Procedures]({{< ref "udf-sproc" >}}) +- [CREATE FUNCTION]({{< ref "create-function" >}}) +- [CREATE PROCEDURE]({{< ref "create-procedure" >}}) +- [INCLUDE]({{< ref "include" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/close.md b/content/docs/latest/user/hive-hplsql/statements/close.md new file mode 100644 index 00000000..645e1527 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/close.md @@ -0,0 +1,38 @@ +--- +title: "Apache Hive : CLOSE Statement - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : CLOSE Statement - PL/HQL Reference + +CLOSE statement closes a cursor. + +**Syntax**: + +``` +CLOSE cursor_name; +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| cursor_name | | Identifier | The name of the previously opened cursor | + +**Examples:** + +``` +DECLARE id INT; +DECLARE cur CURSOR FOR 'SELECT id FROM db.orders'; +OPEN cur; +FETCH cur INTO id; +CLOSE cur; +``` + +**Compatibility:** Oracle, IBM DB2, Teradata, SQL Server, PostgreSQL, MySQL. + +**See also:** +- [DECLARE CURSOR]({{< ref "declare-cursor" >}}) +- [OPEN]({{< ref "open" >}}) +- [FETCH]({{< ref "fetch" >}}) +- [SQLCODE]({{< ref "sqlcode" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/cmp.md b/content/docs/latest/user/hive-hplsql/statements/cmp.md new file mode 100644 index 00000000..c8d3a308 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/cmp.md @@ -0,0 +1,47 @@ +--- +title: "Apache Hive : CMP Statement" +date: 2026-08-12 +--- + +# Apache Hive : CMP Statement + +CMP statement helps you compare data in tables that can be located in the same or different databases. + +**Syntax**: + +Compare the total number of rows: + +``` +CMP ROW_COUNT table1 [where_clause1] | (select_stmt1) [AT conn1], + table2 [where_clause2] | (select_stmt2) [AT conn2] +``` + +Compare the column summary (COUNT, SUM, MIN and MAX applied to columns): + +``` +CMP SUM table1 [where_clause1] [AT conn1], table2 [where_clause2] [AT conn2] +``` + +Notes: +- When data are equal, the CMP statement sets SQLCODE to 0. If data are not equal, SQLCODE is set to 1. In case of any SQL error, SQLCODE is set to -1 +- When the connection profile is not specified, the default connection profile is used for the specified table + +**Example 1**: + +Compare the number of rows: + +``` +CMP ROW_COUNT sales.users WHERE local_dt = CURRENT_DATE, users_daily AT mysqlconn; +``` + +**Example 2**: + +Compare aggregate data in two tables: + +``` +CMP SUM sales.users WHERE local_dt = CURRENT_DATE, users_daily AT mysqlconn; +``` + +**Compatibility:** HPL/SQL Extension + +**Version:** HPL/SQL 0.3.13 diff --git a/content/docs/latest/user/hive-hplsql/statements/copy-from-ftp.md b/content/docs/latest/user/hive-hplsql/statements/copy-from-ftp.md new file mode 100644 index 00000000..7ac8c7cc --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/copy-from-ftp.md @@ -0,0 +1,32 @@ +--- +title: "Apache Hive : COPY FROM FTP Statement" +date: 2026-08-12 +--- + +# Apache Hive : COPY FROM FTP Statement + +COPY FROM FTP statement allows to copy files from a FTP server to local or any Hadoop compatible file system. Using this statement you can easily copy FTP subdirectories into HDFS i.e. + +The NEW option helps you build a ETL process and download only new files from FTP. + +**Syntax**: + +``` +COPY FROM FTP host [USER user [PWD password]] [DIR directory] [FILES files_wildcard] + [TO [LOCAL] target_directory] [options] + +options: + OVERWRITE | NEW + SUBDIR + SESSIONS num +``` + +Notes: +- *host, user* and *pwd* specify the FTP host name, user name and password (identifier, string literal, variable or expression can be specified). +- DIR option specifies the directory to get files, optional. If skipped, the current working FTP directory is used +- FILES option specifies a wildcard (Java regular expression) to choose which files to transfer. By default, all files from the specified directory are transferred. +- LOCAL keyword means that files are copied to the local file system. By default files are copied to HDFS compatible file system. +- OVERWRITE means that the existing files will be overwritten, this is the default. +- NEW means that only new files will be transferred, and existing files will be skipped. +- SUBDIR option specifies to transfer files in sub-directories. The directory structure is recreated in the target. By default, the command transfers files only from the directory specified by DIR option. +- SESSIONS specifies the number of concurrent FTP sessions to transfer the files. Each session transfers the whole file. By default, files are copied in the single session. diff --git a/content/docs/latest/user/hive-hplsql/statements/copy-from-local.md b/content/docs/latest/user/hive-hplsql/statements/copy-from-local.md new file mode 100644 index 00000000..1f7d5fe0 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/copy-from-local.md @@ -0,0 +1,45 @@ +--- +title: "Apache Hive : COPY FROM LOCAL Statement" +date: 2026-08-12 +--- + +# Apache Hive : COPY FROM LOCAL Statement + +COPY FROM LOCAL statement allows to copy local directories and files to Hadoop compatible file system. Using this statement you can easily copy subdirectories into HDFS i.e. + +**Syntax**: + +``` +COPY FROM LOCAL src [, src2, ...] TO tgt [options] + +options: + OVERWRITE + DELETE + IGNORE +``` + +Notes: + +- *srcN* specifies a file or directory. If a directory is specified all subdirectories and their files are copied as well. +- *srcN* can be an expression, variable, quoted or unquoted string. +- If a single file is copied *tgt* must specify a path including the target file name. +- If multiple files are copied *tgt* must specify a directory. +- If the target directory does not exist it is created. +- OVERWRITE specifies to overwrite the target files if they exist. +- DELETE specifies to delete the source file upon successfull copy. +- IGNORE specifies to ignore errors when copying a file and proceed to copy the remaining files. + +**Example**: + +Copy files from a directory and its subdirectories to a daily backup directory: + +``` +COPY FROM LOCAL '/home/data' TO '/user/backup/' || CURRENT_DATE; +``` + +**Compatibility:** HPL/SQL Extension + +**Version:** HPL/SQL 0.3.7 + +See also: +- [COPY]({{< ref "copy" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/copy.md b/content/docs/latest/user/hive-hplsql/statements/copy.md new file mode 100644 index 00000000..68fd6fe7 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/copy.md @@ -0,0 +1,75 @@ +--- +title: "Apache Hive : COPY Statement" +date: 2026-08-12 +--- + +# Apache Hive : COPY Statement + +COPY statement allows to transfer data between tables and files. Use it to transfer relatively small volumes of data i.e. query results, look-up and dimension tables. + +When you copy data between tables they can be located in different databases. + +**Syntax**: + +Export data to a file: + +``` +COPY table_name | (select_stmt) TO [HDFS] file_name [options] + +options: + DELIMITER 'char' +| SQLINSERT target_table_name +``` + +Copy data between existing tables: + +``` +COPY table_name | (select_stmt) TO target_table_name AT target_conn_name [options] + +options: + BATCHSIZE num +``` + +Notes: + +- *table_name* is an identifier. +- *file_name* can be an expression, quoted or unquoted string. +- If *file_name* already exists it is overwritten. +- When HDFS is specified, the data is copied to a HDFS-compatible file system. +- DELIMITER specifies the delimiter between column values, '\t' (TAB character) is the default. +- SQLINSERT specifies to generate SQL INSERT statements to insert data to *target_table_name*. The statements are just stored in the file, and not executed. +- When you copy data into another table, the table must exist. +- BATCHSIZE specifies the number of rows to transfer in a single batch when copying rows between tables, the default is 1000. + +**Example 1**: + +Export the query results to a file: + +``` +COPY (SELECT id, name FROM sales.users WHERE local_dt = CURRENT_DATE) + TO /data/users.txt DELIMITER '\t'; +``` + +**Example 2**: + +Generate SQL INSERT statements: + +``` +COPY sales.users TO /data/users2.sql SQLINSERT sales.users; +``` + +**Example 3**: + +Copy rows from between tables in different databases: + +``` +COPY sales.users TO sales.users2 AT tdconn; +``` + +**Compatibility:** HPL/SQL Extension, PostgreSQL + +**Version:** HPL/SQL 0.3.7 + +See also: +- [COPY FROM LOCAL]({{< ref "copy-from-local" >}}) +- [INSERT DIRECTORY]({{< ref "insert-directory" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/create-database.md b/content/docs/latest/user/hive-hplsql/statements/create-database.md new file mode 100644 index 00000000..86909d90 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/create-database.md @@ -0,0 +1,32 @@ +--- +title: "Apache Hive : CREATE DATABASE Statement" +date: 2026-08-12 +--- + +# Apache Hive : CREATE DATABASE Statement + +CREATE DATABASE statement allows you to create a database. + +**Syntax**: + +``` +CREATE DATABASE | SCHEMA [IF NOT EXISTS] dbname_expr + [COMMENT comment_expr] + [LOCATION path_expr] +``` + +**Example**: + +Create a database named *testYYYYMMDD* (current date): + +``` +create database 'test' || replace(current_date, '-', ''); +``` + +**Compatibility:** MySQL, MariaDB, Hive + +**Version:** HPL/SQL 0.3.17 + +See also: +- [DROP DATABASE]({{< ref "drop-database" >}}) +- [USE]({{< ref "use" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/create-function.md b/content/docs/latest/user/hive-hplsql/statements/create-function.md new file mode 100644 index 00000000..535dc3f7 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/create-function.md @@ -0,0 +1,66 @@ +--- +title: "Apache Hive : CREATE FUNCTION Statement" +date: 2026-08-12 +--- + +# Apache Hive : CREATE FUNCTION Statement + +CREATE FUNCTION statement allows you to create a user-defined SQL function. + +**Syntax**: + +``` +ALTER | CREATE [OR REPLACE] | REPLACE FUNCTION function_name ( [parameters] ) + RETURNS | RETURN data_type + [AS | IS] + body + +parameters: + [IN] name data_type, ... + | + name [IN] data_type, ... + +body: + statement | expression | BEGIN statements END +``` + +**Example 1**: + +Create a function without parameters: + +``` +CREATE FUNCTION hello() + RETURNS STRING +BEGIN + RETURN 'Hello, world'; +END; + +-- Call the function +PRINT hello(); +``` + +**Example 2**: + +Create a function with a parameter: + +``` +CREATE FUNCTION hello2(text STRING) + RETURNS STRING +BEGIN + RETURN 'Hello, ' || text || '!'; +END; + +-- Call the function +PRINT hello2('world'); +``` + +**Compatibility:** Oracle, Teradata, IBM DB2, Microsoft SQL Server, PostgreSQL, MySQL and Netezza + +**Version**: HPL/HQL 0.3.1 + +See also: +- [User-Defined Functions and Stored Procedures]({{< ref "udf-sproc" >}}) +- [CALL]({{< ref "call" >}}) +- [CREATE PACKAGE]({{< ref "create-package" >}}) +- [CREATE PROCEDURE]({{< ref "create-procedure" >}}) +- [INCLUDE]({{< ref "include" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/create-local-temporary-table.md b/content/docs/latest/user/hive-hplsql/statements/create-local-temporary-table.md new file mode 100644 index 00000000..a04538b8 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/create-local-temporary-table.md @@ -0,0 +1,51 @@ +--- +title: "Apache Hive : CREATE LOCAL TEMPORARY TABLE - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : CREATE LOCAL TEMPORARY TABLE - PL/HQL + +CREATE LOCAL TEMPORARY TABLE statement allows you to create a temporary table for the current session. + +**Syntax**: + +``` +CREATE LOCAL TEMPORARY TABLE table_name +( + column_name data_type [NULL | NOT NULL] + [, ...] +) +[ ON COMMIT DELETE ROWS | ON COMMIT PRESERVE ROWS] +``` + +Notes: +- The local temporary table is automatically dropped at the end of session. + +For more details how temporary table support is implemented in PL/HQL, see [Native and Managed Temporary Tables]({{< ref "temporary-tables" >}}). + +**Example**: + +Create a managed temporary table and use it in other SQL statements: + +``` +SET plhql.temp.tables = managed; + +CREATE LOCAL TEMPORARY TABLE temp1 +( + c1 INT, + c2 STRING +); + +INSERT INTO temp1 SELECT 1, 'A' FROM dual; + +SELECT * FROM temp1; +``` + +**Compatibility:** ANSI SQL + +**Version**: PL/HQL 0.3.1 + +See also: +- [Native and Managed Temporary Tables]({{< ref "temporary-tables" >}}) +- [CREATE VOLATILE TABLE]({{< ref "create-volatile-table" >}}) +- [DECLARE TEMPORARY TABLE]({{< ref "declare-temporary-table" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/create-package.md b/content/docs/latest/user/hive-hplsql/statements/create-package.md new file mode 100644 index 00000000..b5315021 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/create-package.md @@ -0,0 +1,84 @@ +--- +title: "Apache Hive : CREATE PACKAGE Statement" +date: 2026-08-12 +--- + +# Apache Hive : CREATE PACKAGE Statement + +CREATE PACKAGE statement allows you to define a collection of related variables, procedures and functions. + +**Syntax** + +Package specification: + +``` +[CREATE [OR REPLACE] | REPLACE] PACKAGE package_name AS | IS package_spec END + +package_spec: + variable declaration | + function declaration | + procedure declaration +``` + +Package body: + +``` +[CREATE [OR REPLACE] | REPLACE] PACKAGE BODY package_name AS | IS package_body END + +package_body: + private variable declaration | + function definition | + procedure definition +``` + +**Example**: + +Define a package and then call its members. + +Package specification: + +``` +create or replace package users as + session_count int := 0; + function get_count() return int; + procedure add(name varchar(100)); +end; +``` + +Package body: + +``` +create or replace package body users as + function get_count() return int + is + begin + return session_count; + end; + procedure add(name varchar(100)) + is + begin + -- ... + session_count = session_count + 1; + end; +end; +``` + +Using the package: + +``` +users.add('John'); +users.add('Sarah'); +users.add('Paul'); +print 'Number of users: ' || users.get_count(); +``` + +**Compatibility:** Oracle + +**Version**: HPL/SQL 0.3.13 + +See also: +- [User-Defined Functions and Stored Procedures]({{< ref "udf-sproc" >}}) +- [CALL]({{< ref "call" >}}) +- [CREATE FUNCTION]({{< ref "create-function" >}}) +- [CREATE PROCEDURE]({{< ref "create-procedure" >}}) +- [INCLUDE]({{< ref "include" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/create-procedure.md b/content/docs/latest/user/hive-hplsql/statements/create-procedure.md new file mode 100644 index 00000000..a2c2e675 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/create-procedure.md @@ -0,0 +1,55 @@ +--- +title: "Apache Hive : CREATE PROCEDURE Statement" +date: 2026-08-12 +--- + +# Apache Hive : CREATE PROCEDURE Statement + +CREATE PROCEDURE statement allows you to create a user-defined SQL procedure (stored procedure). + +**Syntax**: + +``` +[ALTER | CREATE [OR REPLACE] | REPLACE] PROCEDURE | PROC procedure_name [parameters] + [AS | IS] + body + +parameters: + ([IN | OUT | INOUT | IN OUT] name data_type, ...) + | + (name [IN | OUT | INOUT | IN OUT] data_type, ...) + +body: + statement | expression | BEGIN statements END +``` + +**Example**: + +Define a procedure and then call passing a parameter: + +``` +CREATE PROCEDURE set_message(IN name STRING, OUT result STRING) +BEGIN + SET result = 'Hello, ' || name || '!'; +END; + +-- Now call the procedure and print the results +DECLARE str STRING; +CALL set_message('world', str); +PRINT str; + +Result: +-- +Hello, world! +``` + +**Compatibility:** Oracle, Teradata, IBM DB2, Microsoft SQL Server, PostgreSQL, MySQL and Netezza + +**Version**: PL/HQL 0.3.1 + +See also: +- [User-Defined Functions and Stored Procedures]({{< ref "udf-sproc" >}}) +- [CALL]({{< ref "call" >}}) +- [CREATE PACKAGE]({{< ref "create-package" >}}) +- [CREATE FUNCTION]({{< ref "create-function" >}}) +- [INCLUDE]({{< ref "include" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/create-table.md b/content/docs/latest/user/hive-hplsql/statements/create-table.md new file mode 100644 index 00000000..fd118c5a --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/create-table.md @@ -0,0 +1,42 @@ +--- +title: "Apache Hive : CREATE TABLE Statement - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : CREATE TABLE Statement - PL/HQL + +CREATE TABLE statement create a table in the database. + +**Syntax**: + +``` +CREATE TABLE [IF NOT EXISTS] table_name +( + column_name data_type [NULL | NOT NULL] + [, constraint ...] + [, ...] +) +``` + +## CREATE TABLE Conversion + +If the CREATE TABLE statement is defined using the syntax not supported by Hive, it is automatically converted to conform to Hive syntax. + +Currently PL/HQL converts data types, removes NOT NULL/NULL, constraints and default values. For more information, see [On-the-Fly Conversion]({{< ref "conversion" >}}) + +**Example**: + +Convert SQL and create a table in Hive: + +``` +CREATE TABLE dept ( + deptno NUMBER(2,0), + dname NUMBER(14), + loc VARCHAR2(13), + CONSTRAINT pk_dept PRIMARY KEY (deptno) +); +``` + +**Compatibility:** Oracle, Microsoft SQL Server, IBM DB2, Teradata, PostgreSQL, MySQL and Netezza + +**Version**: PL/HQL 0.03 diff --git a/content/docs/latest/user/hive-hplsql/statements/create-volatile-table.md b/content/docs/latest/user/hive-hplsql/statements/create-volatile-table.md new file mode 100644 index 00000000..7bf43e8b --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/create-volatile-table.md @@ -0,0 +1,51 @@ +--- +title: "Apache Hive : CREATE VOLATILE TABLE Statement - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : CREATE VOLATILE TABLE Statement - PL/HQL + +CREATE VOLATILE TABLE statement allows you to create a temporary table for the current session. + +**Syntax**: + +``` +CREATE [SET | MULTISET] VOLATILE TABLE table_name +( + column_name data_type [NULL | NOT NULL] + [, ...] +) +[ ON COMMIT DELETE ROWS | ON COMMIT PRESERVE ROWS] +``` + +Notes: +- The volatile table is automatically dropped at the end of session. + +For more details how temporary table support is implemented in PL/HQL, see [Native and Managed Temporary Tables]({{< ref "temporary-tables" >}}). + +**Example**: + +Create a managed temporary table and use it in other SQL statements: + +``` +SET plhql.temp.tables = managed; + +CREATE VOLATILE TABLE temp1 +( + c1 INT, + c2 STRING +); + +INSERT INTO temp1 SELECT 1, 'A' FROM dual; + +SELECT * FROM temp1; +``` + +**Compatibility:** Teradata + +**Version**: PL/HQL 0.3.1 + +See also: +- [Native and Managed Temporary Tables]({{< ref "temporary-tables" >}}) +- [CREATE LOCAL TEMPORARY TABLE]({{< ref "create-local-temporary-table" >}}) +- [DECLARE TEMPORARY TABLE]({{< ref "declare-temporary-table" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/declare-condition.md b/content/docs/latest/user/hive-hplsql/statements/declare-condition.md new file mode 100644 index 00000000..02850de3 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/declare-condition.md @@ -0,0 +1,47 @@ +--- +title: "Apache Hive : DECLARE CONDITION Statement - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : DECLARE CONDITION Statement - PL/HQL + +You can use DECLARE CONDITION statement to declare a user-defined condition. + +Then you can define a handler for this condition using [DECLARE HANDLER]({{< ref "declare-handler" >}}), and raise the condition using the [SIGNAL]({{< ref "signal" >}}) statement. + +**Syntax**: + +``` +DECLARE condition_name CONDITION; +``` + +**Example:** + +Raise a condition if the number of rows is not equal to the specified number: + +``` +DECLARE cnt INT DEFAULT 0; +DECLARE wrong_cnt_condition CONDITION; + +DECLARE EXIT HANDLER FOR wrong_cnt_condition + PRINT 'Wrong number of rows'; + +SELECT COUNT(*) INTO cnt FROM TABLE (VALUES (1,2)); + +IF cnt <> 1 THEN + SIGNAL wrong_cnt_condition; +END IF; +``` + +**Compatibility:** IBM DB2, Teradata and MySQL. + +**Version**: PL/HQL 0.3.1 + +**See also:** +- [Error Handling]({{< ref "error-handling" >}}) +- [DECLARE HANDLER]({{< ref "declare-handler" >}}) +- [SQLCODE]({{< ref "sqlcode" >}}) +- [SQLSTATE]({{< ref "sqlstate" >}}) +- [GET DIAGNOSTICS]({{< ref "get-diagnostics" >}}) +- [SIGNAL]({{< ref "signal" >}}) +- [RESIGNAL]({{< ref "resignal" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/declare-cursor.md b/content/docs/latest/user/hive-hplsql/statements/declare-cursor.md new file mode 100644 index 00000000..d2284523 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/declare-cursor.md @@ -0,0 +1,68 @@ +--- +title: "Apache Hive : DECLARE CURSOR Statement - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : DECLARE CURSOR Statement - PL/HQL Reference + +You can use DECLARE CURSOR statement to declare a cursor using a dynamic SQL. + +**Syntax**: + +``` +DECLARE name CURSOR FOR | AS | IS dynamic_sql_string | select_statement; +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| dynamic_sql_string | VARCHAR | Variable or expression | Dynamic SQL to define the cursor | +| select_statement | | | SQL SELECT statement to define the cursor | + +**Notes:** + +- *dynamic_sql_string* expression is evaluated at cursor open time, not declare time. + +**Example 1:** + +Using a dynamic SQL string: + +``` +DECLARE tabname VARCHAR DEFAULT 'db.orders'; +DECLARE id INT; +DECLARE cur CURSOR FOR 'SELECT id FROM ' || tabname; +OPEN cur; +FETCH cur INTO id; +WHILE SQLCODE=0 THEN + PRINT id; + FETCH cur INTO id; +END WHILE; +CLOSE cur; +``` + +**Example 2:** + +Using a SQL SELECT statement: + +``` +DECLARE id INT; +DECLARE cur CURSOR FOR SELECT id FROM db.orders; +OPEN cur; +FETCH cur INTO id; +WHILE SQLCODE=0 THEN + PRINT id; + FETCH cur INTO id; +END WHILE; +CLOSE cur; +``` + +**Compatibility:** IBM DB2, MySQL, Teradata. + +**Version:** PL/HQL 0.01 + +**See also:** +- [OPEN]({{< ref "open" >}}) +- [FETCH]({{< ref "fetch" >}}) +- [CLOSE]({{< ref "close" >}}) +- [SQLCODE]({{< ref "sqlcode" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/declare-handler.md b/content/docs/latest/user/hive-hplsql/statements/declare-handler.md new file mode 100644 index 00000000..9027c32a --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/declare-handler.md @@ -0,0 +1,56 @@ +--- +title: "Apache Hive : DECLARE HANDLER Statement - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : DECLARE HANDLER Statement - PL/HQL + +You can use DECLARE HANDLER statement to define one or more PL/HQL statements to execute when a condition occurs. + +**Syntax**: + +``` +DECLARE [CONTINUE | EXIT] HANDLER FOR + [SQLEXCEPTION | NOT FOUND | user_condition] code_block; +``` + +**Description:** + +| CONTINUE | When the handler completes, control is returned to PL/HQL statement following the statement that raised the condition | +| --- | --- | +| EXIT | After the handler completes, control is returned to the end of the block that declared the handler | +| *code_block* | PL/HQL statement(s) to execute when the specified condition occurs | + +**Examples:** + +``` +DECLARE name VARCHAR(100); +DECLARE no_rows INT DEFAULT 0; + +DECLARE CONTINUE HANDLER FOR NOT FOUND + SET no_rows = 1; + +OPEN cur FOR 'SELECT name FROM db.orders'; + +FETCH cur INTO name; +WHILE no_rows = 0 THEN + PRINT id; + FETCH cur INTO name; +END WHILE; +CLOSE cur; +``` + +**Compatibility:** IBM DB2, Teradata and MySQL. + +**Version**: +- PL/HQL 0.3.1 - User-defined condition supported +- PL/HQL 0.01 - Introduced + +**See also:** +- [Error Handling]({{< ref "error-handling" >}}) +- [DECLARE CONDITION]({{< ref "declare-condition" >}}) +- [SQLCODE]({{< ref "sqlcode" >}}) +- [SQLSTATE]({{< ref "sqlstate" >}}) +- [GET DIAGNOSTICS]({{< ref "get-diagnostics" >}}) +- [SIGNAL]({{< ref "signal" >}}) +- [RESIGNAL]({{< ref "resignal" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/declare-temporary-table.md b/content/docs/latest/user/hive-hplsql/statements/declare-temporary-table.md new file mode 100644 index 00000000..7e26b28c --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/declare-temporary-table.md @@ -0,0 +1,61 @@ +--- +title: "Apache Hive : DECLARE TEMPORARY TABLE - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : DECLARE TEMPORARY TABLE - PL/HQL + +DECLARE TEMPORARY TABLE statement allows you to define a temporary table for the current session. + +**Syntax**: + +``` +DECLARE [GLOBAL] TEMPORARY TABLE table_name +( + column_name data_type [NULL | NOT NULL] + [, ...] +) +[ ON COMMIT DELETE ROWS | ON COMMIT PRESERVE ROWS] +``` + +### Compatibility Options + +The following options are supported for compatibility with other databases: + +**IBM DB2:** + +``` +IN tablespace_name +WITH REPLACE +DISTRIBUTE BY HASH (col, ...) +LOGGED | NOT LOGGED +``` + +For more details how temporary table support is implemented in PL/HQL, see [Native and Managed Temporary Tables]({{< ref "temporary-tables" >}}). + +**Example**: + +Create a managed temporary table and use it in other SQL statements: + +``` +SET plhql.temp.tables = managed; + +DECLARE TEMPORARY TABLE temp1 +( + c1 INT, + c2 STRING +); + +INSERT INTO temp1 SELECT 1, 'A' FROM dual; + +SELECT * FROM temp1; +``` + +**Compatibility:** IBM DB2 + +**Version**: PL/HQL 0.03 + +See also: +- [Native and Managed Temporary Tables]({{< ref "temporary-tables" >}}) +- [CREATE LOCAL TEMPORARY TABLE]({{< ref "create-local-temporary-table" >}}) +- [CREATE VOLATILE TABLE]({{< ref "create-volatile-table" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/describe.md b/content/docs/latest/user/hive-hplsql/statements/describe.md new file mode 100644 index 00000000..40177337 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/describe.md @@ -0,0 +1,29 @@ +--- +title: "Apache Hive : DESCRIBE Statement" +date: 2026-08-12 +--- + +# Apache Hive : DESCRIBE Statement + +DESCRIBE statement allows you to print a metadata information for the specified database object. + +**Syntax**: + +``` +DESCRIBE | DESC [TABLE] table_name +``` + +**Example**: + +Describe *src* table in Hive: + +``` +desc src; +-- +key string default +value string default +``` + +**Compatibility:** Oracle, IBM DB2, Hive, MySQL, MariaDB. + +**Version:** HPL/SQL 0.3.17 diff --git a/content/docs/latest/user/hive-hplsql/statements/drop-database.md b/content/docs/latest/user/hive-hplsql/statements/drop-database.md new file mode 100644 index 00000000..f20dec15 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/drop-database.md @@ -0,0 +1,30 @@ +--- +title: "Apache Hive : DROP DATABASE Statement" +date: 2026-08-12 +--- + +# Apache Hive : DROP DATABASE Statement + +DROP DATABASE statement allows you to drop a database. + +**Syntax**: + +``` +DROP DATABASE | SCHEMA [IF EXISTS] dbname_expr +``` + +**Example**: + +Drop a database named *testYYYYMMDD* (current date): + +``` +drop database if exists 'test' || replace(current_date, '-', ''); +``` + +**Compatibility:** Hive + +**Version:** HPL/SQL 0.3.17 + +See also: +- [CREATE DATABASE]({{< ref "create-database" >}}) +- [USE]({{< ref "use" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/drop-table.md b/content/docs/latest/user/hive-hplsql/statements/drop-table.md new file mode 100644 index 00000000..6519bd91 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/drop-table.md @@ -0,0 +1,21 @@ +--- +title: "Apache Hive : DROP TABLE Statement" +date: 2026-08-12 +--- + +# Apache Hive : DROP TABLE Statement + +DROP TABLE statement drops a table. + +**Syntax**: + +``` +DROP TABLE [IF EXISTS] table_name +``` + +**Compatibility:** Oracle, Microsoft SQL Server, IBM DB2, Teradata, PostgreSQL, MySQL, Hive + +**Version**: HPL/SQL 0.3 + +See also: +- [TRUNCATE TABLE]({{< ref "truncate" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/execute.md b/content/docs/latest/user/hive-hplsql/statements/execute.md new file mode 100644 index 00000000..863d10e1 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/execute.md @@ -0,0 +1,74 @@ +--- +title: "Apache Hive : EXECUTE Statement" +date: 2026-08-12 +--- + +# Apache Hive : EXECUTE Statement + +EXECUTE (EXEC or EXECUTE IMMEDIATE) statement executes a dynamic SQL statement and can return the scalar result to local variables. + +You can also use this statement to call a stored procedure. + +**Syntax:** + +``` +EXEC | EXECUTE | EXECUTE IMMEDIATE dynamic_sql_string [INTO var1, var2, ...]; +| +EXEC | EXECUTE proc_name [parm1 = val1, ... ] +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| dynamic_sql_string | VARCHAR | Variable or expression | Dynamic SQL to execute | +| INTO var1, var2, ... | Any | Variable | Variables to assign, optional | + +**Notes**: + +- If the query returns more than 1 row and the INTO clause is specified, only the columns from the first row are used in assignment +- If the statement returns 1 or more rows and the INTO clause is not specified, the result set data is sent to the standard output +- EXEC, EXECUTE are EXECUTE IMMEDIATE synonyms + +**Example:** + +Return the result into a variable: + +``` +DECLARE cnt INT; +EXECUTE 'SELECT COUNT(*) FROM db.orders' INTO cnt; +``` + +Execute a DML statement: + +``` +DECLARE tabname VARCHAR(100) DEFAULT 'tab1'; +EXECUTE IMMEDIATE 'CREATE TABLE ' || tabname || ' (c1 INT)'; +``` + +Print the results to standard output: + +``` +EXEC 'SELECT ''A'', ''B'' FROM dual'; +``` + +Call a stored procedure: + +``` +ALTER PROCEDURE spOrders + @lim INT +AS + DECLARE @cnt INT = 0 + SELECT @cnt = COUNT(*) from src LIMIT @lim + IF @cnt > 0 + SELECT * FROM src +GO + +EXEC spOrders @lim = 3 +``` + +**Compatibility:** Oracle, IBM DB2 and Microsoft SQL Server. + +**Version:** +- HPL/SQL 0.3.11 - Execute a stored procedure +- PL/HQL 0.01 diff --git a/content/docs/latest/user/hive-hplsql/statements/exit.md b/content/docs/latest/user/hive-hplsql/statements/exit.md new file mode 100644 index 00000000..bce5de53 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/exit.md @@ -0,0 +1,37 @@ +--- +title: "Apache Hive : EXIT WHEN Statement - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : EXIT WHEN Statement - PL/HQL Reference + +EXIT WHEN statement exits the loop or block marked by the given label. If the label is not specified, EXIT leaves the innermost loop. + +If a boolean expression is specified, and it evaluates to *true* then EXIT statement is executed, otherwise it is ignored and the execution continues from the statement following EXIT. + +**Syntax:** + +``` +EXIT [label] [WHEN boolean_expression]; +``` + +**Example:** + +``` +WHILE count > 0 LOOP + count := count - 1; + EXIT WHEN count = 0; +END LOOP; +``` + +``` +<> +WHILE 1=1 LOOP + <> + WHILE 1=1 LOOP + EXIT lbl; + END LOOP; +END LOOP; +``` + +**Compatibility:** Oracle, PostgreSQL and Netezza. diff --git a/content/docs/latest/user/hive-hplsql/statements/fetch.md b/content/docs/latest/user/hive-hplsql/statements/fetch.md new file mode 100644 index 00000000..a77fcba4 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/fetch.md @@ -0,0 +1,44 @@ +--- +title: "Apache Hive : FETCH Statement - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : FETCH Statement - PL/HQL Reference + +FETCH statement retrieve the next row from a cursor and assigns column values to local variable. + +**Syntax**: + +``` +FETCH [FROM] cursor_name INTO var1 [, var2, ...]; +``` + +**Parameters:** + +| **Parameter** | **Type** | **Value** | **Description** | +| --- | --- | --- | --- | +| cursor_name | | Identifier | The name of the previously opened cursor | +| varN | | Variable | A local variable | + +**Examples:** + +``` +DECLARE tabname VARCHAR DEFAULT 'db.orders'; +DECLARE id INT; +DECLARE cur CURSOR FOR 'SELECT id FROM ' || tabname; +OPEN cur; +FETCH cur INTO id; +WHILE SQLCODE=0 THEN + PRINT id; + FETCH cur INTO id; +END WHILE; +CLOSE cur; +``` + +**Compatibility:** Oracle, IBM DB2, Teradata, SQL Server, MySQL, PostgreSQL and Netezza. + +**See also:** +- [DECLARE CURSOR]({{< ref "declare-cursor" >}}) +- [OPEN]({{< ref "open" >}}) +- [CLOSE]({{< ref "close" >}}) +- [SQLCODE]({{< ref "sqlcode" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/for-cursor.md b/content/docs/latest/user/hive-hplsql/statements/for-cursor.md new file mode 100644 index 00000000..3558551b --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/for-cursor.md @@ -0,0 +1,38 @@ +--- +title: "Apache Hive : FOR Statement (Cursor Loop) - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : FOR Statement (Cursor Loop) - PL/HQL Reference + +FOR statement opens a cursor, executes one or more statements repeatedly for each row and closes the cursor. + +Syntax: + +``` +FOR cur_name IN [(] select_stmt [)] LOOP + statements +END LOOP; +``` + +**Notes:** + +- You can refer to the cursor columns using *cur_name.col_name* syntax + +**Example:** + +``` +FOR item IN ( + SELECT dname, loc as location + FROM dept + WHERE dname LIKE '%A%' + AND deptno > 10 + ORDER BY location) +LOOP + DBMS_OUTPUT.PUT_LINE('Name = ' || item.dname || ', Location = ' || item.location); +END LOOP; +``` + +**Compatibility:** Oracle, PostgreSQL and Netezza + +**Version:** PL/HQL 0.03 diff --git a/content/docs/latest/user/hive-hplsql/statements/for-range.md b/content/docs/latest/user/hive-hplsql/statements/for-range.md new file mode 100644 index 00000000..ba2eacad --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/for-range.md @@ -0,0 +1,46 @@ +--- +title: "Apache Hive : FOR Statement (Integer Range) - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : FOR Statement (Integer Range) - PL/HQL Reference + +FOR statement executes one or more statements repeatedly for the specified range of integer values. + +Syntax: + +``` +FOR index IN [REVERSE] lower_bound..upper_bound [BY | STEP increment] LOOP + statements +END LOOP; +``` + +**Notes:** + +- *index* - Implicitly declared integer variable +- If REVERSE is specified the index is decreased +- If specified, BY (or STEP) define the iteration step, default is 1 + +**Examples:** + +``` +FOR i IN 1..10 LOOP + -- i will have values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 +END LOOP; +``` + +``` +FOR i IN REVERSE 10..1 LOOP + -- i will have values: 10, 9, 8, 7, 6, 5, 4, 3, 1, 1 +END LOOP; +``` + +``` +FOR i IN 1..10 BY 2 LOOP + -- i will have values: 1, 3, 5, 7, 9 +END LOOP; +``` + +**Compatibility:** Oracle, PostgreSQL and Netezza. + +**Version:** PL/HQL 0.01 diff --git a/content/docs/latest/user/hive-hplsql/statements/get-diagnostics.md b/content/docs/latest/user/hive-hplsql/statements/get-diagnostics.md new file mode 100644 index 00000000..01bd1525 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/get-diagnostics.md @@ -0,0 +1,37 @@ +--- +title: "Apache Hive : GET DIAGNOSTICS Statement - PL/HQL" +date: 2026-08-12 +--- + +# Apache Hive : GET DIAGNOSTICS Statement - PL/HQL + +GET DIAGNOSTICS statement allows you to retrieve the error message, the number of rows about the previous SQL statement. + +**Syntax**: + +Get the error text: + +``` +GET DIAGNOSTICS EXCEPTION 1 var_name = MESSAGE_TEXT; +``` + +Get the number of rows associate with the previous SQL statement: + +``` +GET DIAGNOSTICS var_name = ROW_COUNT; +``` + +**Important Note:** + +- Hive does not support JDBC Statement.getUpdateCount() for INSERT statements, so GET DIAGNOSTICS ROW_COUNT will return 0 for Hive 0.13 and earlier and -1 for Hive 0.14 and later. See [HIVE-7680](https://issues.apache.org/jira/browse/HIVE-7680) for more details. + +**Compatibility:** IBM DB2 + +**Version**: PL/HQL 0.03 + +**See also:** +- [Error Handling]({{< ref "error-handling" >}}) +- [DECLARE HANDLER]({{< ref "declare-handler" >}}) +- [ACTIVITY_COUNT]({{< ref "activity_count" >}}) +- [SQLCODE]({{< ref "sqlcode" >}}) +- [SQLSTATE]({{< ref "sqlstate" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/host.md b/content/docs/latest/user/hive-hplsql/statements/host.md new file mode 100644 index 00000000..21468f87 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/host.md @@ -0,0 +1,53 @@ +--- +title: "Apache Hive : Execute OS Command or External Process" +date: 2026-08-12 +--- + +# Apache Hive : Execute OS Command or External Process + +PL/HQL allows you to execute an OS command or external process from a PL/HQL script: + +**Syntax**: + +! command: + +``` +!cmd [arguments]; +``` + +HOST statement: + +``` +HOST string_expr +``` + +**Parameters:** + +| **Parameter** | **Description** | +| --- | --- | +| cmd | Any OS command or process | +| arguments | Optional argument list | +| string_expr | Command line for HOST statement | + +**Notes**: + +- Blank characters are allowed between ! and cmd +- The ! command must be terminated by a semicolon (;) + +**Example:** + +Using ! command: + +``` +!echo Hello, world; +``` + +Using HOST statement: + +``` +HOST 'echo Hello, world'; +``` + +**Compatibility**: Apache Hive (! command), Oracle (HOST statement). + +**Version**: PL/HQL 0.01 diff --git a/content/docs/latest/user/hive-hplsql/statements/if.md b/content/docs/latest/user/hive-hplsql/statements/if.md new file mode 100644 index 00000000..e3224c01 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/if.md @@ -0,0 +1,76 @@ +--- +title: "Apache Hive : IF Statement - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : IF Statement - PL/HQL Reference + +IF statement executes a set of statements depending on the value of a boolean expression. + +PL/HQL supports multiple syntaxes for IF statement. + +## IF - THEN - ELSIF/ELSEIF - ELSE - END IF + +Syntax: + +``` +IF boolean_expression THEN + statements +[ELSIF | ELSEIF THEN + statements +...] +[ELSE + statements] +END IF; +``` + +**Example:** + +``` +IF state = 'CA' THEN + code := 1; +ELSIF state = 'NY' THEN + code := 2; +ELSIF state = 'MA' THEN + code := 3; +ELSE + code := 5; +END IF; +``` + +**Compatibility:** Oracle, Teradata, IBM DB2, MySQL, PostgreSQL, Netezza. + +## IF - BEGIN - END - ELSE - BEGIN - END + +Syntax: + +``` +IF boolean_expression + single_statement | block +[ELSE + single_statement | block]; +``` + +**Example:** + +``` +IF state = 'CA' + SET code = 1; +ELSE + SET code = 5; +``` + +``` +IF state = 'CA' +BEGIN + SET code = 1; + SET type = 'A'; +END +ELSE +BEGIN + SET code = 5; + SET type = 'B'; +END +``` + +**Compatibility:** Microsoft SQL Server. diff --git a/content/docs/latest/user/hive-hplsql/statements/include.md b/content/docs/latest/user/hive-hplsql/statements/include.md new file mode 100644 index 00000000..e1c3a3fc --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/include.md @@ -0,0 +1,55 @@ +--- +title: "Apache Hive : INCLUDE Statement" +date: 2026-08-12 +--- + +# Apache Hive : INCLUDE Statement + +INCLUDE statement allows you to include statements from another HPL/SQL script. + +You can define user-defined functions and stored procedures in separate HPL/SQL scripts and then use INCLUDE statements to make them available in the current script. + +Additionally you can put INCLUDE statements to [.hplsqlrc]({{< ref "configuration##hplsqlrc-file" >}}) configuration file, so these functions and procedures are always available to users similar to persistent objects in the database. + +**Syntax**: + +``` +INLCUDE file_name; +``` + +Notes: +- *file_name* is the path to the file (quoted or unquoted) or an expression + +**Example**: + +Create a separate file *set_message.sql* containing: + +``` +CREATE PROCEDURE set_message(IN name STRING, OUT result STRING) +BEGIN + SET result = 'Hello, ' || name || '!'; +END; +``` + +The call the procedure from another script as follows: + +``` +INCLUDE set_message.sql + +DECLARE str STRING; +CALL set_message('world', str); +PRINT str; + +Result: +-- +Hello, world! +``` + +**Compatibility:** HPL/SQL extension + +**Version**: PL/HQL 0.3.1 + +See also: +- [CALL]({{< ref "call" >}}) +- [CREATE FUNCTION]({{< ref "create-function" >}}) +- [CREATE PROCEDURE]({{< ref "create-procedure" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/insert-directory.md b/content/docs/latest/user/hive-hplsql/statements/insert-directory.md new file mode 100644 index 00000000..8e5e36d1 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/insert-directory.md @@ -0,0 +1,43 @@ +--- +title: "Apache Hive : INSERT DIRECTORY Statement" +date: 2026-08-12 +--- + +# Apache Hive : INSERT DIRECTORY Statement + +INSERT DIRECTORY statement allows you to write the query results to a local or HDFS-compatible file system. + +**Syntax**: + +``` +INSERT OVERWRITE [LOCAL] DIRECTORY directory select_statement +``` + +Notes: +- *directory* specifies the target directory (path, variable or expression) +- *select_statement* specifies the query (you can also use dynamic SQL string) + +**Examples:** + +Export sales data: + +``` +insert overwrite directory '/data/sales_daily' select * from sales_daily; +``` + +Export sales data from the specified table and put to the directory for the current date: + +``` +declare tabname string = 'sales_daily'; + +insert overwrite directory '/data/sales_' || current_date + 'select * from ' || tabname; +``` + +**Compatibility:** Hive + +**Version**: HPL/SQL 0.3.17 + +See also: +- [COPY]({{< ref "copy" >}}) +- [COPY FROM LOCAL]({{< ref "copy-from-local" >}}) diff --git a/content/docs/latest/user/hive-hplsql/statements/insert.md b/content/docs/latest/user/hive-hplsql/statements/insert.md new file mode 100644 index 00000000..750ee8ce --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/insert.md @@ -0,0 +1,69 @@ +--- +title: "Apache Hive : INSERT Statement" +date: 2026-08-12 +--- + +# Apache Hive : INSERT Statement + +INSERT statement inserts rows into a table. + +**Syntax**: + +Insert from SELECT: + +``` +INSERT OVERWRITE TABLE table_name select_statement +| +INSERT INTO [TABLE] table_name select_statement +``` + +Insert values: + +``` +INSERT INTO [TABLE] table_name VALUES (exrp, expr2, ...) [, (exrp, expr2, ...), ...] +``` + +## INSERT VALUES + +HPL/SQL provides you with two options to run INSERT VALUES statement: **native** and **select**. + +Use the [hplsql.insert.values]({{< ref "configuration#hplsqlinsertvalues" >}}) option to define how to handle INSERT VALUES statement, the default value is **native**. + +### Native INSERT VALUES + +If [hplsql.insert.values]({{< ref "configuration#hplsqlinsertvalues" >}}) is set to **native** HPL/SQL relies on the database that must support INSERT VALUES syntax. Note that INSERT VALUES is available in Hive since version 0.14 only and can only be performed on tables that support ACID. + +### Transform into INSERT SELECT + +If [hplsql.insert.values]({{< ref "configuration#hplsqlinsertvalues" >}}) is set to **select** HPL/SQL transforms VALUES clause to the list of SELECT FROM dual UNION ALL ... clauses. + +For example, if you execute the following INSERT statement: + +``` +INSERT INTO dept VALUES +(10, 'ACCOUNTING', 'NEW YORK'), +(20, 'RESEARCH', 'DALLAS'), +(30, 'SALES', 'CHICAGO'), +(40, 'OPERATIONS', 'BOSTON'); +``` + +HPL/SQL transforms it to: + +``` +INSERT INTO dept +SELECT 10, 'ACCOUNTING', 'NEW YORK' FROM default.dual +UNION ALL +SELECT 20, 'RESEARCH', 'DALLAS' FROM default.dual +UNION ALL +SELECT 30, 'SALES', 'CHICAGO' FROM default.dual +UNION ALL +SELECT 40, 'OPERATIONS', 'BOSTON' FROM default.dual; +``` + +You can specify the single row, single column dual table using [hplsql.dual.table]({{< ref "configuration#hplsqldualtable" >}}) option. + +**Important Note:** Such approach leads to creating one HDFS file **per** INSERT statement, and must not be used to insert large number of rows. + +**Compatibility:** Oracle, Microsoft SQL Server, IBM DB2, Teradata, PostgreSQL and MySQL + +**Version**: HPL/SQL 0.3 diff --git a/content/docs/latest/user/hive-hplsql/statements/leave.md b/content/docs/latest/user/hive-hplsql/statements/leave.md new file mode 100644 index 00000000..becb69e8 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/leave.md @@ -0,0 +1,38 @@ +--- +title: "Apache Hive : LEAVE Statement - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : LEAVE Statement - PL/HQL Reference + +LEAVE statement exits the loop or block marked by the given label. If the label is not specified, LEAVE exists the innermost loop. + +**Syntax:** + +``` +LEAVE [label]; +``` + +**Example:** + +``` +lbl: +WHILE count > 0 DO + SET count = count - 1; + IF count = 0 THEN + LEAVE lbl; + END IF; +END WHILE; +``` + +``` +lbl: +WHILE 1=1 DO + lbl1: + WHILE 1=1 DO + LEAVE lbl; + END WHILE; +END WHILE; +``` + +**Compatibility:** Teradata, IBM DB2 and MySQL. diff --git a/content/docs/latest/user/hive-hplsql/statements/loop.md b/content/docs/latest/user/hive-hplsql/statements/loop.md new file mode 100644 index 00000000..72c2e589 --- /dev/null +++ b/content/docs/latest/user/hive-hplsql/statements/loop.md @@ -0,0 +1,40 @@ +--- +title: "Apache Hive : LOOP Statement - PL/HQL Reference" +date: 2026-08-12 +--- + +# Apache Hive : LOOP Statement - PL/HQL Reference + +LOOP statement executes one or more statements until you exit the loop using EXIT, LEAVE or BREAK statements, or raising an exception. + +Syntax: + +``` +[<