Skip to content

Commit

Permalink
Normalize name when dropping catalogs
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr authored and wendigo committed Jul 26, 2024
1 parent 2fdfb47 commit 1582e86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import static com.google.common.util.concurrent.Futures.immediateVoidFuture;
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;

public class DropCatalogTask
Expand Down Expand Up @@ -59,8 +60,9 @@ public ListenableFuture<Void> execute(
throw new TrinoException(NOT_SUPPORTED, "CASCADE is not yet supported for DROP SCHEMA");
}

accessControl.checkCanDropCatalog(stateMachine.getSession().toSecurityContext(), statement.getCatalogName().toString());
catalogManager.dropCatalog(new CatalogName(statement.getCatalogName().toString()), statement.isExists());
String catalogName = statement.getCatalogName().getValue().toLowerCase(ENGLISH);
accessControl.checkCanDropCatalog(stateMachine.getSession().toSecurityContext(), catalogName);
catalogManager.dropCatalog(new CatalogName(catalogName), statement.isExists());
return immediateVoidFuture();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static io.trino.execution.querystats.PlanOptimizersStatsCollector.createPlanOptimizersStatsCollector;
import static io.trino.testing.TestingSession.testSession;
import static java.util.Collections.emptyList;
import static java.util.Locale.ENGLISH;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_METHOD;
Expand Down Expand Up @@ -98,6 +99,17 @@ public void testDuplicatedCreateCatalogIfNotExists()
assertThat(queryRunner.getPlannerContext().getMetadata().catalogExists(createNewQuery().getSession(), TEST_CATALOG)).isFalse();
}

@Test
void testCaseInsensitiveDropCatalog()
{
queryRunner.createCatalog(TEST_CATALOG, "tpch", ImmutableMap.of());
assertThat(queryRunner.getPlannerContext().getMetadata().catalogExists(createNewQuery().getSession(), TEST_CATALOG)).isTrue();

DropCatalog statement = new DropCatalog(new Identifier(TEST_CATALOG.toUpperCase(ENGLISH)), false, false);
getFutureValue(task.execute(statement, createNewQuery(), emptyList(), WarningCollector.NOOP));
assertThat(queryRunner.getPlannerContext().getMetadata().catalogExists(createNewQuery().getSession(), TEST_CATALOG)).isFalse();
}

private QueryStateMachine createNewQuery()
{
return QueryStateMachine.begin(
Expand Down

0 comments on commit 1582e86

Please sign in to comment.