5959import io .trino .sql .tree .Statement ;
6060import io .trino .sql .tree .Table ;
6161import io .trino .sql .tree .TableFunctionInvocation ;
62+ import io .trino .sql .tree .WithQuery ;
6263import jakarta .servlet .http .HttpServletRequest ;
6364import jakarta .ws .rs .HttpMethod ;
6465
6869import java .util .ArrayList ;
6970import java .util .Arrays ;
7071import java .util .Enumeration ;
72+ import java .util .HashSet ;
7173import java .util .List ;
7274import java .util .Map ;
7375import java .util .Optional ;
7476import java .util .Set ;
7577import java .util .stream .Collectors ;
7678
79+ import static com .google .common .collect .ImmutableSet .toImmutableSet ;
7780import static com .google .common .io .BaseEncoding .base64Url ;
7881import static io .airlift .json .JsonCodec .jsonCodec ;
7982import static java .lang .Math .toIntExact ;
@@ -90,6 +93,7 @@ public class TrinoQueryProperties
9093 private String queryType = "" ;
9194 private String resourceGroupQueryType = "" ;
9295 private Set <QualifiedName > tables = ImmutableSet .of ();
96+ private final Set <QualifiedName > temporaryTables = new HashSet <>();
9397 private final Optional <String > defaultCatalog ;
9498 private final Optional <String > defaultSchema ;
9599 private Set <String > catalogs = ImmutableSet .of ();
@@ -201,12 +205,17 @@ else if (statement instanceof ExecuteImmediate executeImmediate) {
201205
202206 getNames (statement , tableBuilder , catalogBuilder , schemaBuilder , catalogSchemaBuilder );
203207 tables = tableBuilder .build ();
204- catalogBuilder .addAll (tables .stream ().map (q -> q .getParts ().getFirst ()).iterator ());
208+
209+ Set <QualifiedName > filteredTables = tables .stream ()
210+ .filter (table -> !temporaryTables .contains (table ))
211+ .collect (toImmutableSet ());
212+
213+ catalogBuilder .addAll (filteredTables .stream ().map (q -> q .getParts ().getFirst ()).iterator ());
205214 catalogs = catalogBuilder .build ();
206- schemaBuilder .addAll (tables .stream ().map (q -> q .getParts ().get (1 )).iterator ());
215+ schemaBuilder .addAll (filteredTables .stream ().map (q -> q .getParts ().get (1 )).iterator ());
207216 schemas = schemaBuilder .build ();
208217 catalogSchemaBuilder .addAll (
209- tables .stream ().map (qualifiedName -> format ("%s.%s" , qualifiedName .getParts ().getFirst (), qualifiedName .getParts ().get (1 ))).iterator ());
218+ filteredTables .stream ().map (qualifiedName -> format ("%s.%s" , qualifiedName .getParts ().getFirst (), qualifiedName .getParts ().get (1 ))).iterator ());
210219 catalogSchemas = catalogSchemaBuilder .build ();
211220 }
212221 catch (IOException e ) {
@@ -336,8 +345,14 @@ private void getNames(Node node, ImmutableSet.Builder<QualifiedName> tableBuilde
336345 case SetSchemaAuthorization s -> setCatalogAndSchemaNameFromSchemaQualifiedName (Optional .of (s .getSource ()), catalogBuilder , schemaBuilder , catalogSchemaBuilder );
337346 case SetTableAuthorization s -> tableBuilder .add (qualifyName (s .getSource ()));
338347 case SetViewAuthorization s -> tableBuilder .add (qualifyName (s .getSource ()));
339- case Table s -> tableBuilder .add (qualifyName (s .getName ()));
348+ case Table s -> {
349+ // ignore temporary tables as they can have various table parts
350+ if (!temporaryTables .contains (s .getName ())) {
351+ tableBuilder .add (qualifyName (s .getName ()));
352+ }
353+ }
340354 case TableFunctionInvocation s -> tableBuilder .add (qualifyName (s .getName ()));
355+ case WithQuery withQuery -> temporaryTables .add (QualifiedName .of (withQuery .getName ().getValue ()));
341356 default -> {}
342357 }
343358
0 commit comments