use of io.prestodb.tempto.query.QueryResult in project urban-eureka by errir503.
the class TestSelect method testSelectNation.
@Test(groups = { SQL_SERVER, PROFILE_SPECIFIC_TESTS })
public void testSelectNation() {
String sql = format("SELECT n_nationkey, n_name, n_regionkey, n_comment FROM %s", NATION_TABLE_NAME);
QueryResult queryResult = onPresto().executeQuery(sql);
assertThat(queryResult).matches(PRESTO_NATION_RESULT);
}
use of io.prestodb.tempto.query.QueryResult in project urban-eureka by errir503.
the class TestSelect method testNationSelfInnerJoin.
@Test(groups = { SQL_SERVER, PROFILE_SPECIFIC_TESTS })
public void testNationSelfInnerJoin() {
String sql = format("SELECT n1.n_name, n2.n_regionkey FROM %s n1 JOIN " + "%s n2 ON n1.n_nationkey = n2.n_regionkey " + "WHERE n1.n_nationkey=3", NATION_TABLE_NAME, NATION_TABLE_NAME);
QueryResult queryResult = onPresto().executeQuery(sql);
assertThat(queryResult).containsOnly(row("CANADA", 3), row("CANADA", 3), row("CANADA", 3), row("CANADA", 3), row("CANADA", 3));
}
use of io.prestodb.tempto.query.QueryResult in project urban-eureka by errir503.
the class TestSelect method testCreateTableAsSelect.
@Test(groups = { SQL_SERVER, PROFILE_SPECIFIC_TESTS })
public void testCreateTableAsSelect() {
String sql = format("CREATE TABLE %s AS SELECT * FROM %s", CREATE_TABLE_AS_SELECT, NATION_TABLE_NAME);
onPresto().executeQuery(sql);
sql = format("SELECT n_nationkey, n_name, n_regionkey, n_comment FROM %s.%s.%s", "master", KEY_SPACE, CTAS_TABLE_NAME);
QueryResult queryResult = onSqlServer().executeQuery(sql);
assertThat(queryResult).matches(PRESTO_NATION_RESULT);
}
use of io.prestodb.tempto.query.QueryResult in project urban-eureka by errir503.
the class TestSelect method testNationJoinRegion.
@Test(groups = { SQL_SERVER, PROFILE_SPECIFIC_TESTS })
public void testNationJoinRegion() {
String sql = format("SELECT c.n_name, t.name FROM %s c JOIN " + "tpch.tiny.region t ON c.n_regionkey = t.regionkey " + "WHERE c.n_nationkey=3", NATION_TABLE_NAME);
QueryResult queryResult = onPresto().executeQuery(sql);
assertThat(queryResult).containsOnly(row("CANADA", "AMERICA"));
}
use of io.prestodb.tempto.query.QueryResult in project urban-eureka by errir503.
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");
}
Aggregations