Skip to content

Add support for appending queries in sql based connectors #16308

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

Merged
merged 1 commit into from
Jun 26, 2023
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
2 changes: 2 additions & 0 deletions docs/src/main/sphinx/connector/clickhouse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ configured connector to create a catalog named ``sales``.

.. include:: jdbc-common-configurations.fragment

.. include:: query-comment-format.fragment

.. |default_domain_compaction_threshold| replace:: ``1000``
.. include:: jdbc-domain-compaction-threshold.fragment

Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/sphinx/connector/druid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ properties files.

.. include:: jdbc-common-configurations.fragment

.. include:: query-comment-format.fragment

.. |default_domain_compaction_threshold| replace:: ``32``
.. include:: jdbc-domain-compaction-threshold.fragment

Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/sphinx/connector/ignite.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ configured connector to create a catalog named ``sales``.

.. include:: jdbc-common-configurations.fragment

.. include:: query-comment-format.fragment

.. |default_domain_compaction_threshold| replace:: ``1000``
.. include:: jdbc-domain-compaction-threshold.fragment

Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/sphinx/connector/mysql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ creates a catalog named ``sales`` using the configured connector.

.. include:: jdbc-common-configurations.fragment

.. include:: query-comment-format.fragment

.. |default_domain_compaction_threshold| replace:: ``32``
.. include:: jdbc-domain-compaction-threshold.fragment

Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/sphinx/connector/oracle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ you name the property file ``sales.properties``, Trino creates a catalog named

.. include:: jdbc-common-configurations.fragment

.. include:: query-comment-format.fragment

.. |default_domain_compaction_threshold| replace:: ``32``
.. include:: jdbc-domain-compaction-threshold.fragment

Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/sphinx/connector/phoenix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Property name Required Description

.. include:: jdbc-common-configurations.fragment

.. include:: query-comment-format.fragment

.. |default_domain_compaction_threshold| replace:: ``5000``
.. include:: jdbc-domain-compaction-threshold.fragment

Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/sphinx/connector/postgresql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ catalog named ``sales`` using the configured connector.

.. include:: jdbc-common-configurations.fragment

.. include:: query-comment-format.fragment

.. |default_domain_compaction_threshold| replace:: ``32``
.. include:: jdbc-domain-compaction-threshold.fragment

Expand Down
50 changes: 50 additions & 0 deletions docs/src/main/sphinx/connector/query-comment-format.fragment
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Appending query metadata
^^^^^^^^^^^^^^^^^^^^^^^^

The optional parameter ``query.comment-format`` allows you to configure a SQL
comment that is sent to the datasource with each query. The format of this
comment can contain any characters and the following metadata:

* ``$QUERY_ID``: The identifier of the query.
* ``$USER``: The name of the user who submits the query to Trino.
* ``$SOURCE``: The identifier of the client tool used to submit the query, for
example ``trino-cli``.
* ``$TRACE_TOKEN``: The trace token configured with the client tool.

The comment can provide more context about the query. This additional
information is available in the logs of the datasource. To include environment
variables from the Trino cluster with the comment , use the
``${ENV:VARIABLE-NAME}`` syntax.

The following example sets a simple comment that identifies each query sent by
Trino:

.. code-block:: text

query.comment-format=Query sent by Trino.

With this configuration, a query such as ``SELECT * FROM example_table;`` is
sent to the datasource with the comment appended:

.. code-block:: text

SELECT * FROM example_table; /*Query sent by Trino.*/

The following example improves on the preceding example by using metadata:

.. code-block:: text

query.comment-format=Query $QUERY_ID sent by user $USER from Trino.

If ``Jane`` sent the query with the query identifier
``20230622_180528_00000_bkizg``, the following comment string is sent to the
datasource:

.. code-block:: text

SELECT * FROM example_table; /*Query 20230622_180528_00000_bkizg sent by user Jane from Trino.*/

.. note::

Certain JDBC driver settings and logging configurations might cause the
comment to be removed.
2 changes: 2 additions & 0 deletions docs/src/main/sphinx/connector/redshift.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ catalog named ``sales`` using the configured connector.

.. include:: jdbc-common-configurations.fragment

.. include:: query-comment-format.fragment

.. |default_domain_compaction_threshold| replace:: ``32``
.. include:: jdbc-domain-compaction-threshold.fragment

Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/sphinx/connector/singlestore.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ will create a catalog named ``sales`` using the configured connector.

.. include:: jdbc-common-configurations.fragment

.. include:: query-comment-format.fragment

.. |default_domain_compaction_threshold| replace:: ``32``
.. include:: jdbc-domain-compaction-threshold.fragment

Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/sphinx/connector/sqlserver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ catalog named ``sales`` using the configured connector.

.. include:: jdbc-common-configurations.fragment

.. include:: query-comment-format.fragment

.. |default_domain_compaction_threshold| replace:: ``32``
.. include:: jdbc-domain-compaction-threshold.fragment

Expand Down