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

Conversation

Jessie212
Copy link
Contributor

Description

Document added support for appending queries with context in sql based connectors.

Additional context and related issues

#14500

Release notes

(x) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Feb 28, 2023
@Jessie212 Jessie212 changed the title Add support for appending queries in sql based connectors (WIP) Add support for appending queries in sql based connectors Feb 28, 2023
@Jessie212
Copy link
Contributor Author

Hello, @s2lomon I need to document this feature and am hoping you can assist me. What must a user do to implement this?

@github-actions github-actions bot added the docs label Feb 28, 2023
@ebyhr
Copy link
Member

ebyhr commented Feb 28, 2023

cc: @kokosing @Praveen2112

@kokosing
Copy link
Member

kokosing commented Mar 1, 2023

@hashhar Can you please help here?

@hashhar
Copy link
Member

hashhar commented Mar 1, 2023

Ack, I'll share a short summary here later today.

@posulliv
Copy link
Contributor

posulliv commented Apr 6, 2023

@Jessie212 we've been using this in production so figured I would share my notes on it.

We have been using it with Oracle and SQLServer but any JDBC based connector supports it.

The config we are using in our catalog properties is:

query.comment-format=$QUERY_ID,$SOURCE,$USER

$QUERY_ID, $SOURCE, and $USER are replaced with the relevant values when the comment is appended to the SQL sent to the underlying data source.

You can specify any format for the query comment; we just chose to go with a comma-separated format.

There is also an ability to add a $TRACE_TOKEN but we are not using that at the moment.

@hashhar
Copy link
Member

hashhar commented Apr 6, 2023

To add some more context, if query.comment-format is set to a non-blank value (default is blank, i.e. this feature is disabled) then all occurrences of $QUERY_ID, $SOURCE, $USER and $TRACE_TOKEN in the query.comment-format are replaced with actual values and pre-pended to the query we send to remote database.

As example with query.comment-format=query_id: $QUERY_ID, source: $SOURCE, username: $USER, may your query succeed each query sent to remote database will look like:

/* query_id: <query_id>, source: <source>, username: <user>, may your query succeed */ <actual_query_sent_by_trino>

The goal is to allow admins to log query on the datasource so they can correlate which queries come from where and are part of which query id on Trino side.

@wendigo
Copy link
Contributor

wendigo commented Apr 6, 2023

Actually I believe that the comment is added at the end of the query @hashhar and there are no spaces between /* and */

@hashhar
Copy link
Member

hashhar commented Apr 7, 2023

oh yes, it gets appended to the end https://github.com/trinodb/trino/pull/14500/files#diff-45098b72713117f087df848fb61feb4d1b6a26e84113908efba191743d6f50aeR48

So <actual_query_sent_by_trino> /*query_id: <query_id>, source: <source>, username: <user>, may your query succeed*/ in the above example. Thanks for the correction.

@s2lomon
Copy link
Member

s2lomon commented Apr 7, 2023

I think that also it's good to mention, that since it's a standard Trino property, we can add env vars to the format, enriching the meta information about the requests.

@Jessie212 Jessie212 force-pushed the jt/appenders-sql-connectors branch from 161db88 to bbc114a Compare April 7, 2023 20:32
@Jessie212 Jessie212 requested a review from mosabua April 7, 2023 20:33
@Jessie212 Jessie212 changed the title (WIP) Add support for appending queries in sql based connectors Add support for appending queries in sql based connectors Apr 7, 2023
@Jessie212
Copy link
Contributor Author

I'm not sure we need this level of explanation or if examples are necessary, but that depends on where this content ends up.

@Jessie212 Jessie212 force-pushed the jt/appenders-sql-connectors branch from bbc114a to f9153da Compare April 11, 2023 17:20
@Jessie212 Jessie212 force-pushed the jt/appenders-sql-connectors branch from f9153da to eda0eab Compare April 21, 2023 14:56
@Jessie212
Copy link
Contributor Author

I've cautiously added the content as a fragment, and applied it to the SQL Server and Oracle connectors. I would like to know if it's safe to include this fragment to the rest of the JDBC connectors?

@kokosing
Copy link
Member

I would like to know if it's safe to include this fragment to the rest of the JDBC connectors?

That is tricky question. From point of view Trino the same code applies to all JDBC connectors. However it is vendor specific as this appendix can be removed either by vendor specific JDBC driver or logging of the query could lose it.

We can either add it to all and risk that some of them are actually not supported. Or safely document only those that we are sure that are supported. I would prefer the former.

@mosabua
Copy link
Member

mosabua commented Apr 21, 2023

I agree with @kokosing .. we should put the burden on the user and document them for all connectors where it applies with a warning that it might not work for the reasons he outlines. Users can then test and confirm. Also ... it might work in some scenarios with a connector and not work with the same connector in others..

@Jessie212 Jessie212 force-pushed the jt/appenders-sql-connectors branch from eda0eab to 85d9655 Compare April 24, 2023 20:51
@mosabua
Copy link
Member

mosabua commented May 11, 2023

Please reword or set up a meeting with me to collaborate @Jessie212

@hashhar hashhar mentioned this pull request May 16, 2023
@Jessie212 Jessie212 force-pushed the jt/appenders-sql-connectors branch 2 times, most recently from 411644c to 7f346ac Compare May 16, 2023 18:31
@mosabua
Copy link
Member

mosabua commented Jun 22, 2023

Please squash commits and improve commit message @Jessie212

@Jessie212 Jessie212 force-pushed the jt/appenders-sql-connectors branch 2 times, most recently from 78f4c87 to c1efdc8 Compare June 22, 2023 22:19
@Jessie212 Jessie212 force-pushed the jt/appenders-sql-connectors branch from c1efdc8 to f70dd0a Compare June 23, 2023 18:53
@m57lyra m57lyra requested a review from mosabua June 23, 2023 22:14
@Jessie212 Jessie212 force-pushed the jt/appenders-sql-connectors branch from f70dd0a to 5d658ed Compare June 26, 2023 20:38
@Jessie212 Jessie212 force-pushed the jt/appenders-sql-connectors branch from 5d658ed to 10b89ad Compare June 26, 2023 21:06
@mosabua mosabua merged commit 823942a into trinodb:master Jun 26, 2023
@github-actions github-actions bot added this to the 421 milestone Jun 26, 2023
@Jessie212 Jessie212 deleted the jt/appenders-sql-connectors branch June 26, 2023 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

8 participants