Search in sources :

Example 1 with TestTable

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

the class TestDeltaLakeAnalyze method testDropMissingStats.

@Test
public void testDropMissingStats() {
    String path = "test_drop_missing_stats_" + randomTableSuffix();
    try (TestTable table = new TestTable(getQueryRunner()::execute, "test_drop_missing_stats", format("WITH (location = '%s') AS SELECT * FROM tpch.sf1.nation", getLocationForTable(path)))) {
        // When there are no extended stats, the procedure should have no effect
        assertUpdate(format("CALL %s.system.drop_extended_stats('%s', '%s')", DELTA_CATALOG, SCHEMA, table.getName()));
        assertQuery("SHOW STATS FOR " + table.getName(), "VALUES" + // column       size  NDist nullF rows   low  high
        "('nationkey', null, null,  0.0, null,    0,   24)," + "('regionkey', null, null,  0.0, null,    0,    4)," + "('comment',   null, null,  0.0, null, null, null)," + "('name',      null, null,  0.0, null, null, null)," + "(null,        null, null, null, 25.0, null, null)");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test)

Example 2 with TestTable

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

the class BaseJdbcConnectorTest method testWriteBatchSizeSessionProperty.

@Test(dataProvider = "batchSizeAndTotalNumberOfRowsToInsertDataProvider")
public void testWriteBatchSizeSessionProperty(Integer batchSize, Integer numberOfRows) {
    if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
        throw new SkipException("CREATE TABLE is required for write_batch_size test but is not supported");
    }
    Session session = Session.builder(getSession()).setCatalogSessionProperty(getSession().getCatalog().orElseThrow(), "write_batch_size", batchSize.toString()).build();
    try (TestTable table = new TestTable(getQueryRunner()::execute, "write_batch_size", "(a varchar(36), b bigint)")) {
        String values = String.join(",", buildRowsForInsert(numberOfRows));
        assertUpdate(session, "INSERT INTO " + table.getName() + " (a, b) VALUES " + values, numberOfRows);
        assertQuery("SELECT COUNT(*) FROM " + table.getName(), format("VALUES %d", numberOfRows));
    }
}
Also used : SkipException(org.testng.SkipException) TestTable(io.trino.testing.sql.TestTable) Session(io.trino.Session) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 3 with TestTable

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

the class BaseJdbcConnectorTest method testDeleteWithBigintEqualityPredicate.

@Test
public void testDeleteWithBigintEqualityPredicate() {
    skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE) && hasBehavior(SUPPORTS_ROW_LEVEL_DELETE));
    // TODO (https://github.com/trinodb/trino/issues/5901) Use longer table name once Oracle version is updated
    try (TestTable table = new TestTable(getQueryRunner()::execute, "test_delete_bigint", "AS SELECT * FROM region")) {
        assertUpdate("DELETE FROM " + table.getName() + " WHERE regionkey = 1", 1);
        assertQuery("SELECT regionkey, name FROM " + table.getName(), "VALUES " + "(0, 'AFRICA')," + "(2, 'ASIA')," + "(3, 'EUROPE')," + "(4, 'MIDDLE EAST')");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 4 with TestTable

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

the class BaseJdbcConnectorTest method testDeleteWithVarcharEqualityPredicate.

@Test
public void testDeleteWithVarcharEqualityPredicate() {
    skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE) && hasBehavior(SUPPORTS_ROW_LEVEL_DELETE));
    // TODO (https://github.com/trinodb/trino/issues/5901) Use longer table name once Oracle version is updated
    try (TestTable table = new TestTable(getQueryRunner()::execute, "test_delete_varchar", "(col varchar(1))", ImmutableList.of("'a'", "'A'", "null"))) {
        if (!hasBehavior(SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_EQUALITY)) {
            assertQueryFails("DELETE FROM " + table.getName() + " WHERE col = 'A'", "Unsupported delete");
            return;
        }
        assertUpdate("DELETE FROM " + table.getName() + " WHERE col = 'A'", 1);
        assertQuery("SELECT * FROM " + table.getName(), "VALUES 'a', null");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 5 with TestTable

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

the class BaseJdbcConnectorTest method testVarianceAggregationPushdown.

@Test
public void testVarianceAggregationPushdown() {
    String schemaName = getSession().getSchema().orElseThrow();
    if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_VARIANCE)) {
        if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
            throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown");
        }
        try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_var_pushdown", ImmutableList.of())) {
            assertThat(query("SELECT var_pop(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class);
            assertThat(query("SELECT variance(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class);
            assertThat(query("SELECT var_samp(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class);
            return;
        }
    }
    try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_var_pushdown", ImmutableList.of())) {
        assertThat(query("SELECT var_pop(t_double) FROM " + testTable.getName())).isFullyPushedDown();
        assertThat(query("SELECT variance(t_double) FROM " + testTable.getName())).isFullyPushedDown();
        assertThat(query("SELECT var_samp(t_double) FROM " + testTable.getName())).isFullyPushedDown();
        onRemoteDatabase().execute("INSERT INTO " + testTable.getName() + " (t_double) VALUES (1)");
        assertThat(query("SELECT var_pop(t_double) FROM " + testTable.getName())).isFullyPushedDown();
        assertThat(query("SELECT variance(t_double) FROM " + testTable.getName())).isFullyPushedDown();
        assertThat(query("SELECT var_samp(t_double) FROM " + testTable.getName())).isFullyPushedDown();
        onRemoteDatabase().execute("INSERT INTO " + testTable.getName() + " (t_double) VALUES (3)");
        assertThat(query("SELECT var_pop(t_double) FROM " + testTable.getName())).isFullyPushedDown();
        onRemoteDatabase().execute("INSERT INTO " + testTable.getName() + " (t_double) VALUES (5)");
        assertThat(query("SELECT variance(t_double) FROM " + testTable.getName())).isFullyPushedDown();
        assertThat(query("SELECT var_samp(t_double) FROM " + testTable.getName())).isFullyPushedDown();
    }
    try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_var_pushdown", ImmutableList.of("1, 1, 1, 1", "2, 2, 2, 2", "4, 4, 4, 4", "5, 5, 5, 5"))) {
        // Test non-whole number results
        assertThat(query("SELECT var_pop(t_double) FROM " + testTable.getName())).isFullyPushedDown();
        assertThat(query("SELECT variance(t_double) FROM " + testTable.getName())).isFullyPushedDown();
        assertThat(query("SELECT var_samp(t_double) FROM " + testTable.getName())).isFullyPushedDown();
    }
}
Also used : SkipException(org.testng.SkipException) TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

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