Search in sources :

Example 61 with QueryResult

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

the class TestAllDatatypesFromHiveConnector method testSelectAllDatatypesParquetFile.

@Requires(ParquetRequirements.class)
@Test
public void testSelectAllDatatypesParquetFile() {
    String tableName = mutableTableInstanceOf(ALL_HIVE_SIMPLE_TYPES_PARQUET).getNameInDatabase();
    onHive().executeQuery(format("INSERT INTO %s VALUES(" + "127," + "32767," + "2147483647," + "9223372036854775807," + "123.345," + "234.567," + "346," + "345.67800," + "'" + Timestamp.valueOf(LocalDateTime.of(2015, 5, 10, 12, 15, 35, 123_000_000)).toString() + "'," + "'ala ma kota'," + "'ala ma kot'," + "'ala ma    '," + "true," + "'kot binarny'" + ")", tableName));
    assertThat(onTrino().executeQuery(format("SHOW COLUMNS FROM %s", tableName)).project(1, 2)).containsExactlyInOrder(row("c_tinyint", "tinyint"), row("c_smallint", "smallint"), row("c_int", "integer"), row("c_bigint", "bigint"), row("c_float", "real"), row("c_double", "double"), row("c_decimal", "decimal(10,0)"), row("c_decimal_w_params", "decimal(10,5)"), row("c_timestamp", "timestamp(3)"), row("c_string", "varchar"), row("c_varchar", "varchar(10)"), row("c_char", "char(10)"), row("c_boolean", "boolean"), row("c_binary", "varbinary"));
    QueryResult queryResult = onTrino().executeQuery(format("SELECT * FROM %s", tableName));
    assertColumnTypesParquet(queryResult);
    assertThat(queryResult).containsOnly(row(127, 32767, 2147483647, 9223372036854775807L, 123.345f, 234.567, new BigDecimal("346"), new BigDecimal("345.67800"), Timestamp.valueOf(LocalDateTime.of(2015, 5, 10, 12, 15, 35, 123_000_000)), "ala ma kota", "ala ma kot", "ala ma    ", true, "kot binarny".getBytes(UTF_8)));
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) BigDecimal(java.math.BigDecimal) Requires(io.trino.tempto.Requires) Test(org.testng.annotations.Test)

Example 62 with QueryResult

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

the class TestAllDatatypesFromHiveConnector method testSelectAllDatatypesTextFile.

@Requires(TextRequirements.class)
@Test(groups = SMOKE)
public void testSelectAllDatatypesTextFile() {
    String tableName = ALL_HIVE_SIMPLE_TYPES_TEXTFILE.getName();
    assertProperAllDatatypesSchema(tableName);
    QueryResult queryResult = onTrino().executeQuery(format("SELECT * FROM %s", tableName));
    assertColumnTypes(queryResult);
    assertThat(queryResult).containsOnly(row(127, 32767, 2147483647, 9223372036854775807L, 123.345f, 234.567, new BigDecimal("346"), new BigDecimal("345.67800"), Timestamp.valueOf(LocalDateTime.of(2015, 5, 10, 12, 15, 35, 123_000_000)), Date.valueOf("2015-05-10"), "ala ma kota", "ala ma kot", "ala ma    ", true, "kot binarny".getBytes(UTF_8)));
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) BigDecimal(java.math.BigDecimal) Requires(io.trino.tempto.Requires) Test(org.testng.annotations.Test)

Example 63 with QueryResult

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

the class TestComments method testCommentColumn.

@Test(groups = COMMENT)
public void testCommentColumn() {
    String createTableSql = format("" + "CREATE TABLE hive.default.%s (\n" + "   c1 bigint COMMENT 'test comment',\n" + "   c2 bigint COMMENT '',\n" + "   c3 bigint\n" + ")\n" + "WITH (\n" + "   format = 'RCBINARY'\n" + ")", COMMENT_COLUMN_NAME);
    onTrino().executeQuery(createTableSql);
    String createTableSqlPattern = format("\\Q" + "CREATE TABLE hive.default.%s (\n" + "   c1 bigint COMMENT 'test comment',\n" + "   c2 bigint COMMENT '',\n" + "   c3 bigint\n" + ")\\E(?s:.*)", COMMENT_COLUMN_NAME);
    QueryResult actualResult = onTrino().executeQuery("SHOW CREATE TABLE " + COMMENT_COLUMN_NAME);
    assertThat((String) actualResult.row(0).get(0)).matches(createTableSqlPattern);
    createTableSqlPattern = format("\\Q" + "CREATE TABLE hive.default.%s (\n" + "   c1 bigint COMMENT 'new comment',\n" + "   c2 bigint COMMENT '',\n" + "   c3 bigint\n" + ")\\E(?s:.*)", COMMENT_COLUMN_NAME);
    onTrino().executeQuery(format("COMMENT ON COLUMN %s.c1 IS 'new comment'", COMMENT_COLUMN_NAME));
    actualResult = onTrino().executeQuery("SHOW CREATE TABLE " + COMMENT_COLUMN_NAME);
    assertThat((String) actualResult.row(0).get(0)).matches(createTableSqlPattern);
    createTableSqlPattern = format("\\Q" + "CREATE TABLE hive.default.%s (\n" + "   c1 bigint COMMENT '',\n" + "   c2 bigint COMMENT '',\n" + "   c3 bigint\n" + ")\\E(?s:.*)", COMMENT_COLUMN_NAME);
    onTrino().executeQuery(format("COMMENT ON COLUMN %s.c1 IS ''", COMMENT_COLUMN_NAME));
    actualResult = onTrino().executeQuery("SHOW CREATE TABLE " + COMMENT_COLUMN_NAME);
    assertThat((String) actualResult.row(0).get(0)).matches(createTableSqlPattern);
    createTableSqlPattern = format("\\Q" + "CREATE TABLE hive.default.%s (\n" + "   c1 bigint,\n" + "   c2 bigint COMMENT '',\n" + "   c3 bigint\n" + ")\\E(?s:.*)", COMMENT_COLUMN_NAME);
    onTrino().executeQuery(format("COMMENT ON COLUMN %s.c1 IS NULL", COMMENT_COLUMN_NAME));
    actualResult = onTrino().executeQuery("SHOW CREATE TABLE " + COMMENT_COLUMN_NAME);
    assertThat((String) actualResult.row(0).get(0)).matches(createTableSqlPattern);
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) ProductTest(io.trino.tempto.ProductTest) Test(org.testng.annotations.Test)

Example 64 with QueryResult

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

the class AbstractTestHiveViews method testShowCreateView.

@Test(groups = HIVE_VIEWS)
public void testShowCreateView() {
    onHive().executeQuery("DROP VIEW IF EXISTS hive_show_view");
    onHive().executeQuery("CREATE VIEW hive_show_view AS SELECT * FROM nation");
    String showCreateViewSql = "SHOW CREATE VIEW %s.default.hive_show_view";
    String expectedResult = "CREATE VIEW %s.default.hive_show_view SECURITY DEFINER AS\n" + "SELECT\n" + "  \"n_nationkey\"\n" + ", \"n_name\"\n" + ", \"n_regionkey\"\n" + ", \"n_comment\"\n" + "FROM\n" + "  \"default\".\"nation\"";
    QueryResult actualResult = onTrino().executeQuery(format(showCreateViewSql, "hive"));
    assertThat(actualResult).hasRowsCount(1);
    assertEquals((String) actualResult.row(0).get(0), format(expectedResult, "hive"));
    // Verify the translated view sql for a catalog other than "hive", which is configured to the same metastore
    actualResult = onTrino().executeQuery(format(showCreateViewSql, "hive_with_external_writes"));
    assertThat(actualResult).hasRowsCount(1);
    assertEquals((String) actualResult.row(0).get(0), format(expectedResult, "hive_with_external_writes"));
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Test(org.testng.annotations.Test)

Example 65 with QueryResult

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

the class TestSqlCancel method cancelQuery.

private void cancelQuery(String sql) throws InterruptedException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    while (stopwatch.elapsed(SECONDS) < 30) {
        String findQuerySql = "SELECT query_id from system.runtime.queries WHERE query = '%s' and state = 'RUNNING' LIMIT 2";
        QueryResult queryResult = onTrino().executeQuery(format(findQuerySql, sql));
        checkState(queryResult.getRowsCount() < 2, "Query is executed multiple times");
        if (queryResult.getRowsCount() == 1) {
            String queryId = (String) queryResult.row(0).get(0);
            Response response = queryCanceller.cancel(queryId);
            Assertions.assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT.code());
            return;
        }
        MILLISECONDS.sleep(100L);
    }
    throw new IllegalStateException("Query did not reach running state or maybe it was too quick.");
}
Also used : Response(io.airlift.http.client.Response) QueryResult(io.trino.tempto.query.QueryResult) Stopwatch(com.google.common.base.Stopwatch)

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