Search in sources :

Example 11 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestBlackHoleConnector method blackHoleConnector.

@Test(groups = BLACKHOLE_CONNECTOR)
public void blackHoleConnector() {
    String nullTable = "\"blackhole\".default.nation_" + UUID.randomUUID().toString().replace("-", "");
    String table = "tpch.tiny.nation";
    assertThat(onTrino().executeQuery(format("SELECT count(*) from %s", table))).containsExactlyInOrder(row(25));
    QueryResult result = onTrino().executeQuery(format("CREATE TABLE %s AS SELECT * FROM %s", nullTable, table));
    try {
        assertThat(result).updatedRowsCountIsEqualTo(25);
        assertThat(onTrino().executeQuery(format("INSERT INTO %s SELECT * FROM %s", nullTable, table))).updatedRowsCountIsEqualTo(25);
        assertThat(onTrino().executeQuery(format("SELECT * FROM %s", nullTable))).hasNoRows();
    } finally {
        onTrino().executeQuery(format("DROP TABLE %s", nullTable));
    }
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Test(org.testng.annotations.Test)

Example 12 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestInsertIntoCassandraTable method testInsertIntoValuesToCassandraTableAllSimpleTypes.

@Test(groups = { CASSANDRA, PROFILE_SPECIFIC_TESTS })
public void testInsertIntoValuesToCassandraTableAllSimpleTypes() {
    TableName table = mutableTablesState().get(CASSANDRA_INSERT_TABLE).getTableName();
    String tableNameInDatabase = format("%s.%s", CONNECTOR_NAME, table.getNameInDatabase());
    assertContainsEventually(() -> onTrino().executeQuery(format("SHOW TABLES FROM %s.%s", CONNECTOR_NAME, KEY_SPACE)), onTrino().executeQuery(format("SELECT '%s'", table.getSchemalessNameInDatabase())), new Duration(1, MINUTES));
    QueryResult queryResult = onTrino().executeQuery("SELECT * FROM " + tableNameInDatabase);
    assertThat(queryResult).hasNoRows();
    // TODO Following types are not supported now. We need to change null into the value after fixing it
    // blob, frozen<set<type>>, inet, list<type>, map<type,type>, set<type>, decimal, varint
    onTrino().executeQuery("INSERT INTO " + tableNameInDatabase + "(a, b, bl, bo, d, do, dt, f, fr, i, ti, si, integer, l, m, s, t, ts, tu, u, v, vari) VALUES (" + "'ascii value', " + "BIGINT '99999', " + "null, " + "true, " + "null, " + "123.456789, " + "DATE '9999-12-31'," + "REAL '123.45678', " + "null, " + "null, " + "TINYINT '-128', " + "SMALLINT '-32768', " + "123, " + "null, " + "null, " + "null, " + "'text value', " + "timestamp '9999-12-31 23:59:59Z'," + "uuid '50554d6e-29bb-11e5-b345-feff819cdc9f', " + "uuid '12151fd2-7586-11e9-8f9e-2a86e4085a59', " + "'varchar value'," + "null)");
    assertThat(onTrino().executeQuery("SELECT * FROM " + tableNameInDatabase)).containsOnly(row("ascii value", 99999, null, true, null, 123.456789, Date.valueOf("9999-12-31"), 123.45678, null, null, 123, null, null, null, -32768, "text value", -128, Timestamp.from(OffsetDateTime.of(9999, 12, 31, 23, 59, 59, 0, ZoneOffset.UTC).toInstant()), "50554d6e-29bb-11e5-b345-feff819cdc9f", "12151fd2-7586-11e9-8f9e-2a86e4085a59", "varchar value", null));
    // insert null for all datatypes
    onTrino().executeQuery("INSERT INTO " + tableNameInDatabase + "(a, b, bl, bo, d, do, dt, f, fr, i, ti, si, integer, l, m, s, t, ts, tu, u, v, vari) VALUES (" + "'key 1', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null) ");
    assertThat(onTrino().executeQuery(format("SELECT * FROM %s WHERE a = 'key 1'", tableNameInDatabase))).containsOnly(row("key 1", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null));
    // insert into only a subset of columns
    onTrino().executeQuery(format("INSERT INTO %s (a, bo, integer, t) VALUES ('key 2', false, 999, 'text 2')", tableNameInDatabase));
    assertThat(onTrino().executeQuery(format("SELECT * FROM %s WHERE a = 'key 2'", tableNameInDatabase))).containsOnly(row("key 2", null, null, false, null, null, null, null, null, null, 999, null, null, null, null, "text 2", null, null, null, null, null, null));
    // negative test: failed to insert null to primary key
    assertQueryFailure(() -> onTrino().executeQuery(format("INSERT INTO %s (a) VALUES (null) ", tableNameInDatabase))).hasMessageContaining("Invalid null value in condition for column a");
}
Also used : TableName(io.trino.tempto.internal.fulfillment.table.TableName) QueryResult(io.trino.tempto.query.QueryResult) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest)

Example 13 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestHivePartitionsTable method testShowPartitionsFromHiveTableWithTooManyPartitions.

@Test(groups = HIVE_PARTITIONING)
@Flaky(issue = ERROR_COMMITTING_WRITE_TO_HIVE_ISSUE, match = ERROR_COMMITTING_WRITE_TO_HIVE_MATCH)
public void testShowPartitionsFromHiveTableWithTooManyPartitions() {
    String tableName = tablesState.get(PARTITIONED_TABLE_WITH_VARIABLE_PARTITIONS).getNameInDatabase();
    String partitionsTable = "\"" + tableName + "$partitions\"";
    createPartitions(tableName, TOO_MANY_PARTITIONS);
    // Verify we created enough partitions for the test to be meaningful
    assertThatThrownBy(() -> onTrino().executeQuery("SELECT * FROM " + tableName)).hasMessageMatching(".*: Query over table '\\S+' can potentially read more than \\d+ partitions");
    QueryResult partitionListResult;
    partitionListResult = onTrino().executeQuery(format("SELECT * FROM %s WHERE part_col < 7", partitionsTable));
    assertThat(partitionListResult).containsExactlyInOrder(row(0), row(1), row(2), row(3), row(4), row(5), row(6));
    assertColumnNames(partitionListResult, "part_col");
    partitionListResult = onTrino().executeQuery(format("SELECT a.part_col FROM (SELECT * FROM %s WHERE part_col = 1) a, (SELECT * FROM %s WHERE part_col = 1) b WHERE a.col = b.col", tableName, tableName));
    assertThat(partitionListResult).containsExactlyInOrder(row(1));
    partitionListResult = onTrino().executeQuery(format("SELECT * FROM %s WHERE part_col < -10", partitionsTable));
    assertThat(partitionListResult).hasNoRows();
    partitionListResult = onTrino().executeQuery(format("SELECT * FROM %s ORDER BY part_col LIMIT 7", partitionsTable));
    assertThat(partitionListResult).containsExactlyInOrder(row(0), row(1), row(2), row(3), row(4), row(5), row(6));
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest) Flaky(io.trino.testng.services.Flaky)

Example 14 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestSelect method testNationJoinRegion.

@Test(groups = { CASSANDRA, PROFILE_SPECIFIC_TESTS })
public void testNationJoinRegion() {
    String sql = format("SELECT c.n_name, t.name FROM %s.%s.%s c JOIN " + "tpch.tiny.region t ON c.n_regionkey = t.regionkey " + "WHERE c.n_nationkey=3", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_NATION.getName());
    QueryResult queryResult = onTrino().executeQuery(sql);
    assertThat(queryResult).containsOnly(row("CANADA", "AMERICA"));
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest)

Example 15 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestSelect method testSelectTupleType.

@Test(groups = { CASSANDRA, PROFILE_SPECIFIC_TESTS })
public void testSelectTupleType() {
    String tableName = "select_tuple_table";
    onCassandra(format("DROP TABLE IF EXISTS %s.%s", KEY_SPACE, tableName));
    onCassandra(format("CREATE TABLE %s.%s (key int, value frozen<tuple<int, text, float>>, PRIMARY KEY (key))", KEY_SPACE, tableName));
    onCassandra(format("INSERT INTO %s.%s (key, value) VALUES(1, (1, 'text-1', 1.11))", KEY_SPACE, tableName));
    QueryResult queryResult = onTrino().executeQuery(format("SELECT * FROM %s.%s.%s", CONNECTOR_NAME, KEY_SPACE, tableName));
    assertThat(queryResult).hasRowsCount(1);
    Assertions.assertThat(queryResult.row(0).get(0)).isEqualTo(1);
    Assertions.assertThat(queryResult.row(0).get(1)).isEqualTo(Row.builder().addUnnamedField(1).addUnnamedField("text-1").addUnnamedField(1.11f).build());
    onCassandra(format("DROP TABLE IF EXISTS %s.%s", KEY_SPACE, tableName));
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest)

Aggregations

QueryResult (io.trino.tempto.query.QueryResult)84 Test (org.testng.annotations.Test)75 ProductTest (io.trino.tempto.ProductTest)61 Requires (io.trino.tempto.Requires)16 Row (io.trino.tempto.assertions.QueryAssert.Row)8 BigDecimal (java.math.BigDecimal)8 Duration (io.airlift.units.Duration)7 Flaky (io.trino.testng.services.Flaky)6 Statement (java.sql.Statement)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 QueryExecutionException (io.trino.tempto.query.QueryExecutionException)4 PreparedStatement (java.sql.PreparedStatement)4 ImmutableList (com.google.common.collect.ImmutableList)3 Row.row (io.trino.tempto.assertions.QueryAssert.Row.row)3 QueryAssert.assertThat (io.trino.tempto.assertions.QueryAssert.assertThat)3 List (java.util.List)3 Inject (com.google.inject.Inject)2 HiveTimestampPrecision (io.trino.plugin.hive.HiveTimestampPrecision)2 HMS_ONLY (io.trino.tests.product.TestGroups.HMS_ONLY)2 STORAGE_FORMATS (io.trino.tests.product.TestGroups.STORAGE_FORMATS)2