Search in sources :

Example 1 with Row

use of io.prestodb.tempto.assertions.QueryAssert.Row in project presto by prestodb.

the class TestHiveStorageFormats method assertSelect.

private static void assertSelect(String query, String tableName) {
    QueryResult expected = query(format(query, "tpch." + TPCH_SCHEMA + ".lineitem"));
    List<Row> expectedRows = expected.rows().stream().map((columns) -> row(columns.toArray())).collect(toImmutableList());
    QueryResult actual = query(format(query, tableName));
    assertThat(actual).hasColumns(expected.getColumnTypes()).containsExactly(expectedRows);
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Connection(java.sql.Connection) DataProvider(org.testng.annotations.DataProvider) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) QueryExecutors.onHive(com.facebook.presto.tests.utils.QueryExecutors.onHive) STORAGE_FORMATS(com.facebook.presto.tests.TestGroups.STORAGE_FORMATS) Test(org.testng.annotations.Test) Row.row(io.prestodb.tempto.assertions.QueryAssert.Row.row) String.format(java.lang.String.format) SQLException(java.sql.SQLException) List(java.util.List) QueryExecutor.query(io.prestodb.tempto.query.QueryExecutor.query) Row(io.prestodb.tempto.assertions.QueryAssert.Row) QueryAssert.assertThat(io.prestodb.tempto.assertions.QueryAssert.assertThat) QueryExecutor.defaultQueryExecutor(io.prestodb.tempto.query.QueryExecutor.defaultQueryExecutor) Locale(java.util.Locale) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) JdbcDriverUtils(com.facebook.presto.tests.utils.JdbcDriverUtils) ProductTest(io.prestodb.tempto.ProductTest) JdbcDriverUtils.setSessionProperty(com.facebook.presto.tests.utils.JdbcDriverUtils.setSessionProperty) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) QueryResult(io.prestodb.tempto.query.QueryResult) Row(io.prestodb.tempto.assertions.QueryAssert.Row)

Example 2 with Row

use of io.prestodb.tempto.assertions.QueryAssert.Row in project presto by prestodb.

the class TestHiveCoercion method doTestHiveCoercion.

private void doTestHiveCoercion(HiveTableDefinition tableDefinition) {
    String tableName = mutableTableInstanceOf(tableDefinition).getNameInDatabase();
    String floatToDoubleType = tableName.toLowerCase(Locale.ENGLISH).contains("parquet") ? "DOUBLE" : "REAL";
    query(format("INSERT INTO %s\n" + "VALUES\n" + "  (TINYINT '-1', TINYINT '2', TINYINT '-3', SMALLINT '100', SMALLINT '-101', INTEGER '2323', 12345, REAL '0.5',\n" + "    CAST(ROW ('as is', -1, 100, 2323, 12345) AS ROW(keep VARCHAR, ti2si TINYINT, si2int SMALLINT, int2bi INTEGER, bi2vc BIGINT)),\n" + "    ARRAY [CAST(ROW (2, -101, 12345, 'removed') AS ROW (ti2int TINYINT, si2bi SMALLINT, bi2vc BIGINT, remove VARCHAR))],\n" + "    MAP (ARRAY [TINYINT '2'], ARRAY [CAST(ROW (-3, 2323, REAL '0.5') AS ROW (ti2bi TINYINT, int2bi INTEGER, float2double %s))]),\n" + "    1),\n" + "  (TINYINT '1', TINYINT '-2', NULL, SMALLINT '-100', SMALLINT '101', INTEGER '-2323', -12345, REAL '-1.5',\n" + "    CAST(ROW (NULL, 1, -100, -2323, -12345) AS ROW(keep VARCHAR, ti2si TINYINT, si2int SMALLINT, int2bi INTEGER, bi2vc BIGINT)),\n" + "    ARRAY [CAST(ROW (-2, 101, -12345, NULL) AS ROW (ti2int TINYINT, si2bi SMALLINT, bi2vc BIGINT, remove VARCHAR))],\n" + "    MAP (ARRAY [TINYINT '-2'], ARRAY [CAST(ROW (null, -2323, REAL '-1.5') AS ROW (ti2bi TINYINT, int2bi INTEGER, float2double %s))]),\n" + "    1)", tableName, floatToDoubleType, floatToDoubleType));
    alterTableColumnTypes(tableName);
    assertProperAlteredTableSchema(tableName);
    QueryResult queryResult = query(format("SELECT * FROM %s", tableName));
    assertColumnTypes(queryResult);
    List<Row> expectedRows;
    Connection connection = defaultQueryExecutor().getConnection();
    if (usingPrestoJdbcDriver(connection)) {
        expectedRows = ImmutableList.of(row(-1, 2, -3L, 100, -101L, 2323L, "12345", 0.5, asMap("keep", "as is", "ti2si", (short) -1, "si2int", 100, "int2bi", 2323L, "bi2vc", "12345"), ImmutableList.of(asMap("ti2int", 2, "si2bi", -101L, "bi2vc", "12345")), asMap(2, asMap("ti2bi", -3L, "int2bi", 2323L, "float2double", 0.5, "add", null)), 1), row(1, -2, null, -100, 101L, -2323L, "-12345", -1.5, asMap("keep", null, "ti2si", (short) 1, "si2int", -100, "int2bi", -2323L, "bi2vc", "-12345"), ImmutableList.of(asMap("ti2int", -2, "si2bi", 101L, "bi2vc", "-12345")), ImmutableMap.of(-2, asMap("ti2bi", null, "int2bi", -2323L, "float2double", -1.5, "add", null)), 1));
    } else if (usingTeradataJdbcDriver(connection)) {
        expectedRows = ImmutableList.of(row(-1, 2, -3L, 100, -101L, 2323L, "12345", 0.5, "[\"as is\",-1,100,2323,\"12345\"]", "[[2,-101,\"12345\"]]", "{\"2\":[-3,2323,0.5,null]}", 1), row(1, -2, null, -100, 101L, -2323L, "-12345", -1.5, "[null,1,-100,-2323,\"-12345\"]", "[[-2,101,\"-12345\"]]", "{\"-2\":[null,-2323,-1.5,null]}", 1));
    } else {
        throw new IllegalStateException();
    }
    // test primitive values
    assertThat(queryResult.project(1, 2, 3, 4, 5, 6, 7, 8, 12)).containsOnly(project(expectedRows, 1, 2, 3, 4, 5, 6, 7, 8, 12));
    // test structural values (tempto can't handle map and row)
    assertEqualsIgnoreOrder(queryResult.column(9), column(expectedRows, 9), "row_to_row field is not equal");
    if (usingPrestoJdbcDriver(connection)) {
        assertEqualsIgnoreOrder(extract(queryResult.column(10)), column(expectedRows, 10), "list_to_list field is not equal");
    } else if (usingTeradataJdbcDriver(connection)) {
        assertEqualsIgnoreOrder(queryResult.column(10), column(expectedRows, 10), "list_to_list field is not equal");
    } else {
        throw new IllegalStateException();
    }
    assertEqualsIgnoreOrder(queryResult.column(11), column(expectedRows, 11), "map_to_map field is not equal");
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Connection(java.sql.Connection) Row(io.prestodb.tempto.assertions.QueryAssert.Row)

Example 3 with Row

use of io.prestodb.tempto.assertions.QueryAssert.Row in project presto by prestodb.

the class TestCsv method assertSelect.

private static void assertSelect(String query, String tableName) {
    QueryResult expected = query(format(query, "tpch." + TPCH_SCHEMA + ".lineitem"));
    List<Row> expectedRows = expected.rows().stream().map((columns) -> row(columns.toArray())).collect(toImmutableList());
    QueryResult actual = query(format(query, tableName));
    List<Row> actualRows = actual.rows().stream().map((columns) -> row(columns.toArray())).collect(toImmutableList());
    assertThat(actual).hasColumns(expected.getColumnTypes()).containsOnly(expectedRows);
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) List(java.util.List) QueryExecutor.query(io.prestodb.tempto.query.QueryExecutor.query) Row(io.prestodb.tempto.assertions.QueryAssert.Row) QueryAssert.assertThat(io.prestodb.tempto.assertions.QueryAssert.assertThat) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) STORAGE_FORMATS(com.facebook.presto.tests.TestGroups.STORAGE_FORMATS) Test(org.testng.annotations.Test) Row.row(io.prestodb.tempto.assertions.QueryAssert.Row.row) ProductTest(io.prestodb.tempto.ProductTest) String.format(java.lang.String.format) QueryResult(io.prestodb.tempto.query.QueryResult) Row(io.prestodb.tempto.assertions.QueryAssert.Row)

Aggregations

Row (io.prestodb.tempto.assertions.QueryAssert.Row)3 QueryResult (io.prestodb.tempto.query.QueryResult)3 STORAGE_FORMATS (com.facebook.presto.tests.TestGroups.STORAGE_FORMATS)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ProductTest (io.prestodb.tempto.ProductTest)2 Row.row (io.prestodb.tempto.assertions.QueryAssert.Row.row)2 QueryAssert.assertThat (io.prestodb.tempto.assertions.QueryAssert.assertThat)2 QueryExecutor.query (io.prestodb.tempto.query.QueryExecutor.query)2 String.format (java.lang.String.format)2 Connection (java.sql.Connection)2 List (java.util.List)2 Test (org.testng.annotations.Test)2 JdbcDriverUtils (com.facebook.presto.tests.utils.JdbcDriverUtils)1 JdbcDriverUtils.setSessionProperty (com.facebook.presto.tests.utils.JdbcDriverUtils.setSessionProperty)1 QueryExecutors.onHive (com.facebook.presto.tests.utils.QueryExecutors.onHive)1 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 QueryExecutor.defaultQueryExecutor (io.prestodb.tempto.query.QueryExecutor.defaultQueryExecutor)1 SQLException (java.sql.SQLException)1 Locale (java.util.Locale)1