Skip to content

Commit

Permalink
Inline supports method in BaseConnectorTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Feb 28, 2022
1 parent 8322116 commit c53ee94
Showing 1 changed file with 33 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,93 +112,6 @@
public abstract class BaseConnectorTest
extends AbstractTestQueries
{
/**
* @deprecated Use {@link #hasBehavior(TestingConnectorBehavior)} instead.
*/
@Deprecated
protected final boolean supportsCreateSchema()
{
return hasBehavior(SUPPORTS_CREATE_SCHEMA);
}

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

/**
* @deprecated Use {@link #hasBehavior(TestingConnectorBehavior)} instead.
*/
@Deprecated
protected final boolean supportsCreateTable()
{
return hasBehavior(SUPPORTS_CREATE_TABLE);
}

/**
* @deprecated Use {@link #hasBehavior(TestingConnectorBehavior)} instead.
*/
@Deprecated
protected final boolean supportsInsert()
{
return hasBehavior(SUPPORTS_INSERT);
}

/**
* @deprecated Use {@link #hasBehavior(TestingConnectorBehavior)} instead.
*/
@Deprecated
protected final boolean supportsDelete()
{
return hasBehavior(SUPPORTS_DELETE);
}

/**
* @deprecated Use {@link #hasBehavior(TestingConnectorBehavior)} instead.
*/
@Deprecated
protected final boolean supportsViews()
{
return hasBehavior(SUPPORTS_CREATE_VIEW);
}

/**
* @deprecated Use {@link #hasBehavior(TestingConnectorBehavior)} instead.
*/
@Deprecated
protected final boolean supportsArrays()
{
return hasBehavior(SUPPORTS_ARRAY);
}

/**
* @deprecated Use {@link #hasBehavior(TestingConnectorBehavior)} instead.
*/
@Deprecated
protected final boolean supportsCommentOnTable()
{
return hasBehavior(SUPPORTS_COMMENT_ON_TABLE);
}

/**
* @deprecated Use {@link #hasBehavior(TestingConnectorBehavior)} instead.
*/
@Deprecated
protected final boolean supportsCommentOnColumn()
{
return hasBehavior(SUPPORTS_COMMENT_ON_COLUMN);
}

/**
* @deprecated Use {@link #hasBehavior(TestingConnectorBehavior)} instead.
*/
@Deprecated
protected boolean supportsRenameTable()
{
return hasBehavior(SUPPORTS_RENAME_TABLE);
}

protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
return connectorBehavior.hasBehaviorByDefault(this::hasBehavior);
Expand Down Expand Up @@ -236,7 +149,7 @@ public void testShowCreateSchema()
public void testCreateSchema()
{
String schemaName = "test_schema_create_" + randomTableSuffix();
if (!supportsCreateSchema()) {
if (!hasBehavior(SUPPORTS_CREATE_SCHEMA)) {
assertQueryFails("CREATE SCHEMA " + schemaName, "This connector does not support creating schemas");
return;
}
Expand Down Expand Up @@ -264,7 +177,8 @@ public void testCreateSchema()
public void testDropNonEmptySchema()
{
String schemaName = "test_drop_non_empty_schema_" + randomTableSuffix();
if (!supportsDropSchema()) {
// A connector either supports CREATE SCHEMA and DROP SCHEMA or none of them.
if (!hasBehavior(SUPPORTS_CREATE_SCHEMA)) {
return;
}

Expand Down Expand Up @@ -596,7 +510,7 @@ public void testDescribeTable()
@Test
public void testView()
{
if (!supportsViews()) {
if (!hasBehavior(SUPPORTS_CREATE_VIEW)) {
assertQueryFails("CREATE VIEW nation_v AS SELECT * FROM nation", "This connector does not support creating views");
return;
}
Expand Down Expand Up @@ -749,7 +663,7 @@ public void testView()
@Test
public void testViewCaseSensitivity()
{
skipTestUnless(supportsViews());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_VIEW));

String upperCaseView = "test_view_uppercase_" + randomTableSuffix();
String mixedCaseView = "test_view_mixedcase_" + randomTableSuffix();
Expand Down Expand Up @@ -957,7 +871,7 @@ public void testMaterializedView()
@Test
public void testCompatibleTypeChangeForView()
{
skipTestUnless(supportsViews());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_VIEW));

String tableName = "test_table_" + randomTableSuffix();
String viewName = "test_view_" + randomTableSuffix();
Expand All @@ -980,7 +894,7 @@ public void testCompatibleTypeChangeForView()
@Test
public void testCompatibleTypeChangeForView2()
{
skipTestUnless(supportsViews());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_VIEW));

String tableName = "test_table_" + randomTableSuffix();
String viewName = "test_view_" + randomTableSuffix();
Expand All @@ -1003,7 +917,7 @@ public void testCompatibleTypeChangeForView2()
@Test(dataProvider = "testViewMetadataDataProvider")
public void testViewMetadata(String securityClauseInCreate, String securityClauseInShowCreate)
{
skipTestUnless(supportsViews());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_VIEW));

String viewName = "meta_test_view_" + randomTableSuffix();

Expand Down Expand Up @@ -1090,7 +1004,7 @@ public static Object[][] testViewMetadataDataProvider()
@Test
public void testShowCreateView()
{
skipTestUnless(supportsViews());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_VIEW));
checkState(getSession().getCatalog().isPresent(), "catalog is not set");
checkState(getSession().getSchema().isPresent(), "schema is not set");

Expand Down Expand Up @@ -1579,7 +1493,7 @@ public void testAddColumn()
return;
}

skipTestUnless(supportsCreateTable());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE));

String tableName;
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_add_column_", "AS SELECT VARCHAR 'first' x")) {
Expand Down Expand Up @@ -1622,7 +1536,7 @@ public void testDropColumn()
return;
}

skipTestUnless(supportsCreateTable());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE));

String tableName;
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_drop_column_", "AS SELECT 123 x, 456 y, 111 a")) {
Expand Down Expand Up @@ -1650,7 +1564,7 @@ public void testRenameColumn()
return;
}

skipTestUnless(supportsCreateTable());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE));

String tableName;
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_rename_column_", "AS SELECT 'some value' x")) {
Expand Down Expand Up @@ -1684,7 +1598,7 @@ public void testRenameColumn()
public void testCreateTable()
{
String tableName = "test_create_" + randomTableSuffix();
if (!supportsCreateTable()) {
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
assertQueryFails("CREATE TABLE " + tableName + " (a bigint, b double, c varchar(50))", "This connector does not support creating tables");
return;
}
Expand Down Expand Up @@ -1734,7 +1648,7 @@ public void testCreateTable()
public void testCreateTableAsSelect()
{
String tableName = "test_ctas" + randomTableSuffix();
if (!supportsCreateTable()) {
if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
assertQueryFails("CREATE TABLE IF NOT EXISTS " + tableName + " AS SELECT name, regionkey FROM nation", "This connector does not support creating tables with data");
return;
}
Expand Down Expand Up @@ -1805,7 +1719,7 @@ public void testCreateTableAsSelect()
public void testCreateTableAsSelectWithUnicode()
{
// Covered by testCreateTableAsSelect
skipTestUnless(supportsCreateTable());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE));
assertCreateTableAsSelect(
"SELECT '\u2603' unicode",
"SELECT 1");
Expand Down Expand Up @@ -1864,12 +1778,12 @@ protected String errorMessageForCreateTableAsSelectNegativeDate(String date)
@Test
public void testRenameTable()
{
skipTestUnless(supportsCreateTable());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE));
String tableName = "test_rename_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT 123 x", 1);

String renamedTable = "test_rename_new_" + randomTableSuffix();
if (!supportsRenameTable()) {
if (!hasBehavior(SUPPORTS_RENAME_TABLE)) {
assertQueryFails("ALTER TABLE " + tableName + " RENAME TO " + renamedTable, "This connector does not support renaming tables");
return;
}
Expand Down Expand Up @@ -1900,7 +1814,7 @@ public void testRenameTable()
@Test
public void testCommentTable()
{
if (!supportsCommentOnTable()) {
if (!hasBehavior(SUPPORTS_COMMENT_ON_TABLE)) {
assertQueryFails("COMMENT ON TABLE nation IS 'new comment'", "This connector does not support setting table comments");
return;
}
Expand Down Expand Up @@ -1959,7 +1873,7 @@ private String getTableComment(String tableName)
@Test
public void testCommentColumn()
{
if (!supportsCommentOnColumn()) {
if (!hasBehavior(SUPPORTS_COMMENT_ON_COLUMN)) {
assertQueryFails("COMMENT ON COLUMN nation.nationkey IS 'new comment'", "This connector does not support setting column comments");
return;
}
Expand Down Expand Up @@ -2004,7 +1918,7 @@ private String getColumnComment(String tableName, String columnName)
@Test
public void testInsert()
{
if (!supportsInsert()) {
if (!hasBehavior(SUPPORTS_INSERT)) {
assertQueryFails("INSERT INTO nation(nationkey) VALUES (42)", "This connector does not support inserts");
return;
}
Expand Down Expand Up @@ -2047,7 +1961,7 @@ public void testInsert()
@Test
public void testInsertForDefaultColumn()
{
skipTestUnless(supportsInsert());
skipTestUnless(hasBehavior(SUPPORTS_INSERT));

try (TestTable testTable = createTableWithDefaultColumns()) {
assertUpdate(format("INSERT INTO %s (col_required, col_required2) VALUES (1, 10)", testTable.getName()), 1);
Expand All @@ -2067,7 +1981,7 @@ protected TestTable createTableWithDefaultColumns()
@Test
public void testInsertUnicode()
{
skipTestUnless(supportsInsert());
skipTestUnless(hasBehavior(SUPPORTS_INSERT));

try (TestTable table = new TestTable(getQueryRunner()::execute, "test_insert_unicode_", "(test varchar(50))")) {
assertUpdate("INSERT INTO " + table.getName() + "(test) VALUES 'Hello', U&'hello\\6d4B\\8Bd5world\\7F16\\7801' ", 2);
Expand Down Expand Up @@ -2097,7 +2011,7 @@ public void testInsertUnicode()
@Test
public void testInsertHighestUnicodeCharacter()
{
skipTestUnless(supportsInsert());
skipTestUnless(hasBehavior(SUPPORTS_INSERT));

try (TestTable table = new TestTable(getQueryRunner()::execute, "test_insert_unicode_", "(test varchar(50))")) {
assertUpdate("INSERT INTO " + table.getName() + "(test) VALUES 'Hello', U&'hello\\6d4B\\8Bd5\\+10FFFFworld\\7F16\\7801' ", 2);
Expand All @@ -2109,10 +2023,10 @@ public void testInsertHighestUnicodeCharacter()
@Test
public void testInsertArray()
{
skipTestUnless(supportsInsert());
skipTestUnless(hasBehavior(SUPPORTS_INSERT));

String tableName = "test_insert_array_" + randomTableSuffix();
if (!supportsArrays()) {
if (!hasBehavior(SUPPORTS_ARRAY)) {
assertThatThrownBy(() -> query("CREATE TABLE " + tableName + " (a array(bigint))"))
// TODO Unify failure message across connectors
.hasMessageMatching("[Uu]nsupported (column )?type: \\Qarray(bigint)");
Expand Down Expand Up @@ -2337,9 +2251,9 @@ public void testDeleteWithVarcharPredicate()

protected void skipTestUnlessSupportsDeletes()
{
skipTestUnless(supportsCreateTable());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE));
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_supports_delete", "(col varchar(1))")) {
if (!supportsDelete()) {
if (!hasBehavior(SUPPORTS_DELETE)) {
assertQueryFails("DELETE FROM " + table.getName(), "This connector does not support deletes");
throw new SkipException("This connector does not support deletes");
}
Expand Down Expand Up @@ -2513,7 +2427,7 @@ public void testTruncateTable()
@Test
public void testQueryLoggingCount()
{
skipTestUnless(supportsCreateTable());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE));

QueryManager queryManager = getDistributedQueryRunner().getCoordinator().getQueryManager();
executeExclusively(() -> {
Expand Down Expand Up @@ -2583,7 +2497,7 @@ public void testShowSchemasFromOther()
@Test
public void testSymbolAliasing()
{
skipTestUnless(supportsCreateTable());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE));

String tableName = "test_symbol_aliasing" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT 1 foo_1, 2 foo_2_4", 1);
Expand All @@ -2594,8 +2508,8 @@ public void testSymbolAliasing()
@Test
public void testWrittenStats()
{
skipTestUnless(supportsCreateTable());
skipTestUnless(supportsInsert());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE));
skipTestUnless(hasBehavior(SUPPORTS_INSERT));

String tableName = "test_written_stats_" + randomTableSuffix();
try {
Expand Down Expand Up @@ -2623,7 +2537,7 @@ public void testWrittenStats()
@Test(dataProvider = "testColumnNameDataProvider")
public void testColumnName(String columnName)
{
skipTestUnless(supportsCreateTable());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE));

if (!requiresDelimiting(columnName)) {
testColumnName(columnName, false);
Expand Down Expand Up @@ -2732,7 +2646,7 @@ public void testDataMappingSmokeTest(DataMappingTestSetup dataMappingTestSetup)

private void testDataMapping(DataMappingTestSetup dataMappingTestSetup)
{
skipTestUnless(supportsCreateTable());
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE));

String trinoTypeName = dataMappingTestSetup.getTrinoTypeName();
String sampleValueLiteral = dataMappingTestSetup.getSampleValueLiteral();
Expand Down

0 comments on commit c53ee94

Please sign in to comment.