Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failure when creating a schema with non-lowercase username on Iceberg Glue catalog #16124

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,15 @@ public void testSchemaAuthorizationForRole()
assertUpdate(admin, "DROP ROLE authorized_users IN hive");
}

@Override
public void testCreateSchemaWithNonLowercaseOwnerName()
{
// Override because HivePrincipal's username is case-sensitive unlike TrinoPrincipal
assertThatThrownBy(super::testCreateSchemaWithNonLowercaseOwnerName)
.hasMessageContaining("Access Denied: Cannot create schema")
.hasStackTraceContaining("CREATE SCHEMA");
}

@Test
public void testCreateSchemaWithAuthorizationForUser()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,13 @@ public void testShowCreateTable()
" format = 'ORC'\n" +
")");
}

@Override
public void testCreateSchemaWithNonLowercaseOwnerName()
{
// Override because HivePrincipal's username is case-sensitive unlike TrinoPrincipal
assertThatThrownBy(super::testCreateSchemaWithNonLowercaseOwnerName)
.hasMessageContaining("Access Denied: Cannot create schema")
.hasStackTraceContaining("CREATE SCHEMA");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public Optional<TrinoPrincipal> getNamespacePrincipal(ConnectorSession session,
public void createNamespace(ConnectorSession session, String namespace, Map<String, Object> properties, TrinoPrincipal owner)
{
checkArgument(owner.getType() == PrincipalType.USER, "Owner type must be USER");
checkArgument(owner.getName().equals(session.getUser()), "Explicit schema owner is not supported");
checkArgument(owner.getName().equals(session.getUser().toLowerCase(ENGLISH)), "Explicit schema owner is not supported");

try {
stats.getCreateDatabase().call(() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public void testCreateSchema()
.hasMessage("Creating schema in Kudu connector not allowed if schema emulation is disabled.");
}

@Override
public void testCreateSchemaWithNonLowercaseOwnerName()
{
assertThatThrownBy(super::testCreateSchemaWithNonLowercaseOwnerName)
.hasMessage("Creating schema in Kudu connector not allowed if schema emulation is disabled.");
}

@Test
@Override
public void testRenameTableAcrossSchemas()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ public void testCreateSchema()
.hasMessage("Creating schema in Kudu connector not allowed if schema emulation is disabled.");
}

@Override
public void testCreateSchemaWithNonLowercaseOwnerName()
{
assertThatThrownBy(super::testCreateSchemaWithNonLowercaseOwnerName)
.hasMessage("Creating schema in Kudu connector not allowed if schema emulation is disabled.");
}

@Override
public void testCreateSchemaWithLongName()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package io.trino.testing;

import com.google.common.collect.ImmutableList;
import io.trino.Session;
import io.trino.spi.security.Identity;
import io.trino.testing.sql.TestTable;
import io.trino.tpch.TpchTable;
import org.testng.SkipException;
Expand Down Expand Up @@ -315,6 +317,22 @@ public void testCreateSchema()
assertUpdate("DROP SCHEMA " + schemaName);
}

@Test
public void testCreateSchemaWithNonLowercaseOwnerName()
{
skipTestUnless(hasBehavior(SUPPORTS_CREATE_SCHEMA));

Session newSession = Session.builder(getSession())
.setIdentity(Identity.ofUser("ADMIN"))
.build();
String schemaName = "test_schema_create_uppercase_owner_name_" + randomNameSuffix();
assertUpdate(newSession, createSchemaSql(schemaName));
assertThat(query(newSession, "SHOW SCHEMAS"))
.skippingTypesCheck()
.containsAll(format("VALUES '%s'", schemaName));
assertUpdate(newSession, "DROP SCHEMA " + schemaName);
}

@Test
public void testRenameSchema()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.trino.server.BasicQueryInfo;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.connector.MaterializedViewFreshness;
import io.trino.spi.security.Identity;
import io.trino.sql.planner.OptimizerConfig.JoinDistributionType;
import io.trino.sql.planner.Plan;
import io.trino.sql.planner.assertions.PlanMatchPattern;
Expand Down Expand Up @@ -2881,6 +2882,22 @@ public void testCreateTable()
assertFalse(getQueryRunner().tableExists(getSession(), tableNameLike));
}

@Test
public void testCreateSchemaWithNonLowercaseOwnerName()
{
skipTestUnless(hasBehavior(SUPPORTS_CREATE_SCHEMA));

Session newSession = Session.builder(getSession())
.setIdentity(Identity.ofUser("ADMIN"))
.build();
String schemaName = "test_schema_create_uppercase_owner_name_" + randomNameSuffix();
assertUpdate(newSession, createSchemaSql(schemaName));
assertThat(query(newSession, "SHOW SCHEMAS"))
.skippingTypesCheck()
.containsAll(format("VALUES '%s'", schemaName));
assertUpdate(newSession, "DROP SCHEMA " + schemaName);
}

@Test
public void testCreateSchemaWithLongName()
{
Expand Down