-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
SQL: Fix catalog filtering in SYS COLUMNS #40583
Conversation
Properly treat '%' as a wildcard for catalog filtering instead of doing a straight string match. Fix elastic#40582
Pinging @elastic/es-search |
Add integration test for SYS COLUMNS - currently running only inside single_node since the cluster name is test dependent.
I have updated the PR to fix also alias filtering which was not performed (only the index name was considered). Also added a test suite since mocking doesn't really work for this case. |
@@ -215,6 +216,8 @@ private Throwable reworkException(Throwable th) { | |||
|
|||
@SuppressForbidden(reason = "test reads from jar") | |||
public static InputStream readFromJarUrl(URL source) throws IOException { | |||
return source.openStream(); | |||
URLConnection con = source.openConnection(); | |||
con.setDefaultUseCaches(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment why this is necessary?
boolean matchesAlias = false; | ||
if (pattern != null && aliasMetadata != null) { | ||
for (AliasMetaData aliasMeta : aliasMetadata) { | ||
matchesAlias |= pattern.matcher(aliasMeta.alias()).matches(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we exit on first occurrence of true?
public static List<Object[]> readScriptSpec() throws Exception { | ||
List<Object[]> list = new ArrayList<>(); | ||
list.addAll(CsvSpecTestCase.readScriptSpec()); | ||
return readScriptSpec("/disabled/command-sys.csv-spec", specParser()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like disabled
in the path here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
for the drivers) Move away from separateMappings() since in case of aliases pointing to multiple indices, it can return duplicated entries (as there's no merging) causing issues. Hence why mergedMapping is used instead with the assumption that only one table will be used at a time. A more correct (yet quite expensive) alternative would be to return the mapping per index yet in case of aliases, drop it and use field caps instead. However as this is not CCS-friendly, using field_caps instead seems a good solution for now.
Fix monotony of ORDINAL_POSITION
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added two comments, but am not 100% sure I am right about those.
|
||
TABLE_CAT:s | TABLE_SCHEM:s| TABLE_NAME:s | COLUMN_NAME:s | DATA_TYPE:i | TYPE_NAME:s | COLUMN_SIZE:i| BUFFER_LENGTH:i|DECIMAL_DIGITS:i|NUM_PREC_RADIX:i | NULLABLE:i| REMARKS:s | COLUMN_DEF:s |SQL_DATA_TYPE:i|SQL_DATETIME_SUB:i|CHAR_OCTET_LENGTH:i|ORDINAL_POSITION:i|IS_NULLABLE:s|SCOPE_CATALOG:s|SCOPE_SCHEMA:s|SCOPE_TABLE:s|SOURCE_DATA_TYPE:sh|IS_AUTOINCREMENT:s|IS_GENERATEDCOLUMN:s | ||
---------------+---------------+---------------+--------------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+----------------+-----------------+----------------+---------------+---------------+---------------+---------------+----------------+----------------+------------------ | ||
x-pack_plugin_sql_qa_single-node_integTestCluster |null |test\_emp |birth_date |93 |DATETIME |24 |8 |null |null |1 |null |null |9 |3 |null |1 |YES |null |null |null |null |NO |NO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may miss something, but is it ok for this to return `test\_emp' (including the escaped character)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bug - the test\_emp
is escaped so the name should be test_emp
.
sysColumnsWithTableLikeNoEscape | ||
SYS COLUMNS TABLE LIKE 'test_emp'; | ||
|
||
// since there's no escaping test_emp means test*emp which matches also test_alias_emp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_emp
should match test
[one character]emp
when there is no escape character, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately due to the current field caps features, we can't figure out the source index.
Gave the branch a try and if nothing was mistaken during the process:
|
Update after consulting with @costin:
This (=empty result set) is correct, since the catalog argument
This is currently a known limitation; however, it should have no practical impact, since the applications ask for the columns of specific table. |
Properly treat '%' as a wildcard for catalog filtering instead of doing a straight string match. Table filtering now considers aliases as well. Add escaping char for LIKE queries with user defined params Fix monotony of ORDINAL_POSITION Add integration test for SYS COLUMNS - currently running only inside single_node since the cluster name is test dependent. Add pattern unescaping for index names Fix #40582 (cherry picked from commit 8e61b77)
Properly treat '%' as a wildcard for catalog filtering instead of doing a straight string match. Table filtering now considers aliases as well. Add escaping char for LIKE queries with user defined params Fix monotony of ORDINAL_POSITION Add integration test for SYS COLUMNS - currently running only inside single_node since the cluster name is test dependent. Add pattern unescaping for index names Fix #40582 (cherry picked from commit 8e61b77)
Properly treat '%' as a wildcard for catalog filtering instead of doing a straight string match. Table filtering now considers aliases as well. Add escaping char for LIKE queries with user defined params Fix monotony of ORDINAL_POSITION Add integration test for SYS COLUMNS - currently running only inside single_node since the cluster name is test dependent. Add pattern unescaping for index names Fix #40582 (cherry picked from commit 8e61b77)
Properly treat '%' as a wildcard for catalog filtering instead of doing a straight string match. Table filtering now considers aliases as well. Add escaping char for LIKE queries with user defined params Fix monotony of ORDINAL_POSITION Add integration test for SYS COLUMNS - currently running only inside single_node since the cluster name is test dependent. Add pattern unescaping for index names Fix elastic#40582
Properly treat '%' as a wildcard for catalog filtering instead of doing
a straight string match.
Fix #40582