Skip to content

Add compatibility with misbehaving client applications#7438

Merged
findepi merged 4 commits intotrinodb:masterfrom
findepi:findepi/literal-jdbc-metadata
Mar 30, 2021
Merged

Add compatibility with misbehaving client applications#7438
findepi merged 4 commits intotrinodb:masterfrom
findepi:findepi/literal-jdbc-metadata

Conversation

@findepi
Copy link
Member

@findepi findepi commented Mar 26, 2021

Number of DatabaseMetaData methods accept name patterns (e.g.
schemaPattern, tableNamePattern, columnNamePattern, etc.). Values
provided, if ought to be treated as literals, should have underscores
_ and percent signs % escaped with
DatabaseMetaData.getSearchStringEscape(). Sadly, many client
applications do not do that, which results in metadata queries which
cannot be answered efficiently by the server.

This commit adds a compatibility flag as a workaround for such
misbehaving client applications.

Closes #7424

@findepi findepi added enhancement New feature or request jdbc Relates to Trino JDBC driver labels Mar 26, 2021
@cla-bot cla-bot bot added the cla-signed label Mar 26, 2021
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given fact we have no test for new functionality we will only notice this verify fails on deployed Trino, if constant value changes. A simple unit test for this method would help.

Copy link
Member

@losipiuk losipiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THx. LGTM. One comment.

Copy link
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some tests when this property is set it is expected that table_name won't match tableXname.

It is dangerous flag and it has to be well documented that it is due buggy BI tools, and it may cause incorrect results. I think that property name has to be more scary: workaroudNonEscapedLiteralsInMetadataCalls?

@findepi
Copy link
Member Author

findepi commented Mar 27, 2021

It is dangerous flag and it has to be well documented that it is due buggy BI tools, and it may cause incorrect results. I think that property name has to be more scary: workaroudNonEscapedLiteralsInMetadataCalls?

i agree we need a good name for this property.
I proposed assumeLiteralNamesInMetadataCalls but i am not very attached to this.

@losipiuk @electrum @martint @alexjo2144 thoughts?

@losipiuk
Copy link
Member

It is dangerous flag and it has to be well documented that it is due buggy BI tools, and it may cause incorrect results. I think that property name has to be more scary: workaroudNonEscapedLiteralsInMetadataCalls?

i agree we need a good name for this property.
I proposed assumeLiteralNamesInMetadataCalls but i am not very attached to this.

@losipiuk @electrum @martint @alexjo2144 thoughts?

assumeLiteralNamesInMetadataCallsForBuggyClients?

@findepi
Copy link
Member Author

findepi commented Mar 29, 2021

assumeLiteralNamesInMetadataCallsForBuggyClients

Buggy -> NonConforming

@findepi
Copy link
Member Author

findepi commented Mar 29, 2021

Let's have an agreement for the general approach, and the name (in comments) and will update the code for merge separately.
I don't want to back and forth with the name within PR, as it's in multiple places.

@willmostly
Copy link
Contributor

Thanks for the work @findepi ! We've encountered a significant amount of pain due to improper escaping over the years. Its unfortunate that Trino has to compensate for improper behavior by clients, but the current situation has not been particularly effective at incentivizing Tableau, et al., to change their behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably deserves a comment describing what the intent is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex replace needs some unit testing too, be wary of this from the docs:

"Note that backslashes () and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences as described above, and backslashes are used to escape literal characters in the replacement string"

@alexjo2144
Copy link
Member

alexjo2144 commented Mar 29, 2021

Maybe something like rewriteIncorrectlyEscapedMetadataPatterns?

@findepi
Copy link
Member Author

findepi commented Mar 29, 2021

@losipiuk @kokosing @electrum what do you think about the approach in general?

for the name, i see these proposals

  • assumeLiteralNamesInMetadataCalls
  • assumeLiteralNamesInMetadataCallsForBuggyClients
  • assumeLiteralNamesInMetadataCallsForNonConformingClients
  • rewriteIncorrectlyEscapedMetadataPatterns

the assumeLiteralNamesInMetadataCallsForNonConformingClients is current my preferred, but i am open to other suggestions

Copy link
Member

@losipiuk losipiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT % naming decision and test nice to have

@losipiuk
Copy link
Member

As for the naming from options above I think assumeLiteralNamesInMetadataCallsForNonConformingClients is the best. Slightly long, but maybe that is a good thing if we want the option to be scary :)

@kokosing
Copy link
Member

assumeLiteralNamesInMetadataCallsForNonConformingClients 👍

@findepi
Copy link
Member Author

findepi commented Mar 30, 2021

Seems like we have agreement. I am changing to assumeLiteralNamesInMetadataCallsForNonConformingClients then and adding tests.
Thank you!

findepi added 3 commits March 30, 2021 10:53
Before the change, each invocation of `assertMetadataCalls` opened a new
connection, even though the test setup provides one.
@findepi findepi force-pushed the findepi/literal-jdbc-metadata branch from e9578a2 to 7bdb0b2 Compare March 30, 2021 09:26
@findepi
Copy link
Member Author

findepi commented Mar 30, 2021

Renamed the flag, added tests, both unit for escaping and end-to-end, fixing the bug spotted by @alexjo2144 .
Will merge when green.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot parse this comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// no matches in getTables call as table name pattern treated as literal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this return something else if assumeLiteralNamesInMetadataCallsForNonConformingClients was not passed?
Or in other words. Is there some other schema which matches test_schema1 (e.g testXschema1)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, but it would result in a different number of metadata calls.

note however the test_schema_ test case which seems what you're looking for.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense

Number of `DatabaseMetaData` methods accept name patterns (e.g.
`schemaPattern`, `tableNamePattern`, `columnNamePattern`, etc.). Values
provided, if ought to be treated as literals, should have underscores
`_` and percent signs `%` escaped with
`DatabaseMetaData.getSearchStringEscape()`. Sadly, many client
applications do not do that, which results in metadata queries which
cannot be answered efficiently by the server.

This commit adds
`assumeLiteralNamesInMetadataCallsForNonConformingClients`, a
compatibility flag as a workaround for such misbehaving client
applications.
@findepi findepi force-pushed the findepi/literal-jdbc-metadata branch from 7bdb0b2 to 69778e1 Compare March 30, 2021 09:43
@findepi findepi merged commit 266e001 into trinodb:master Mar 30, 2021
@findepi findepi added this to the 355 milestone Mar 30, 2021
@findepi findepi deleted the findepi/literal-jdbc-metadata branch March 30, 2021 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed enhancement New feature or request jdbc Relates to Trino JDBC driver

Development

Successfully merging this pull request may close these issues.

Wrong statement to retreive metadata from HMS ? (LIKE instead of =)

5 participants