Search in sources :

Example 51 with QueryResult

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

the class TestHiveBucketedTables method testBucketingWithUnsupportedDataTypes.

@Test(dataProvider = "testBucketingWithUnsupportedDataTypesDataProvider")
@Flaky(issue = ERROR_COMMITTING_WRITE_TO_HIVE_ISSUE, match = ERROR_COMMITTING_WRITE_TO_HIVE_MATCH)
public void testBucketingWithUnsupportedDataTypes(BucketingType bucketingType, String columnToBeBucketed) {
    try (TemporaryHiveTable table = temporaryHiveTable("table_with_unsupported_bucketing_types_" + randomTableSuffix())) {
        String tableName = table.getName();
        onHive().executeQuery(format("CREATE TABLE %s (" + "n_integer       INT," + "n_decimal       DECIMAL(9, 2)," + "n_timestamp     TIMESTAMP," + "n_char          CHAR(10)," + "n_binary        BINARY," + "n_union         UNIONTYPE<INT,STRING>," + "n_struct        STRUCT<field1:INT,field2:STRING>) " + "CLUSTERED BY (%s) INTO 2 BUCKETS " + "STORED AS ORC " + "%s", tableName, columnToBeBucketed, hiveTableProperties(bucketingType)));
        QueryResult showCreateTableResult = onTrino().executeQuery("SHOW CREATE TABLE " + tableName);
        assertThat(showCreateTableResult).hasRowsCount(1);
        Assertions.assertThat((String) getOnlyElement(getOnlyElement(showCreateTableResult.rows()))).matches(Pattern.compile(format("\\QCREATE TABLE hive.default.%s (\n" + "   n_integer integer,\n" + "   n_decimal decimal(9, 2),\n" + "   n_timestamp timestamp(3),\n" + "   n_char char(10),\n" + "   n_binary varbinary,\n" + "   n_union ROW(tag tinyint, field0 integer, field1 varchar),\n" + "   n_struct ROW(field1 integer, field2 varchar)\n" + ")\n" + "WITH (\\E(?s:.*)" + "bucket_count = 2,\n(?s:.*)" + "bucketed_by = ARRAY\\['%s'\\],\n(?s:.*)" + "bucketing_version = %s,(?s:.*)", tableName, Pattern.quote(columnToBeBucketed), getExpectedBucketVersion(bucketingType))));
        populateRowToHiveTable(tableName, ImmutableList.<String>builder().add("1").add("CAST(1 AS DECIMAL(9, 2))").add("CAST('2015-01-01T00:01:00.15' AS TIMESTAMP)").add("'char value'").add("unhex('00010203')").add("create_union(0, 1, 'union value')").add("named_struct('field1', 1, 'field2', 'Field2')").build(), Optional.empty());
        assertThat(onTrino().executeQuery(format("SELECT * FROM %s", tableName))).hasRowsCount(1);
        assertQueryFailure(() -> onTrino().executeQuery("SELECT \"$bucket\" FROM " + tableName)).hasMessageMatching("Query failed \\(#\\w+\\):\\Q line 1:8: Column '$bucket' cannot be resolved");
        assertQueryFailure(() -> onTrino().executeQuery(format("INSERT INTO %s(n_integer) VALUES (1)", tableName))).hasMessageMatching("Query failed \\(#\\w+\\): Cannot write to a table bucketed on an unsupported type");
        String newTableName = "new_" + tableName;
        assertQueryFailure(() -> onTrino().executeQuery(format("CREATE TABLE %s (LIKE %s INCLUDING PROPERTIES)", newTableName, tableName))).hasMessageMatching("Query failed \\(#\\w+\\): Cannot create a table bucketed on an unsupported type");
        assertQueryFailure(() -> onTrino().executeQuery(format("CREATE TABLE %s (" + "n_integer       integer," + "n_decimal       decimal(9, 2)," + "n_timestamp     timestamp(3)," + "n_char          char(10)," + "n_binary        varbinary," + "n_union         ROW(tag tinyint, field0 integer, field1 varchar)," + "n_struct        ROW(field1 integer, field2 varchar)) " + "WITH (" + "   bucketed_by = ARRAY['%s']," + "   bucket_count = 2" + ")", newTableName, columnToBeBucketed))).hasMessageMatching("Query failed \\(#\\w+\\): Cannot create a table bucketed on an unsupported type");
        assertQueryFailure(() -> onTrino().executeQuery(format("CREATE TABLE %s WITH (%s) AS SELECT * FROM %s", newTableName, bucketingType.getTrinoTableProperties(columnToBeBucketed, 2).stream().collect(joining(",")), tableName))).hasMessageMatching("Query failed \\(#\\w+\\): Cannot create a table bucketed on an unsupported type");
    }
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) TemporaryHiveTable(io.trino.tests.product.hive.util.TemporaryHiveTable) Test(org.testng.annotations.Test) Flaky(io.trino.testng.services.Flaky)

Example 52 with QueryResult

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

the class TestHiveCoercion method assertQueryResults.

private void assertQueryResults(Engine engine, String query, Map<String, List<Object>> expected, List<String> columns, int rowCount, String tableName) {
    QueryResult actual = execute(engine, query);
    ImmutableList.Builder<Row> rowsBuilder = ImmutableList.builder();
    for (int row = 0; row < rowCount; row++) {
        // Avoid ImmutableList to allow nulls
        List<Object> currentRow = new ArrayList<>();
        for (int column = 0; column < columns.size(); column++) {
            String columnName = columns.get(column);
            checkArgument(expected.containsKey(columnName), "columnName should be present in expected results");
            currentRow.add(expected.get(columnName).get(row));
        }
        rowsBuilder.add(new Row(currentRow));
    }
    List<Row> expectedRows = rowsBuilder.build();
    assertColumnTypes(actual, tableName, engine, columns);
    for (int sqlIndex = 1; sqlIndex <= columns.size(); sqlIndex++) {
        String column = columns.get(sqlIndex - 1);
        if (column.equals("row_to_row") || column.equals("map_to_map")) {
            assertEqualsIgnoreOrder(actual.column(sqlIndex), column(expectedRows, sqlIndex), format("%s field is not equal", column));
            continue;
        }
        if (column.equals("list_to_list")) {
            assertEqualsIgnoreOrder(engine == Engine.TRINO ? extract(actual.column(sqlIndex)) : actual.column(sqlIndex), column(expectedRows, sqlIndex), "list_to_list field is not equal");
            continue;
        }
        // test primitive values
        assertThat(actual.project(sqlIndex)).containsOnly(project(expectedRows, sqlIndex));
    }
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) Row(io.trino.tempto.assertions.QueryAssert.Row)

Example 53 with QueryResult

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

the class TestSelect method testAllDataTypes.

@Test(groups = { CASSANDRA, PROFILE_SPECIFIC_TESTS })
public void testAllDataTypes() {
    // NOTE: DECIMAL is treated like DOUBLE
    QueryResult query = onTrino().executeQuery(format("SELECT a, b, bl, bo, d, do, dt, f, fr, i, integer, l, m, s, si, t, ti, ts, tu, u, v, vari FROM %s.%s.%s", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_ALL_TYPES.getName()));
    assertThat(query).hasColumns(VARCHAR, BIGINT, VARBINARY, BOOLEAN, DOUBLE, DOUBLE, DATE, REAL, VARCHAR, VARCHAR, INTEGER, VARCHAR, VARCHAR, VARCHAR, SMALLINT, VARCHAR, TINYINT, TIMESTAMP_WITH_TIMEZONE, JAVA_OBJECT, JAVA_OBJECT, VARCHAR, VARCHAR).containsOnly(row("\0", Long.MIN_VALUE, Bytes.fromHexString("0x00").array(), false, 0f, Double.MIN_VALUE, Date.valueOf("1970-01-02"), Float.MIN_VALUE, "[0]", "0.0.0.0", Integer.MIN_VALUE, "[0]", "{\"\\u0000\":-2147483648,\"a\":0}", "[0]", Short.MIN_VALUE, "\0", Byte.MIN_VALUE, Timestamp.from(OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).toInstant()), "d2177dd0-eaa2-11de-a572-001b779c76e3", "01234567-0123-0123-0123-0123456789ab", "\0", String.valueOf(Long.MIN_VALUE)), row("the quick brown fox jumped over the lazy dog", 9223372036854775807L, "01234".getBytes(UTF_8), true, Double.valueOf("99999999999999999999999999999999999999"), Double.MAX_VALUE, Date.valueOf("9999-12-31"), Float.MAX_VALUE, "[4,5,6,7]", "255.255.255.255", Integer.MAX_VALUE, "[4,5,6]", "{\"a\":1,\"b\":2}", "[4,5,6]", Short.MAX_VALUE, "this is a text value", Byte.MAX_VALUE, Timestamp.from(OffsetDateTime.of(9999, 12, 31, 23, 59, 59, 0, ZoneOffset.UTC).toInstant()), "d2177dd0-eaa2-11de-a572-001b779c76e3", "01234567-0123-0123-0123-0123456789ab", "abc", String.valueOf(Long.MAX_VALUE)), row("def", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null));
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest)

Example 54 with QueryResult

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

the class TestSelect method testSelectUserDefinedType.

@Test(groups = { CASSANDRA, PROFILE_SPECIFIC_TESTS })
public void testSelectUserDefinedType() {
    String udtName = "type_user_defined";
    String tableName = "user_defined_type_table";
    onCassandra(format("DROP TABLE IF EXISTS %s.%s", KEY_SPACE, tableName));
    onCassandra(format("DROP TYPE IF EXISTS %s.%s", KEY_SPACE, udtName));
    onCassandra(format("" + "CREATE TYPE %s.%s (" + "t text, " + "u uuid, " + "integer int, " + "b bigint, " + "bl blob, " + "ts timestamp, " + "a ascii, " + "bo boolean, " + "d decimal, " + "do double, " + "f float, " + "i inet, " + "v varchar, " + "vari varint, " + "tu timeuuid, " + "l frozen <list<text>>, " + "m frozen <map<varchar, bigint>>, " + "s frozen <set<boolean>> " + ")", KEY_SPACE, udtName));
    onCassandra(format("" + "CREATE TABLE %s.%s (" + "key text PRIMARY KEY, " + "typeudt frozen <%s>, " + ")", KEY_SPACE, tableName, udtName));
    onCassandra(format("" + "INSERT INTO %s.%s (key, typeudt) VALUES (" + "'key'," + "{ " + "t: 'text', " + "u: 01234567-0123-0123-0123-0123456789ab, " + "integer: -2147483648, " + "b:  -9223372036854775808," + "bl: 0x3031323334, " + "ts: '1970-01-01 13:30:00.000', " + "a: 'ansi', " + "bo: true, " + "d: 99999999999999997748809823456034029568, " + "do: 4.9407e-324, " + "f: 1.4013e-45, " + "i: '0.0.0.0', " + "v: 'varchar', " + "vari: -9223372036854775808, " + "tu: d2177dd0-eaa2-11de-a572-001b779c76e3, " + "l: ['list'], " + "m: {'map': 1}, " + "s: {true} " + "}" + ")", KEY_SPACE, tableName));
    QueryResult queryResult = onTrino().executeQuery(format("" + "SELECT " + "typeudt.t, " + "typeudt.u, " + "typeudt.integer, " + "typeudt.b, " + "typeudt.bl, " + "typeudt.ts, " + "typeudt.a, " + "typeudt.bo, " + "typeudt.d, " + "typeudt.do, " + "typeudt.f, " + "typeudt.i, " + "typeudt.v, " + "typeudt.vari, " + "typeudt.tu, " + "typeudt.l, " + "typeudt.m, " + "typeudt.s " + "FROM %s.%s.%s", CONNECTOR_NAME, KEY_SPACE, tableName));
    assertThat(queryResult).containsOnly(row("text", "01234567-0123-0123-0123-0123456789ab", -2147483648, -9223372036854775808L, "01234".getBytes(UTF_8), Timestamp.valueOf(LocalDateTime.of(1970, 1, 1, 13, 30)), "ansi", true, 99999999999999997748809823456034029568D, 4.9407e-324, 1.4E-45f, "0.0.0.0", "varchar", "-9223372036854775808", "d2177dd0-eaa2-11de-a572-001b779c76e3", "[\"list\"]", "{\"map\":1}", "[true]"));
    onCassandra(format("DROP TABLE %s.%s", KEY_SPACE, tableName));
    onCassandra(format("DROP TYPE %s.%s", KEY_SPACE, udtName));
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest)

Example 55 with QueryResult

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

the class TestSelect method testSelectWithNonEqualityFilterOnNonPartitioningKey.

@Test(groups = { CASSANDRA, PROFILE_SPECIFIC_TESTS })
public void testSelectWithNonEqualityFilterOnNonPartitioningKey() {
    String sql = format("SELECT n_name FROM %s.%s.%s WHERE n_name < 'B'", CONNECTOR_NAME, KEY_SPACE, CASSANDRA_NATION.getName());
    QueryResult queryResult = onTrino().executeQuery(sql);
    assertThat(queryResult).containsOnly(row("ALGERIA"), row("ARGENTINA"));
}
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