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

Fix bug when querying system.jdbc.tables #4965

Conversation

skrzypo987
Copy link
Member

Making where constraints upper-case caused exception

@@ -36,7 +38,7 @@ private FilterUtil() {}
}

Object value = domain.getSingleValue();
return Optional.of(((Slice) value).toStringUtf8());
return Optional.of(((Slice) value).toStringUtf8().toLowerCase(ENGLISH));
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct. This method is not dedicated to table/column names, so should not lower case.
Even if it was dedicated, lowercasing would be misleading. (a non-lowercase expected value never matches, when lowercased will)

Copy link
Member Author

Choose a reason for hiding this comment

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

You are faster than GHA.
Fixed - moved lowercasing to a different place.

@skrzypo987 skrzypo987 force-pushed the bugfix-upper-case-list-tables-filter branch from e527598 to 72db624 Compare August 25, 2020 10:34
@@ -81,8 +82,8 @@ public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, Connect
{
Session session = ((FullConnectorSession) connectorSession).getSession();
Optional<String> catalogFilter = tryGetSingleVarcharValue(constraint, 0);
Optional<String> schemaFilter = tryGetSingleVarcharValue(constraint, 1);
Optional<String> tableFilter = tryGetSingleVarcharValue(constraint, 2);
Optional<String> schemaFilter = tryGetSingleVarcharValue(constraint, 1).map(filter -> filter.toLowerCase(ENGLISH));
Copy link
Member

Choose a reason for hiding this comment

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

Can we instead fix the check in the other place to allow non lower cased values? This seems invalid to me to manipulate values given in sql literals.

@skrzypo987 skrzypo987 force-pushed the bugfix-upper-case-list-tables-filter branch from 72db624 to a9f6f79 Compare August 26, 2020 09:58
@skrzypo987
Copy link
Member Author

Upper case predicate in where will now always return empty values.
@kokosing @findepi please take a look

Builder table = InMemoryRecordSet.builder(METADATA);
if (!isLowerCase(schemaFilter) || !isLowerCase(tableFilter)) {
// Uppercase predicate will never match a lowercase name
return table.build().cursor();
Copy link
Member

Choose a reason for hiding this comment

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

This is something to be removed in #17

If we place the logic closer to where it's needed (eg when QualifiedTablePrefix is constructed), then

  • it would be more obvious why the check matters
  • it would be easier to track it down and remove when doing above issue

@kokosing
Copy link
Member

Please check automation failures.

{
assertThat(queryRunner.execute("SELECT * FROM system.jdbc.tables WHERE TABLE_SCHEM = 'upper_case_schema' AND TABLE_NAME = 'upper_case_table'"))
.hasSize(1);
assertThat(queryRunner.execute("SELECT * FROM system.jdbc.tables WHERE TABLE_SCHEM = 'UPPER_CASE_SCHEMA'"))
Copy link
Member

Choose a reason for hiding this comment

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

Once #17 got fixed it should return actually tables from UPPER_CASE_SCHEMA. Please add a comment and link to the #17 issue.

@skrzypo987 skrzypo987 force-pushed the bugfix-upper-case-list-tables-filter branch from a9f6f79 to 2c1737f Compare August 27, 2020 06:32
Making where constraints upper-case caused exception
Copy link
Member

@findepi findepi left a comment

Choose a reason for hiding this comment

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

Code LGTM, but I would sprinkle it with "TODO" to make the intent and code's contemporary applicability more clear.

kokosing and others added 5 commits September 2, 2020 12:22
…ger.java

Co-authored-by: Piotr Findeisen <piotr.findeisen@gmail.com>
…ger.java

Co-authored-by: Piotr Findeisen <piotr.findeisen@gmail.com>
…ableJdbcTable.java

Co-authored-by: Piotr Findeisen <piotr.findeisen@gmail.com>
…ableJdbcTable.java

Co-authored-by: Piotr Findeisen <piotr.findeisen@gmail.com>
…ger.java

Co-authored-by: Piotr Findeisen <piotr.findeisen@gmail.com>
@kokosing
Copy link
Member

kokosing commented Sep 2, 2020

Merged as: c336e9a

@kokosing kokosing closed this Sep 2, 2020
@kokosing
Copy link
Member

kokosing commented Sep 2, 2020

Thanks!

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.

4 participants