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);
}
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");
}
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);
}
Aggregations