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)");
}
}
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));
}
}
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')");
}
}
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");
}
}
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();
}
}
Aggregations