Search in sources :

Example 6 with QueryResult

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

the class TestAllDatatypesFromHiveConnector method testSelectAllDatatypesOrc.

@Requires(OrcRequirements.class)
@Test(groups = JDBC)
public void testSelectAllDatatypesOrc() {
    String tableName = mutableTableInstanceOf(ALL_HIVE_SIMPLE_TYPES_ORC).getNameInDatabase();
    populateDataToHiveTable(tableName);
    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 7 with QueryResult

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

the class TestAllDatatypesFromHiveConnector method testSelectAllDatatypesAvro.

@Requires(AvroRequirements.class)
@Test(groups = JDBC)
public void testSelectAllDatatypesAvro() {
    String tableName = mutableTableInstanceOf(ALL_HIVE_SIMPLE_TYPES_AVRO).getNameInDatabase();
    onHive().executeQuery(format("INSERT INTO %s VALUES(" + "2147483647," + "9223372036854775807," + "123.345," + "234.567," + "346," + "345.67800," + "'" + Timestamp.valueOf(LocalDateTime.of(2015, 5, 10, 12, 15, 35, 123_000_000)).toString() + "'," + "'" + Date.valueOf("2015-05-10") + "'," + "'ala ma kota'," + "'ala ma kot'," + "'ala ma    '," + "true," + "'kot binarny'" + ")", tableName));
    assertThat(onTrino().executeQuery("SHOW COLUMNS FROM " + tableName).project(1, 2)).containsExactlyInOrder(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_date", "date"), 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("SELECT * FROM " + tableName);
    assertThat(queryResult).hasColumns(INTEGER, BIGINT, REAL, DOUBLE, DECIMAL, DECIMAL, TIMESTAMP, DATE, VARCHAR, VARCHAR, CHAR, BOOLEAN, VARBINARY);
    assertThat(queryResult).containsOnly(row(2147483647, 9223372036854775807L, 123.345f, 234.567, new BigDecimal("346"), new BigDecimal("345.67800"), isHiveWithBrokenAvroTimestamps() ? // TODO (https://github.com/trinodb/trino/issues/1218) requires https://issues.apache.org/jira/browse/HIVE-21002
    Timestamp.valueOf(LocalDateTime.of(2015, 5, 10, 18, 0, 35, 123_000_000)) : 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 8 with QueryResult

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

the class TestAvroSchemaUrl method isOnHdp.

private boolean isOnHdp() {
    try {
        QueryResult queryResult = onHive().executeQuery("SET system:hdp.version");
        String hdpVersion = (String) queryResult.row(0).get(0);
        return !isNullOrEmpty(hdpVersion);
    } catch (QueryExecutionException e) {
        return false;
    }
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) QueryExecutionException(io.trino.tempto.query.QueryExecutionException)

Example 9 with QueryResult

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

the class TestComments method testCommentTable.

@Test(groups = COMMENT)
public void testCommentTable() {
    String createTableSql = format("" + "CREATE TABLE hive.default.%s (\n" + "   c1 bigint\n" + ")\n" + "COMMENT 'old comment'\n" + "WITH (\n" + "   format = 'RCBINARY'\n" + ")", COMMENT_TABLE_NAME);
    onTrino().executeQuery(createTableSql);
    QueryResult actualResult = onTrino().executeQuery("SHOW CREATE TABLE " + COMMENT_TABLE_NAME);
    assertThat((String) actualResult.row(0).get(0)).matches(tableWithCommentPattern(COMMENT_TABLE_NAME, Optional.of("old comment")));
    onTrino().executeQuery(format("COMMENT ON TABLE %s IS 'new comment'", COMMENT_TABLE_NAME));
    actualResult = onTrino().executeQuery("SHOW CREATE TABLE " + COMMENT_TABLE_NAME);
    assertThat((String) actualResult.row(0).get(0)).matches(tableWithCommentPattern(COMMENT_TABLE_NAME, Optional.of("new comment")));
    onTrino().executeQuery(format("COMMENT ON TABLE %s IS ''", COMMENT_TABLE_NAME));
    actualResult = onTrino().executeQuery("SHOW CREATE TABLE " + COMMENT_TABLE_NAME);
    assertThat((String) actualResult.row(0).get(0)).matches(tableWithCommentPattern(COMMENT_TABLE_NAME, Optional.of("")));
    onTrino().executeQuery(format("COMMENT ON TABLE %s IS NULL", COMMENT_TABLE_NAME));
    actualResult = onTrino().executeQuery("SHOW CREATE TABLE " + COMMENT_TABLE_NAME);
    assertThat((String) actualResult.row(0).get(0)).matches(tableWithCommentPattern(COMMENT_TABLE_NAME, Optional.empty()));
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) ProductTest(io.trino.tempto.ProductTest) Test(org.testng.annotations.Test)

Example 10 with QueryResult

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

the class TestHiveTransactionalTable method verifyOriginalFiles.

private void verifyOriginalFiles(String tableName, String whereClause) {
    QueryResult result = onTrino().executeQuery(format("SELECT DISTINCT \"$path\" FROM %s %s", tableName, whereClause));
    String path = (String) result.row(0).get(0);
    checkArgument(ORIGINAL_FILE_MATCHER.matcher(path).matches(), "Path should be original file path, but isn't, path: %s", path);
}
Also used : QueryResult(io.trino.tempto.query.QueryResult)

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