Search in sources :

Example 26 with TestTable

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

the class TestPhoenixTypeMapping method testArrayNulls.

@Test
public void testArrayNulls() {
    // Verify only SELECT instead of using SqlDataTypeTest because array comparison not supported for arrays with null elements
    try (TestTable table = new TestTable(getQueryRunner()::execute, "test_array_nulls", "(c1 ARRAY(boolean), c2 ARRAY(varchar), c3 ARRAY(varchar))", ImmutableList.of("(NULL, ARRAY[NULL], ARRAY['foo', NULL, 'bar', NULL])"))) {
        assertThat(query("SELECT c1 FROM " + table.getName())).matches("VALUES CAST(NULL AS ARRAY(boolean))");
        assertThat(query("SELECT c2 FROM " + table.getName())).matches("VALUES CAST(ARRAY[NULL] AS ARRAY(varchar))");
        assertThat(query("SELECT c3 FROM " + table.getName())).matches("VALUES CAST(ARRAY['foo', NULL, 'bar', NULL] AS ARRAY(varchar))");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 27 with TestTable

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

the class TestPhoenixTypeMapping method testArrayNulls.

@Test
public void testArrayNulls() {
    // Verify only SELECT instead of using SqlDataTypeTest because array comparison not supported for arrays with null elements
    try (TestTable table = new TestTable(getQueryRunner()::execute, "test_array_nulls", "(c1 ARRAY(boolean), c2 ARRAY(varchar), c3 ARRAY(varchar))", ImmutableList.of("(NULL, ARRAY[NULL], ARRAY['foo', NULL, 'bar', NULL])"))) {
        assertThat(query("SELECT c1 FROM " + table.getName())).matches("VALUES CAST(NULL AS ARRAY(boolean))");
        assertThat(query("SELECT c2 FROM " + table.getName())).matches("VALUES CAST(ARRAY[NULL] AS ARRAY(varchar))");
        assertThat(query("SELECT c3 FROM " + table.getName())).matches("VALUES CAST(ARRAY['foo', NULL, 'bar', NULL] AS ARRAY(varchar))");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 28 with TestTable

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

the class TestPhoenixTypeMapping method testUnsupportedTinyint.

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

Example 29 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 30 with TestTable

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

the class TestPhoenixConnectorTest method testCountDistinctWithStringTypes.

// Overridden because Phoenix requires a ROWID column
@Override
public void testCountDistinctWithStringTypes() {
    assertThatThrownBy(super::testCountDistinctWithStringTypes).hasStackTraceContaining("Illegal data. CHAR types may only contain single byte characters");
    // Skipping the ą test case because it is not supported
    List<String> rows = Streams.mapWithIndex(Stream.of("a", "b", "A", "B", " a ", "a", "b", " b "), (value, idx) -> String.format("%d, '%2$s', '%2$s'", idx, value)).collect(toImmutableList());
    String tableName = "count_distinct_strings" + randomTableSuffix();
    try (TestTable testTable = new TestTable(getQueryRunner()::execute, tableName, "(id int, t_char CHAR(5), t_varchar VARCHAR(5)) WITH (ROWKEYS='id')", rows)) {
        assertQuery("SELECT count(DISTINCT t_varchar) FROM " + testTable.getName(), "VALUES 6");
        assertQuery("SELECT count(DISTINCT t_char) FROM " + testTable.getName(), "VALUES 6");
        assertQuery("SELECT count(DISTINCT t_char), count(DISTINCT t_varchar) FROM " + testTable.getName(), "VALUES (6, 6)");
    }
}
Also used : SkipException(org.testng.SkipException) DESCENDING(io.trino.sql.tree.SortItem.Ordering.DESCENDING) Connection(java.sql.Connection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) TestTable(io.trino.testing.sql.TestTable) PlanMatchPattern.limit(io.trino.sql.planner.assertions.PlanMatchPattern.limit) SQLException(java.sql.SQLException) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PlanMatchPattern.exchange(io.trino.sql.planner.assertions.PlanMatchPattern.exchange) PlanMatchPattern.sort(io.trino.sql.planner.assertions.PlanMatchPattern.sort) UnsupportedTypeHandling(io.trino.plugin.jdbc.UnsupportedTypeHandling) LOCAL(io.trino.sql.planner.plan.ExchangeNode.Scope.LOCAL) TestingConnectorBehavior(io.trino.testing.TestingConnectorBehavior) SqlExecutor(io.trino.testing.sql.SqlExecutor) UNSUPPORTED_TYPE_HANDLING(io.trino.plugin.jdbc.TypeHandlingJdbcSessionProperties.UNSUPPORTED_TYPE_HANDLING) LAST(io.trino.sql.tree.SortItem.NullOrdering.LAST) ASCENDING(io.trino.sql.tree.SortItem.Ordering.ASCENDING) TestTable.randomTableSuffix(io.trino.testing.sql.TestTable.randomTableSuffix) AfterClass(org.testng.annotations.AfterClass) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) FINAL(io.trino.sql.planner.plan.TopNNode.Step.FINAL) PhoenixQueryRunner.createPhoenixQueryRunner(io.trino.plugin.phoenix5.PhoenixQueryRunner.createPhoenixQueryRunner) PlanMatchPattern.topN(io.trino.sql.planner.assertions.PlanMatchPattern.topN) Streams(com.google.common.collect.Streams) FIRST(io.trino.sql.tree.SortItem.NullOrdering.FIRST) String.format(java.lang.String.format) BaseJdbcConnectorTest(io.trino.plugin.jdbc.BaseJdbcConnectorTest) List(java.util.List) Stream(java.util.stream.Stream) GATHER(io.trino.sql.planner.plan.ExchangeNode.Type.GATHER) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) REMOTE(io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE) QueryRunner(io.trino.testing.QueryRunner) Statement(java.sql.Statement) CONVERT_TO_VARCHAR(io.trino.plugin.jdbc.UnsupportedTypeHandling.CONVERT_TO_VARCHAR) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) PlanMatchPattern.output(io.trino.sql.planner.assertions.PlanMatchPattern.output) DriverManager(java.sql.DriverManager) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) Session(io.trino.Session) TestTable(io.trino.testing.sql.TestTable)

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