Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document ALTER TABLE EXECUTE commands #9682

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/src/main/sphinx/connector/hive.rst
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,45 @@ features:

* :ref:`sql-security-operations`, see also :ref:`hive-sql-standard-based-authorization`

.. _hive-alter-table-execute:

ALTER TABLE EXECUTE
^^^^^^^^^^^^^^^^^^^

The connector supports the following commands for use with
:ref:`ALTER TABLE EXECUTE <alter-table-execute>`:

* ``optimize``: collapse files in transactional tables up to a threshold
defined in the ``file_size_threshold`` parameter. For example, the following
statement collapses files in a table that are under 10 megabytes in size:

.. code-block:: sql

ALTER TABLE test_table EXECUTE optimize(file_size_threshold => '10MB')

You can use a ``WHERE`` clause with the columns used to partition the table,
to filter which partitions are optimized.

The ``optimize`` procedure is disabled by default, and can be enabled for a
catalog with the ``<catalog-name>.non_transactional_optimize_enabled``
session property:

.. code-block:: sql

SET SESSION <catalog_name>.non_transactional_optimize_enabled=true

.. warning::

Because Hive tables are non-transactional, take note of the following possible
outcomes:

* If queries are run against tables that are currently being optimized,
duplicate rows may be read.
* In rare cases where exceptions occur during the ``optimize`` operation,
a manual cleanup of the table directory is needed. In this situation, refer
to the Trino logs and query failure messages to see which files need to be
deleted.

.. _hive-data-management:

Data management
Expand Down
17 changes: 17 additions & 0 deletions docs/src/main/sphinx/sql/alter-table.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Synopsis
ALTER TABLE [ IF EXISTS ] name RENAME COLUMN [ IF EXISTS ] old_name TO new_name
ALTER TABLE name SET AUTHORIZATION ( user | USER user | ROLE role )
ALTER TABLE SET PROPERTIES ( property_name = expression [, ...] )
ALTER TABLE name EXECUTE command [ ( parameter => expression [, ... ] ) ]
[ WHERE expression ]

Description
-----------
Expand All @@ -27,6 +29,16 @@ The optional ``IF EXISTS`` (when used before the column name) clause causes the

The optional ``IF NOT EXISTS`` clause causes the error to be suppressed if the column already exists.

.. _alter-table-execute:

EXECUTE
^^^^^^^

The ``ALTER TABLE EXECUTE`` statement followed by a ``command`` and
``parameters`` modifies the table according to the specified command and
parameters. ``ALTER TABLE EXECUTE`` supports different commands on a
per-connector basis.

Examples
--------

Expand Down Expand Up @@ -74,6 +86,11 @@ Set table properties (``x=y``) to table ``users``::

ALTER TABLE people SET PROPERTIES (x = 'y')

Collapse files in a table that are over 10 megabytes in size, as supported by
the Hive connector::

ALTER TABLE hive.schema.test_table EXECUTE optimize(file_size_threshold => `10MB`)

See also
--------

Expand Down