diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorIntegrationSmokeTest.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/BaseRaptorConnectorTest.java similarity index 91% rename from plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorIntegrationSmokeTest.java rename to plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/BaseRaptorConnectorTest.java index 3366f3ff68d4..ca82b34c9e74 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorIntegrationSmokeTest.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/BaseRaptorConnectorTest.java @@ -15,22 +15,23 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.SetMultimap; import io.trino.spi.type.ArrayType; -import io.trino.testing.AbstractTestIntegrationSmokeTest; +import io.trino.testing.BaseConnectorTest; import io.trino.testing.MaterializedResult; import io.trino.testing.MaterializedRow; -import io.trino.testing.QueryRunner; +import io.trino.testing.TestingConnectorBehavior; +import io.trino.testing.sql.TestTable; import io.trino.testng.services.Flaky; -import io.trino.tpch.TpchTable; import org.intellij.lang.annotations.Language; +import org.testng.SkipException; import org.testng.annotations.Test; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Collection; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.StringJoiner; import java.util.UUID; @@ -43,29 +44,106 @@ import static io.airlift.testing.Assertions.assertInstanceOf; import static io.airlift.testing.Assertions.assertLessThan; import static io.trino.plugin.raptor.legacy.RaptorColumnHandle.SHARD_UUID_COLUMN_TYPE; -import static io.trino.plugin.raptor.legacy.RaptorQueryRunner.createRaptorQueryRunner; import static io.trino.spi.type.BigintType.BIGINT; import static io.trino.spi.type.BooleanType.BOOLEAN; import static io.trino.spi.type.DateType.DATE; import static io.trino.spi.type.IntegerType.INTEGER; import static io.trino.spi.type.VarcharType.VARCHAR; +import static io.trino.testing.sql.TestTable.randomTableSuffix; import static java.lang.String.format; import static java.util.Arrays.asList; import static java.util.function.Function.identity; import static java.util.stream.Collectors.toSet; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotEquals; import static org.testng.Assert.assertNotNull; -public class TestRaptorIntegrationSmokeTest - // TODO extend BaseConnectorTest - extends AbstractTestIntegrationSmokeTest +public abstract class BaseRaptorConnectorTest + extends BaseConnectorTest { @Override - protected QueryRunner createQueryRunner() - throws Exception + protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) { - return createRaptorQueryRunner(ImmutableMap.of(), TpchTable.getTables(), false, ImmutableMap.of()); + switch (connectorBehavior) { + case SUPPORTS_DELETE: + case SUPPORTS_CREATE_VIEW: + return true; + case SUPPORTS_CREATE_SCHEMA: + case SUPPORTS_RENAME_SCHEMA: + case SUPPORTS_COMMENT_ON_TABLE: + case SUPPORTS_COMMENT_ON_COLUMN: + case SUPPORTS_NOT_NULL_CONSTRAINT: + case SUPPORTS_TOPN_PUSHDOWN: + return false; + default: + return super.hasBehavior(connectorBehavior); + } + } + + @Override + protected TestTable createTableWithDefaultColumns() + { + throw new SkipException("Raptor connector does not support column default values"); + } + + @Test + @Override + public void testCharVarcharComparison() + { + assertThatThrownBy(super::testCharVarcharComparison) + .hasMessage("No storage type for type: char(3)"); + } + + @Test + @Override + public void testRenameTableAcrossSchema() + { + // Raptor allows renaming to a schema it doesn't exist https://github.com/trinodb/trino/issues/11110 + String tableName = "test_rename_old_" + randomTableSuffix(); + assertUpdate("CREATE TABLE " + tableName + " AS SELECT 123 x", 1); + + String schemaName = "test_schema_" + randomTableSuffix(); + + String renamedTable = schemaName + ".test_rename_new_" + randomTableSuffix(); + assertUpdate("ALTER TABLE " + tableName + " RENAME TO " + renamedTable); + + assertFalse(getQueryRunner().tableExists(getSession(), tableName)); + assertQuery("SELECT x FROM " + renamedTable, "VALUES 123"); + + assertUpdate("DROP TABLE " + renamedTable); + + assertFalse(getQueryRunner().tableExists(getSession(), tableName)); + assertFalse(getQueryRunner().tableExists(getSession(), renamedTable)); + } + + @Override + protected Optional filterDataMappingSmokeTestData(DataMappingTestSetup dataMappingTestSetup) + { + String typeName = dataMappingTestSetup.getTrinoTypeName(); + if (typeName.equals("tinyint") + || typeName.equals("real") + || typeName.startsWith("decimal(") + || typeName.equals("time") + || typeName.equals("timestamp(3) with time zone") + || typeName.startsWith("char(")) { + //TODO this should either work or fail cleanly + return Optional.empty(); + } + + return Optional.of(dataMappingTestSetup); + } + + @Override + protected Optional filterCaseSensitiveDataMappingTestData(DataMappingTestSetup dataMappingTestSetup) + { + String typeName = dataMappingTestSetup.getTrinoTypeName(); + if (typeName.equals("char(1)")) { + //TODO this should either work or fail cleanly + return Optional.empty(); + } + return Optional.of(dataMappingTestSetup); } @Test @@ -305,12 +383,12 @@ public void testShardsSystemTable() "SELECT table_schema, table_name, sum(row_count)\n" + "FROM system.shards\n" + "WHERE table_schema = 'tpch'\n" + - " AND table_name IN ('orders', 'lineitem')\n" + + " AND table_name IN ('orders', 'region')\n" + "GROUP BY 1, 2", "" + "SELECT 'tpch', 'orders', (SELECT count(*) FROM orders)\n" + "UNION ALL\n" + - "SELECT 'tpch', 'lineitem', (SELECT count(*) FROM lineitem)"); + "SELECT 'tpch', 'region', (SELECT count(*) FROM region)"); } @Test @@ -671,12 +749,12 @@ public void testTableStatsSystemTable() "SELECT table_schema, table_name, sum(row_count)\n" + "FROM system.table_stats\n" + "WHERE table_schema = 'tpch'\n" + - " AND table_name IN ('orders', 'lineitem')\n" + + " AND table_name IN ('orders', 'region')\n" + "GROUP BY 1, 2", "" + "SELECT 'tpch', 'orders', (SELECT count(*) FROM orders)\n" + "UNION ALL\n" + - "SELECT 'tpch', 'lineitem', (SELECT count(*) FROM lineitem)"); + "SELECT 'tpch', 'region', (SELECT count(*) FROM region)"); assertQuery("" + "SELECT\n" + diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorIntegrationSmokeTestBucketed.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorBucketedConnectorTest.java similarity index 90% rename from plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorIntegrationSmokeTestBucketed.java rename to plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorBucketedConnectorTest.java index f5275fbc88fd..960bddfc3284 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorIntegrationSmokeTestBucketed.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorBucketedConnectorTest.java @@ -15,20 +15,19 @@ import com.google.common.collect.ImmutableMap; import io.trino.testing.QueryRunner; -import io.trino.tpch.TpchTable; import org.testng.annotations.Test; import static io.trino.plugin.raptor.legacy.RaptorQueryRunner.createRaptorQueryRunner; import static org.assertj.core.api.Assertions.assertThat; -public class TestRaptorIntegrationSmokeTestBucketed - extends TestRaptorIntegrationSmokeTest +public class TestRaptorBucketedConnectorTest + extends BaseRaptorConnectorTest { @Override protected QueryRunner createQueryRunner() throws Exception { - return createRaptorQueryRunner(ImmutableMap.of(), TpchTable.getTables(), true, ImmutableMap.of()); + return createRaptorQueryRunner(ImmutableMap.of(), REQUIRED_TPCH_TABLES, true, ImmutableMap.of()); } @Test diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorDistributedQueriesBucketed.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorConnectorTest.java similarity index 78% rename from plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorDistributedQueriesBucketed.java rename to plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorConnectorTest.java index e5b08ecec127..ce99a6be5ca7 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorDistributedQueriesBucketed.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorConnectorTest.java @@ -15,17 +15,16 @@ import com.google.common.collect.ImmutableMap; import io.trino.testing.QueryRunner; -import io.trino.tpch.TpchTable; import static io.trino.plugin.raptor.legacy.RaptorQueryRunner.createRaptorQueryRunner; -public class TestRaptorDistributedQueriesBucketed - extends TestRaptorDistributedQueries +public class TestRaptorConnectorTest + extends BaseRaptorConnectorTest { @Override protected QueryRunner createQueryRunner() throws Exception { - return createRaptorQueryRunner(ImmutableMap.of(), TpchTable.getTables(), true, ImmutableMap.of()); + return createRaptorQueryRunner(ImmutableMap.of(), REQUIRED_TPCH_TABLES, false, ImmutableMap.of()); } } diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorDistributedQueries.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorDistributedQueries.java deleted file mode 100644 index 44b819044f42..000000000000 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorDistributedQueries.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.trino.plugin.raptor.legacy; - -import com.google.common.collect.ImmutableMap; -import io.trino.testing.AbstractTestDistributedQueries; -import io.trino.testing.QueryRunner; -import io.trino.testing.sql.TestTable; -import org.testng.SkipException; - -import java.util.Optional; - -import static io.trino.plugin.raptor.legacy.RaptorQueryRunner.createRaptorQueryRunner; - -public class TestRaptorDistributedQueries - extends AbstractTestDistributedQueries -{ - @Override - protected QueryRunner createQueryRunner() - throws Exception - { - return createRaptorQueryRunner(ImmutableMap.of(), REQUIRED_TPCH_TABLES, false, ImmutableMap.of()); - } - - @Override - protected boolean supportsCreateSchema() - { - return false; - } - - @Override - protected boolean supportsCommentOnTable() - { - return false; - } - - @Override - protected boolean supportsCommentOnColumn() - { - return false; - } - - @Override - protected TestTable createTableWithDefaultColumns() - { - throw new SkipException("Raptor connector does not support column default values"); - } - - @Override - protected Optional filterDataMappingSmokeTestData(DataMappingTestSetup dataMappingTestSetup) - { - String typeName = dataMappingTestSetup.getTrinoTypeName(); - if (typeName.equals("tinyint") - || typeName.equals("real") - || typeName.startsWith("decimal(") - || typeName.equals("time") - || typeName.equals("timestamp(3) with time zone") - || typeName.startsWith("char(")) { - // TODO this should either work or fail cleanly - return Optional.empty(); - } - - return Optional.of(dataMappingTestSetup); - } - - @Override - protected Optional filterCaseSensitiveDataMappingTestData(DataMappingTestSetup dataMappingTestSetup) - { - String typeName = dataMappingTestSetup.getTrinoTypeName(); - if (typeName.equals("char(1)")) { - // TODO this should either work or fail cleanly - return Optional.empty(); - } - return Optional.of(dataMappingTestSetup); - } -} diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorIntegrationSmokeTestMySql.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorMySqlConnectorTest.java similarity index 95% rename from plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorIntegrationSmokeTestMySql.java rename to plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorMySqlConnectorTest.java index 7a7ed2ee6ff3..a574f05ce072 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorIntegrationSmokeTestMySql.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/TestRaptorMySqlConnectorTest.java @@ -17,7 +17,6 @@ import io.trino.plugin.tpch.TpchPlugin; import io.trino.testing.DistributedQueryRunner; import io.trino.testing.QueryRunner; -import io.trino.tpch.TpchTable; import org.testcontainers.containers.MySQLContainer; import org.testng.annotations.AfterClass; @@ -28,8 +27,8 @@ import static io.trino.plugin.raptor.legacy.RaptorQueryRunner.createSession; import static java.lang.String.format; -public class TestRaptorIntegrationSmokeTestMySql - extends TestRaptorIntegrationSmokeTest +public class TestRaptorMySqlConnectorTest + extends BaseRaptorConnectorTest { private MySQLContainer mysqlContainer; @@ -77,7 +76,7 @@ private static QueryRunner createRaptorMySqlQueryRunner(String mysqlUrl) queryRunner.createCatalog("raptor", "raptor-legacy", raptorProperties); - copyTables(queryRunner, "tpch", createSession(), false, TpchTable.getTables()); + copyTables(queryRunner, "tpch", createSession(), false, REQUIRED_TPCH_TABLES); return queryRunner; }