|
44 | 44 | import io.trino.sql.tree.ExecuteImmediate; |
45 | 45 | import io.trino.sql.tree.Expression; |
46 | 46 | import io.trino.sql.tree.Identifier; |
| 47 | +import io.trino.sql.tree.Insert; |
47 | 48 | import io.trino.sql.tree.Node; |
48 | 49 | import io.trino.sql.tree.NodeLocation; |
49 | 50 | import io.trino.sql.tree.QualifiedName; |
@@ -296,6 +297,7 @@ private void visitNode(Node node, ImmutableSet.Builder<QualifiedName> tableBuild |
296 | 297 | case DropCatalog s -> catalogBuilder.add(s.getCatalogName().getValue()); |
297 | 298 | case DropSchema s -> setCatalogAndSchemaNameFromSchemaQualifiedName(Optional.of(s.getSchemaName()), catalogBuilder, schemaBuilder, catalogSchemaBuilder); |
298 | 299 | case DropTable s -> tableBuilder.add(qualifyName(s.getTableName())); |
| 300 | + case Insert s -> tableBuilder.add(qualifyName(s.getTarget())); |
299 | 301 | case Query q -> q.getWith().ifPresent(with -> temporaryTables.addAll(with.getQueries().stream().map(WithQuery::getName).map(Identifier::getValue).map(QualifiedName::of).toList())); |
300 | 302 | case RenameMaterializedView s -> { |
301 | 303 | tableBuilder.add(qualifyName(s.getSource())); |
@@ -392,20 +394,23 @@ private void setCatalogAndSchemaNameFromSchemaQualifiedName( |
392 | 394 | if (schemaOptional.isEmpty()) { |
393 | 395 | schemaBuilder.add(defaultSchema.orElseThrow(this::unsetDefaultExceptionSupplier)); |
394 | 396 | catalogBuilder.add(defaultCatalog.orElseThrow(this::unsetDefaultExceptionSupplier)); |
395 | | - catalogSchemaBuilder.add(format("%s.%s", defaultCatalog, defaultSchema)); |
| 397 | + catalogSchemaBuilder.add(format("%s.%s", defaultCatalog.orElseThrow(this::unsetDefaultExceptionSupplier), |
| 398 | + defaultSchema.orElseThrow(this::unsetDefaultExceptionSupplier))); |
396 | 399 | } |
397 | 400 | else { |
398 | 401 | QualifiedName schema = schemaOptional.orElseThrow(); |
399 | 402 | switch (schema.getParts().size()) { |
400 | 403 | case 1 -> { |
401 | 404 | schemaBuilder.add(schema.getParts().getFirst()); |
402 | 405 | catalogBuilder.add(defaultCatalog.orElseThrow(this::unsetDefaultExceptionSupplier)); |
403 | | - catalogSchemaBuilder.add(format("%s.%s", defaultCatalog, schema.getParts().getFirst())); |
| 406 | + catalogSchemaBuilder.add(format("%s.%s", defaultCatalog.orElseThrow(this::unsetDefaultExceptionSupplier), schema.getParts().getFirst())); |
| 407 | + break; |
404 | 408 | } |
405 | 409 | case 2 -> { |
406 | 410 | schemaBuilder.add(schema.getParts().get(1)); |
407 | 411 | catalogBuilder.add(schema.getParts().getFirst()); |
408 | 412 | catalogSchemaBuilder.add(format("%s.%s", schema.getParts().getFirst(), schema.getParts().getLast())); |
| 413 | + break; |
409 | 414 | } |
410 | 415 | default -> log.error("Schema has >2 parts: %s", schema); |
411 | 416 | } |
@@ -499,7 +504,7 @@ private QualifiedName parseIdentifierStringToQualifiedName(String name) |
499 | 504 | parts.add(new Identifier(name.substring(start, name.length() - 1))); |
500 | 505 | } |
501 | 506 | else { |
502 | | - parts.add(new Identifier(name.substring(start, name.length()))); |
| 507 | + parts.add(new Identifier(name.substring(start))); |
503 | 508 | } |
504 | 509 | return QualifiedName.of(parts); |
505 | 510 | } |
|
0 commit comments