Skip to content

Commit

Permalink
Test DROP SCHEMA with non-empty schema
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Jul 23, 2021
1 parent 491dae0 commit 8abdbca
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static io.trino.testing.assertions.Assert.assertEquals;
import static io.trino.testing.sql.TestTable.randomTableSuffix;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

Expand Down Expand Up @@ -80,6 +81,15 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
}
}

@Override
public void testDropNonEmptySchema()
{
assertThatThrownBy(super::testDropNonEmptySchema)
.isInstanceOf(AssertionError.class)
.hasMessageStartingWith("Expected query to fail: DROP SCHEMA ");
throw new SkipException("DROP SCHEMA erases all tables in ClickHouse connector"); // TODO (https://github.com/trinodb/trino/issues/8634)
}

@Override
@Test(dataProvider = "testColumnNameDataProvider")
public void testColumnName(String columnName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ public void testInsertUnicode()
throw new SkipException("TODO");
}

@Override
public void testDropNonEmptySchema()
{
// TODO Support these test once kudu connector can create tables with default partitions
throw new SkipException("TODO");
}

@Override
public void testDelete()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static java.util.stream.Collectors.joining;
import static java.util.stream.IntStream.range;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

Expand Down Expand Up @@ -160,6 +161,15 @@ public void testInsertUnicode()
throw new SkipException("MemSQL doesn't support utf8mb4");
}

@Override
public void testDropNonEmptySchema()
{
assertThatThrownBy(super::testDropNonEmptySchema)
.isInstanceOf(AssertionError.class)
.hasMessageStartingWith("Expected query to fail: DROP SCHEMA ");
throw new SkipException("DROP SCHEMA erases all tables in MemSQL connector"); // TODO (https://github.com/trinodb/trino/issues/8634)
}

@Test
public void testDropTable()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.trino.testing.TestingConnectorBehavior;
import io.trino.testing.sql.TestTable;
import org.intellij.lang.annotations.Language;
import org.testng.SkipException;
import org.testng.annotations.Test;

import java.util.Optional;
Expand All @@ -33,6 +34,7 @@
import static io.trino.testing.assertions.Assert.assertEquals;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

Expand Down Expand Up @@ -178,6 +180,15 @@ public void testShowCreateTable()
")");
}

@Override
public void testDropNonEmptySchema()
{
assertThatThrownBy(super::testDropNonEmptySchema)
.isInstanceOf(AssertionError.class)
.hasMessageStartingWith("Expected query to fail: DROP SCHEMA ");
throw new SkipException("DROP SCHEMA erases all tables in MySQL connector"); // TODO (https://github.com/trinodb/trino/issues/8634)
}

@Test
public void testDropTable()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ protected boolean supportsCreateSchema()
return true;
}

private boolean supportsDropSchema()
{
// A connector either supports CREATE SCHEMA and DROP SCHEMA or none of them.
return supportsCreateSchema();
}

protected boolean supportsCreateTable()
{
return true;
Expand Down Expand Up @@ -1126,6 +1132,26 @@ public void testCreateSchema()
assertQueryFails("DROP SCHEMA " + schemaName, format("line 1:1: Schema '.*\\.%s' does not exist", schemaName));
}

@Test
public void testDropNonEmptySchema()
{
if (!supportsCreateSchema()) {
assertQueryFails("DROP SCHEMA " + getSession().getSchema().orElseThrow(), "This connector does not support dropping schemas");
return;
}

String schemaName = "test_drop_non_empty_schema_" + randomTableSuffix();
assertUpdate("CREATE SCHEMA " + schemaName);
assertUpdate("CREATE TABLE " + schemaName + ".t(x int)");
assertQueryFails("DROP SCHEMA " + schemaName, "(?si).*" +
"(Schema not empty|" +
"Cannot drop schema|" +
"schema has (\\w+ )?tables|" +
"Cannot drop .{0,3}\\Q" + schemaName + "\\E).*");
assertUpdate("DROP TABLE " + schemaName + ".t");
assertUpdate("DROP SCHEMA " + schemaName);
}

@Test
public void testInsertForDefaultColumn()
{
Expand Down

0 comments on commit 8abdbca

Please sign in to comment.