-
Notifications
You must be signed in to change notification settings - Fork 67
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
Exclude with statement names from tables #532
Conversation
@@ -194,13 +196,25 @@ else if (statement instanceof ExecuteImmediate executeImmediate) { | |||
|
|||
queryType = statement.getClass().getSimpleName(); | |||
resourceGroupQueryType = StatementUtils.getQueryType(statement).toString(); | |||
ImmutableSet.Builder<QualifiedName> tableBuilder = ImmutableSet.builder(); | |||
List<QualifiedName> allQUalifiedNames = new ArrayList<>(); |
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.
Why did you change to ArrayList? #Also, the new name has a typo. U
should be a lowercase.
private void getNames(Node node, ImmutableSet.Builder<QualifiedName> tableBuilder, | ||
private void getNames( | ||
Node node, | ||
List<QualifiedName> allQualifiedNames, |
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 understand the difference between tableBuilder
and allQualifiedNames
. What's the motivation of this renaming?
WITH dos (c1) as (select c1 from uno), | ||
uno(c1) as (select c1 from cat.schem.tbl1) | ||
SELECT c1 from uno, dos |
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.
Uppercase as, select, from.
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 think this is valid SQL. You cannot use uno as it is defined after dos.
WITH dos (c1) as (select c1 from uno), | |
uno(c1) as (select c1 from cat.schem.tbl1) | |
SELECT c1 from uno, dos | |
WITH dos AS (SELECT c1 from cat.schem.tbl1), | |
uno as (SELECT c1 FROM dos) | |
SELECT c1 FROM uno, dos |
you can test this in trino via simple sql
// works fine
WITH dos AS (SELECT node_id FROM system.runtime.nodes),
uno AS (SELECT node_id as node_id2 FROM dos)
SELECT node_id, node_id2
FROM uno, dos
// doesn't work as uno is not defined before dos.
// Query 20241023_021715_04215_f8xaz failed: line 1:34: Table 'system.runtime.uno' does not exist
WITH dos AS (SELECT node_id FROM uno),
uno AS (SELECT node_id as node_id2 FROM system.runtime.nodes)
SELECT node_id, node_id2
FROM uno, dos
assertThat(trinoQueryPropertiesWithDefaults.tablesContains(String.format("%s.%s.%s", DEFAULT_CATALOG, DEFAULT_SCHEMA, "uno"))).isFalse(); | ||
assertThat(trinoQueryPropertiesWithDefaults.tablesContains(String.format("%s.%s.%s", DEFAULT_CATALOG, DEFAULT_SCHEMA, "does"))).isFalse(); |
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.
Static import format
method. https://github.com/trinodb/trino/blob/master/.github/DEVELOPMENT.md#prefer-string-formatting
when(mockRequestNoDefaults.getReader()).thenReturn(bufferedReader); | ||
|
||
TrinoQueryProperties trinoQueryPropertiesNoDefaults = new TrinoQueryProperties(mockRequestNoDefaults, requestAnalyzerConfig); | ||
assertThat(trinoQueryPropertiesNoDefaults.getTables().size()).isEqualTo(1); |
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.
AssertJ provides hasSize
method.
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.
do you consider temporary tables (with clause) as non-tables?
This overlaps with #531 ... |
case SetViewAuthorization s -> allQualifiedNames.add(s.getSource()); | ||
case Table s -> allQualifiedNames.add(s.getName()); | ||
case TableFunctionInvocation s -> allQualifiedNames.add(s.getName()); | ||
case WithQuery withQuery -> withQueryNamesBuilder.add(withQuery.getName()); |
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.
didn't know you could do this directly, i thought withQuery comes with Query.
closing for #531 |
Description
Exclude with statement names from the list of tables extracted from SQL by
TrinoQueryProperties
Additional context and related issues
The existing TrinoQueryProperties will include WITH statement names in the list of tables. For example, for the query
the tables list will be
{"c.s.t", "arbitrary_name"}
, or, if default catalog and schema are not specified, processing of the SQL will fail whenTrinoQueryPoperties
attempts to qualifyarbitrary_name
with a catalog and schema.Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text: