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

Small test cleanup around schemas #14771

Merged
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 @@ -216,7 +216,7 @@ public void testDropNonEmptySchemaWithTable()
}

try {
assertUpdate("CREATE SCHEMA " + schemaName);
assertUpdate(createSchemaSql(schemaName));
assertUpdate("CREATE TABLE " + schemaName + ".t(x int)");
assertQueryFails("DROP SCHEMA " + schemaName, ".*Cannot drop non-empty schema '\\Q" + schemaName + "\\E'");
}
Expand All @@ -239,7 +239,7 @@ public void testDropNonEmptySchemaWithView()
String schemaName = "test_drop_non_empty_schema_view_" + randomTableSuffix();

try {
assertUpdate("CREATE SCHEMA " + schemaName);
assertUpdate(createSchemaSql(schemaName));
assertUpdate("CREATE VIEW " + schemaName + ".v_t AS SELECT 123 x");

assertQueryFails("DROP SCHEMA " + schemaName, ".*Cannot drop non-empty schema '\\Q" + schemaName + "\\E'");
Expand All @@ -263,7 +263,7 @@ public void testDropNonEmptySchemaWithMaterializedView()
String schemaName = "test_drop_non_empty_schema_mv_" + randomTableSuffix();

try {
assertUpdate("CREATE SCHEMA " + schemaName);
assertUpdate(createSchemaSql(schemaName));
assertUpdate("CREATE MATERIALIZED VIEW " + schemaName + ".mv_t AS SELECT 123 x");

assertQueryFails("DROP SCHEMA " + schemaName, ".*Cannot drop non-empty schema '\\Q" + schemaName + "\\E'");
Expand Down Expand Up @@ -931,13 +931,16 @@ public void testMaterializedView()
return;
}

String otherSchema = "other_schema" + randomTableSuffix();
assertUpdate(createSchemaSql(otherSchema));

QualifiedObjectName view = new QualifiedObjectName(
getSession().getCatalog().orElseThrow(),
getSession().getSchema().orElseThrow(),
"test_materialized_view_" + randomTableSuffix());
QualifiedObjectName otherView = new QualifiedObjectName(
getSession().getCatalog().orElseThrow(),
"other_schema",
otherSchema,
"test_materialized_view_" + randomTableSuffix());
QualifiedObjectName viewWithComment = new QualifiedObjectName(
getSession().getCatalog().orElseThrow(),
Expand Down Expand Up @@ -1111,6 +1114,8 @@ public void testMaterializedView()
assertQueryReturnsEmptyResult(listMaterializedViewsSql("name = '" + view.getObjectName() + "'"));
assertQueryReturnsEmptyResult(listMaterializedViewsSql("name = '" + otherView.getObjectName() + "'"));
assertQueryReturnsEmptyResult(listMaterializedViewsSql("name = '" + viewWithComment.getObjectName() + "'"));

assertUpdate("DROP SCHEMA " + otherSchema);
}

@Test
Expand Down Expand Up @@ -1279,10 +1284,11 @@ public void testRenameMaterializedView()
{
skipTestUnless(hasBehavior(SUPPORTS_CREATE_MATERIALIZED_VIEW));

String schema = "rename_mv_test";
String schema = "rename_mv_test_" + randomTableSuffix();
Session session = Session.builder(getSession())
.setSchema(schema)
.build();
assertUpdate(createSchemaSql(schema));

QualifiedObjectName originalMaterializedView = new QualifiedObjectName(
session.getCatalog().orElseThrow(),
Expand Down Expand Up @@ -1316,8 +1322,8 @@ public void testRenameMaterializedView()
assertUpdate(session, "ALTER MATERIALIZED VIEW " + testExistsMaterializedViewName + " RENAME TO " + uppercaseName);
assertTestingMaterializedViewQuery(schema, uppercaseName.toLowerCase(ENGLISH)); // Ensure select allows for lower-case, not delimited identifier

String otherSchema = "rename_mv_other_schema";
assertUpdate(format("CREATE SCHEMA IF NOT EXISTS %s", otherSchema));
String otherSchema = "rename_mv_other_schema_" + randomTableSuffix();
assertUpdate(createSchemaSql(otherSchema));
if (hasBehavior(SUPPORTS_RENAME_MATERIALIZED_VIEW_ACROSS_SCHEMAS)) {
assertUpdate(session, "ALTER MATERIALIZED VIEW " + uppercaseName + " RENAME TO " + otherSchema + "." + originalMaterializedView.getObjectName());
assertTestingMaterializedViewQuery(otherSchema, originalMaterializedView.getObjectName());
Expand Down Expand Up @@ -1351,7 +1357,6 @@ private void assertTestingMaterializedViewQuery(String schema, String materializ

private void createTestingMaterializedView(QualifiedObjectName view, Optional<String> comment)
{
assertUpdate(format("CREATE SCHEMA IF NOT EXISTS %s", view.getSchemaName()));
assertUpdate(format(
"CREATE MATERIALIZED VIEW %s %s AS SELECT * FROM nation",
view,
Expand Down Expand Up @@ -1869,7 +1874,7 @@ public void testRenameSchema()

String schemaName = "test_rename_schema_" + randomTableSuffix();
try {
assertUpdate("CREATE SCHEMA " + schemaName);
assertUpdate(createSchemaSql(schemaName));
assertUpdate("ALTER SCHEMA " + schemaName + " RENAME TO " + schemaName + "_renamed");
assertThat(computeActual("SHOW SCHEMAS").getOnlyColumnAsSet()).contains(schemaName + "_renamed");
}
Expand Down Expand Up @@ -2129,7 +2134,7 @@ public void testCreateSchemaWithLongName()
.orElse(65536 + 5);

String validSchemaName = baseSchemaName + "z".repeat(maxLength - baseSchemaName.length());
assertUpdate("CREATE SCHEMA " + validSchemaName);
assertUpdate(createSchemaSql(validSchemaName));
assertThat(computeActual("SHOW SCHEMAS").getOnlyColumnAsSet()).contains(validSchemaName);
assertUpdate("DROP SCHEMA " + validSchemaName);

Expand All @@ -2138,7 +2143,7 @@ public void testCreateSchemaWithLongName()
}

String invalidSchemaName = validSchemaName + "z";
assertThatThrownBy(() -> assertUpdate("CREATE SCHEMA " + invalidSchemaName))
assertThatThrownBy(() -> assertUpdate(createSchemaSql(invalidSchemaName)))
.satisfies(this::verifySchemaNameLengthFailurePermissible);
assertThat(computeActual("SHOW SCHEMAS").getOnlyColumnAsSet()).doesNotContain(invalidSchemaName);
}
Expand All @@ -2148,8 +2153,8 @@ public void testRenameSchemaToLongName()
{
skipTestUnless(hasBehavior(SUPPORTS_RENAME_SCHEMA));

String sourceTableName = "test_rename_source_" + randomTableSuffix();
assertUpdate("CREATE SCHEMA " + sourceTableName);
String sourceSchemaName = "test_rename_source_" + randomTableSuffix();
assertUpdate(createSchemaSql(sourceSchemaName));

String baseSchemaName = "test_rename_target_" + randomTableSuffix();

Expand All @@ -2158,17 +2163,17 @@ public void testRenameSchemaToLongName()
.orElse(65536 + 5);

String validTargetSchemaName = baseSchemaName + "z".repeat(maxLength - baseSchemaName.length());
assertUpdate("ALTER SCHEMA " + sourceTableName + " RENAME TO " + validTargetSchemaName);
assertUpdate("ALTER SCHEMA " + sourceSchemaName + " RENAME TO " + validTargetSchemaName);
assertThat(computeActual("SHOW SCHEMAS").getOnlyColumnAsSet()).contains(validTargetSchemaName);
assertUpdate("DROP SCHEMA " + validTargetSchemaName);

if (maxSchemaNameLength().isEmpty()) {
return;
}

assertUpdate("CREATE SCHEMA " + sourceTableName);
assertUpdate(createSchemaSql(sourceSchemaName));
String invalidTargetSchemaName = validTargetSchemaName + "z";
assertThatThrownBy(() -> assertUpdate("ALTER SCHEMA " + sourceTableName + " RENAME TO " + invalidTargetSchemaName))
assertThatThrownBy(() -> assertUpdate("ALTER SCHEMA " + sourceSchemaName + " RENAME TO " + invalidTargetSchemaName))
.satisfies(this::verifySchemaNameLengthFailurePermissible);
assertThat(computeActual("SHOW SCHEMAS").getOnlyColumnAsSet()).doesNotContain(invalidTargetSchemaName);
}
Expand Down Expand Up @@ -2649,7 +2654,7 @@ public void testRenameTableAcrossSchema()
assertUpdate("CREATE TABLE " + tableName + " AS SELECT 123 x", 1);

String schemaName = "test_schema_" + randomTableSuffix();
assertUpdate("CREATE SCHEMA " + schemaName);
assertUpdate(createSchemaSql(schemaName));

String renamedTable = "test_rename_new_" + randomTableSuffix();
try {
Expand Down