Search in sources :

Example 21 with TestTable

use of io.trino.testing.sql.TestTable in project trino by trinodb.

the class TestMySqlLegacyConnectorTest method testCountDistinctWithStringTypes.

@Test
@Override
public void testCountDistinctWithStringTypes() {
    // Create a table with CHARACTER SET utf8mb4 option in MySQL side to insert unicode values
    List<String> rows = Stream.of("a", "b", "A", "B", " a ", "a", "b", " b ", "ą").map(value -> format("'%1$s', '%1$s'", value)).collect(toImmutableList());
    try (TestTable testTable = new TestTable(onRemoteDatabase(), "tpch.distinct_strings", "(t_char CHAR(5), t_varchar VARCHAR(5) CHARACTER SET utf8mb4)", rows)) {
        // disabling hash generation to prevent extra projections in the plan which make it hard to write matchers for isNotFullyPushedDown
        Session optimizeHashGenerationDisabled = Session.builder(getSession()).setSystemProperty("optimize_hash_generation", "false").build();
        // It is not captured in the `isNotFullyPushedDown` calls (can't do that) but depending on the connector in use some aggregations
        // still can be pushed down to connector.
        // the DISTINCT part of aggregation will still be pushed down to connector as `GROUP BY`. Only the `count` part will remain on the Trino side.
        assertThat(query(optimizeHashGenerationDisabled, "SELECT count(DISTINCT t_varchar) FROM " + testTable.getName())).matches("VALUES BIGINT '7'").isNotFullyPushedDown(AggregationNode.class);
        assertThat(query(optimizeHashGenerationDisabled, "SELECT count(DISTINCT t_char) FROM " + testTable.getName())).matches("VALUES BIGINT '7'").isNotFullyPushedDown(AggregationNode.class);
        assertThat(query("SELECT count(DISTINCT t_char), count(DISTINCT t_varchar) FROM " + testTable.getName())).matches("VALUES (BIGINT '7', BIGINT '7')").isNotFullyPushedDown(MarkDistinctNode.class, ExchangeNode.class, ExchangeNode.class, ProjectNode.class);
    }
}
Also used : MarkDistinctNode(io.trino.sql.planner.plan.MarkDistinctNode) MySqlQueryRunner.createMySqlQueryRunner(io.trino.plugin.mysql.MySqlQueryRunner.createMySqlQueryRunner) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) LEGACY_IMAGE(io.trino.plugin.mysql.TestingMySqlServer.LEGACY_IMAGE) TestTable(io.trino.testing.sql.TestTable) String.format(java.lang.String.format) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) QueryRunner(io.trino.testing.QueryRunner) AggregationNode(io.trino.sql.planner.plan.AggregationNode) Optional(java.util.Optional) ExchangeNode(io.trino.sql.planner.plan.ExchangeNode) ProjectNode(io.trino.sql.planner.plan.ProjectNode) Session(io.trino.Session) TestTable(io.trino.testing.sql.TestTable) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 22 with TestTable

use of io.trino.testing.sql.TestTable in project trino by trinodb.

the class TestMySqlLegacyConnectorTest method testInsertUnicode.

@Test
@Override
public void testInsertUnicode() {
    // Create tables with CHARACTER SET utf8mb4 option in MySQL side to allow inserting unicode values
    try (TestTable table = new TestTable(onRemoteDatabase(), "tpch.test_insert_unicode_", "(test varchar(50) CHARACTER SET utf8mb4)")) {
        assertUpdate("INSERT INTO " + table.getName() + "(test) VALUES 'Hello', U&'hello\\6d4B\\8Bd5world\\7F16\\7801' ", 2);
        assertThat(computeActual("SELECT test FROM " + table.getName()).getOnlyColumnAsSet()).containsExactlyInAnyOrder("Hello", "hello测试world编码");
    }
    try (TestTable table = new TestTable(onRemoteDatabase(), "tpch.test_insert_unicode_", "(test varchar(50) CHARACTER SET utf8mb4)")) {
        assertUpdate("INSERT INTO " + table.getName() + "(test) VALUES 'aa', 'bé'", 2);
        assertQuery("SELECT test FROM " + table.getName(), "VALUES 'aa', 'bé'");
        assertQuery("SELECT test FROM " + table.getName() + " WHERE test = 'aa'", "VALUES 'aa'");
        assertQuery("SELECT test FROM " + table.getName() + " WHERE test > 'ba'", "VALUES 'bé'");
        assertQuery("SELECT test FROM " + table.getName() + " WHERE test < 'ba'", "VALUES 'aa'");
        assertQueryReturnsEmptyResult("SELECT test FROM " + table.getName() + " WHERE test = 'ba'");
    }
    try (TestTable table = new TestTable(onRemoteDatabase(), "tpch.test_insert_unicode_", "(test varchar(50) CHARACTER SET utf8mb4)")) {
        assertUpdate("INSERT INTO " + table.getName() + "(test) VALUES 'a', 'é'", 2);
        assertQuery("SELECT test FROM " + table.getName(), "VALUES 'a', 'é'");
        assertQuery("SELECT test FROM " + table.getName() + " WHERE test = 'a'", "VALUES 'a'");
        assertQuery("SELECT test FROM " + table.getName() + " WHERE test > 'b'", "VALUES 'é'");
        assertQuery("SELECT test FROM " + table.getName() + " WHERE test < 'b'", "VALUES 'a'");
        assertQueryReturnsEmptyResult("SELECT test FROM " + table.getName() + " WHERE test = 'b'");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test)

Example 23 with TestTable

use of io.trino.testing.sql.TestTable in project trino by trinodb.

the class TestPhoenixTypeMapping method testUnsupportedSmallint.

@Test
public void testUnsupportedSmallint() {
    try (TestTable table = new TestTable(new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()), "tpch.test_unsupported_smallint", "(data smallint, pk smallint primary key)")) {
        assertPhoenixQueryFails(// min - 1
        format("INSERT INTO %s VALUES (-32769, 1)", table.getName()), "ERROR 203 (22005): Type mismatch. BIGINT and SMALLINT for expression: -32769 in column 0.DATA");
        assertPhoenixQueryFails(// max + 1
        format("INSERT INTO %s VALUES (32768, 2)", table.getName()), "ERROR 203 (22005): Type mismatch. SMALLINT and INTEGER for 32768");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 24 with TestTable

use of io.trino.testing.sql.TestTable in project trino by trinodb.

the class TestPhoenixTypeMapping method testUnsupportedBigInt.

@Test
public void testUnsupportedBigInt() {
    try (TestTable table = new TestTable(new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()), "tpch.test_unsupported_bigint", "(data bigint, pk bigint primary key)")) {
        assertPhoenixQueryFails(// min - 1
        format("INSERT INTO %s VALUES (-9223372036854775809, 1)", table.getName()), "ERROR 203 (22005): Type mismatch. DECIMAL and BIGINT for expression: -9223372036854775809 in column 0.DATA");
        // Phoenix JDBC driver throws ArithmeticException instead of SQLException when the value is larger than max of bigint
        // max + 1
        assertThatThrownBy(() -> new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()).execute(format("INSERT INTO %s VALUES (9223372036854775808, 2)", table.getName()))).isInstanceOf(ArithmeticException.class).hasMessage("Overflow");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 25 with TestTable

use of io.trino.testing.sql.TestTable in project trino by trinodb.

the class TestPhoenixTypeMapping method testDecimalUnspecifiedPrecision.

@Test
public void testDecimalUnspecifiedPrecision() {
    PhoenixSqlExecutor phoenixSqlExecutor = new PhoenixSqlExecutor(phoenixServer.getJdbcUrl());
    try (TestTable testTable = new TestTable(phoenixSqlExecutor, "tpch.test_var_decimal", "(pk bigint primary key, d_col decimal)", asList("1, 1.12", "2, 123456.789", "3, -1.12", "4, -123456.789"))) {
        assertQueryFails(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 0), "SELECT d_col FROM " + testTable.getName(), "Rounding necessary");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 0), "SELECT d_col FROM " + testTable.getName(), "VALUES (1), (123457), (-1), (-123457)");
        assertQueryFails(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 1), "SELECT d_col FROM " + testTable.getName(), "Rounding necessary");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 1), "SELECT d_col FROM " + testTable.getName(), "VALUES (1.1), (123456.8), (-1.1), (-123456.8)");
        assertQueryFails(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 2), "SELECT d_col FROM " + testTable.getName(), "Rounding necessary");
        assertQuery(sessionWithDecimalMappingAllowOverflow(HALF_UP, 2), "SELECT d_col FROM " + testTable.getName(), "VALUES (1.12), (123456.79), (-1.12), (-123456.79)");
        assertQuery(sessionWithDecimalMappingAllowOverflow(UNNECESSARY, 3), "SELECT d_col FROM " + testTable.getName(), "VALUES (1.12), (123456.789), (-1.12), (-123456.789)");
        assertQueryFails(sessionWithDecimalMappingStrict(CONVERT_TO_VARCHAR), "SELECT d_col FROM " + testTable.getName(), "Rounding necessary");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Aggregations

TestTable (io.trino.testing.sql.TestTable)145 Test (org.testng.annotations.Test)132 SqlDataTypeTest (io.trino.testing.datatype.SqlDataTypeTest)50 BaseConnectorTest (io.trino.testing.BaseConnectorTest)26 Session (io.trino.Session)18 BaseJdbcConnectorTest (io.trino.plugin.jdbc.BaseJdbcConnectorTest)17 DataTypeTest (io.trino.testing.datatype.DataTypeTest)15 SkipException (org.testng.SkipException)14 List (java.util.List)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)8 String.format (java.lang.String.format)8 Stream (java.util.stream.Stream)8 ImmutableList (com.google.common.collect.ImmutableList)7 TestingConnectorBehavior (io.trino.testing.TestingConnectorBehavior)7 JdbcSqlExecutor (io.trino.testing.sql.JdbcSqlExecutor)7 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)7 PlanMatchPattern (io.trino.sql.planner.assertions.PlanMatchPattern)6 ExchangeNode (io.trino.sql.planner.plan.ExchangeNode)6 TableScanNode (io.trino.sql.planner.plan.TableScanNode)6