|
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; |
@@ -362,6 +363,7 @@ private void visitNode(Node node, ImmutableSet.Builder<QualifiedName> tableBuild |
362 | 363 | case DropCatalog s -> catalogBuilder.add(s.getCatalogName().getValue()); |
363 | 364 | case DropSchema s -> setCatalogAndSchemaNameFromSchemaQualifiedName(Optional.of(s.getSchemaName()), catalogBuilder, schemaBuilder, catalogSchemaBuilder); |
364 | 365 | case DropTable s -> tableBuilder.add(qualifyName(s.getTableName())); |
| 366 | + case Insert s -> tableBuilder.add(qualifyName(s.getTarget())); |
365 | 367 | case Query q -> q.getWith().ifPresent(with -> temporaryTables.addAll(with.getQueries().stream().map(WithQuery::getName).map(Identifier::getValue).map(QualifiedName::of).toList())); |
366 | 368 | case RenameMaterializedView s -> { |
367 | 369 | tableBuilder.add(qualifyName(s.getSource())); |
@@ -458,20 +460,23 @@ private void setCatalogAndSchemaNameFromSchemaQualifiedName( |
458 | 460 | if (schemaOptional.isEmpty()) { |
459 | 461 | schemaBuilder.add(defaultSchema.orElseThrow(this::unsetDefaultExceptionSupplier)); |
460 | 462 | catalogBuilder.add(defaultCatalog.orElseThrow(this::unsetDefaultExceptionSupplier)); |
461 | | - catalogSchemaBuilder.add(format("%s.%s", defaultCatalog, defaultSchema)); |
| 463 | + catalogSchemaBuilder.add(format("%s.%s", defaultCatalog.orElseThrow(this::unsetDefaultExceptionSupplier), |
| 464 | + defaultSchema.orElseThrow(this::unsetDefaultExceptionSupplier))); |
462 | 465 | } |
463 | 466 | else { |
464 | 467 | QualifiedName schema = schemaOptional.orElseThrow(); |
465 | 468 | switch (schema.getParts().size()) { |
466 | 469 | case 1 -> { |
467 | 470 | schemaBuilder.add(schema.getParts().getFirst()); |
468 | 471 | catalogBuilder.add(defaultCatalog.orElseThrow(this::unsetDefaultExceptionSupplier)); |
469 | | - catalogSchemaBuilder.add(format("%s.%s", defaultCatalog, schema.getParts().getFirst())); |
| 472 | + catalogSchemaBuilder.add(format("%s.%s", defaultCatalog.orElseThrow(this::unsetDefaultExceptionSupplier), schema.getParts().getFirst())); |
| 473 | + break; |
470 | 474 | } |
471 | 475 | case 2 -> { |
472 | 476 | schemaBuilder.add(schema.getParts().get(1)); |
473 | 477 | catalogBuilder.add(schema.getParts().getFirst()); |
474 | 478 | catalogSchemaBuilder.add(format("%s.%s", schema.getParts().getFirst(), schema.getParts().getLast())); |
| 479 | + break; |
475 | 480 | } |
476 | 481 | default -> log.error("Schema has >2 parts: %s", schema); |
477 | 482 | } |
@@ -565,7 +570,7 @@ private QualifiedName parseIdentifierStringToQualifiedName(String name) |
565 | 570 | parts.add(new Identifier(name.substring(start, name.length() - 1))); |
566 | 571 | } |
567 | 572 | else { |
568 | | - parts.add(new Identifier(name.substring(start, name.length()))); |
| 573 | + parts.add(new Identifier(name.substring(start))); |
569 | 574 | } |
570 | 575 | return QualifiedName.of(parts); |
571 | 576 | } |
|
0 commit comments