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

Migrate Raptor to use BaseConnectorTest #11111

Merged
merged 3 commits into from
Feb 22, 2022
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 @@ -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;
Expand All @@ -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<DataMappingTestSetup> 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<DataMappingTestSetup> 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
Expand Down Expand Up @@ -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" +
hashhar marked this conversation as resolved.
Show resolved Hide resolved
"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
Expand Down Expand Up @@ -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" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down