Skip to content

Commit 6c044f4

Browse files
author
Jaeho Yoo
committed
Fix schema parsing fallthrough and Optional string formatting
1 parent 513a41e commit 6c044f4

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;
@@ -296,6 +297,7 @@ private void visitNode(Node node, ImmutableSet.Builder<QualifiedName> tableBuild
296297
case DropCatalog s -> catalogBuilder.add(s.getCatalogName().getValue());
297298
case DropSchema s -> setCatalogAndSchemaNameFromSchemaQualifiedName(Optional.of(s.getSchemaName()), catalogBuilder, schemaBuilder, catalogSchemaBuilder);
298299
case DropTable s -> tableBuilder.add(qualifyName(s.getTableName()));
300+
case Insert s -> tableBuilder.add(qualifyName(s.getTarget()));
299301
case Query q -> q.getWith().ifPresent(with -> temporaryTables.addAll(with.getQueries().stream().map(WithQuery::getName).map(Identifier::getValue).map(QualifiedName::of).toList()));
300302
case RenameMaterializedView s -> {
301303
tableBuilder.add(qualifyName(s.getSource()));
@@ -392,20 +394,23 @@ private void setCatalogAndSchemaNameFromSchemaQualifiedName(
392394
if (schemaOptional.isEmpty()) {
393395
schemaBuilder.add(defaultSchema.orElseThrow(this::unsetDefaultExceptionSupplier));
394396
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)));
396399
}
397400
else {
398401
QualifiedName schema = schemaOptional.orElseThrow();
399402
switch (schema.getParts().size()) {
400403
case 1 -> {
401404
schemaBuilder.add(schema.getParts().getFirst());
402405
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;
404408
}
405409
case 2 -> {
406410
schemaBuilder.add(schema.getParts().get(1));
407411
catalogBuilder.add(schema.getParts().getFirst());
408412
catalogSchemaBuilder.add(format("%s.%s", schema.getParts().getFirst(), schema.getParts().getLast()));
413+
break;
409414
}
410415
default -> log.error("Schema has >2 parts: %s", schema);
411416
}
@@ -499,7 +504,7 @@ private QualifiedName parseIdentifierStringToQualifiedName(String name)
499504
parts.add(new Identifier(name.substring(start, name.length() - 1)));
500505
}
501506
else {
502-
parts.add(new Identifier(name.substring(start, name.length())));
507+
parts.add(new Identifier(name.substring(start)));
503508
}
504509
return QualifiedName.of(parts);
505510
}

0 commit comments

Comments
 (0)