Skip to content

Commit f903b28

Browse files
author
Jaeho Yoo
committed
Fix schema parsing fallthrough and Optional string formatting
1 parent 86d0e09 commit f903b28

File tree

2 files changed

+418
-3
lines changed

2 files changed

+418
-3
lines changed

gateway-ha/src/main/java/io/trino/gateway/ha/router/TrinoQueryProperties.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import io.trino.sql.tree.ExecuteImmediate;
4545
import io.trino.sql.tree.Expression;
4646
import io.trino.sql.tree.Identifier;
47+
import io.trino.sql.tree.Insert;
4748
import io.trino.sql.tree.Node;
4849
import io.trino.sql.tree.NodeLocation;
4950
import io.trino.sql.tree.QualifiedName;
@@ -362,6 +363,7 @@ private void visitNode(Node node, ImmutableSet.Builder<QualifiedName> tableBuild
362363
case DropCatalog s -> catalogBuilder.add(s.getCatalogName().getValue());
363364
case DropSchema s -> setCatalogAndSchemaNameFromSchemaQualifiedName(Optional.of(s.getSchemaName()), catalogBuilder, schemaBuilder, catalogSchemaBuilder);
364365
case DropTable s -> tableBuilder.add(qualifyName(s.getTableName()));
366+
case Insert s -> tableBuilder.add(qualifyName(s.getTarget()));
365367
case Query q -> q.getWith().ifPresent(with -> temporaryTables.addAll(with.getQueries().stream().map(WithQuery::getName).map(Identifier::getValue).map(QualifiedName::of).toList()));
366368
case RenameMaterializedView s -> {
367369
tableBuilder.add(qualifyName(s.getSource()));
@@ -458,20 +460,23 @@ private void setCatalogAndSchemaNameFromSchemaQualifiedName(
458460
if (schemaOptional.isEmpty()) {
459461
schemaBuilder.add(defaultSchema.orElseThrow(this::unsetDefaultExceptionSupplier));
460462
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)));
462465
}
463466
else {
464467
QualifiedName schema = schemaOptional.orElseThrow();
465468
switch (schema.getParts().size()) {
466469
case 1 -> {
467470
schemaBuilder.add(schema.getParts().getFirst());
468471
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;
470474
}
471475
case 2 -> {
472476
schemaBuilder.add(schema.getParts().get(1));
473477
catalogBuilder.add(schema.getParts().getFirst());
474478
catalogSchemaBuilder.add(format("%s.%s", schema.getParts().getFirst(), schema.getParts().getLast()));
479+
break;
475480
}
476481
default -> log.error("Schema has >2 parts: %s", schema);
477482
}
@@ -565,7 +570,7 @@ private QualifiedName parseIdentifierStringToQualifiedName(String name)
565570
parts.add(new Identifier(name.substring(start, name.length() - 1)));
566571
}
567572
else {
568-
parts.add(new Identifier(name.substring(start, name.length())));
573+
parts.add(new Identifier(name.substring(start)));
569574
}
570575
return QualifiedName.of(parts);
571576
}

0 commit comments

Comments
 (0)