Skip to content

Commit

Permalink
Add tests for sum, min, max and avg queries running on native workers
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasmanova committed Sep 12, 2020
1 parent 926df09 commit ec9b5cf
Showing 1 changed file with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,31 @@ private static QueryRunner createQueryRunner()
private static QueryRunner createQueryRunner(Optional<String> prestoServerPath, Optional<Path> baseDataDir)
throws Exception
{
if (!prestoServerPath.isPresent()) {
return HiveQueryRunner.createQueryRunner(
ImmutableList.of(NATION),
ImmutableMap.of(),
"sql-standard",
ImmutableMap.of("hive.storage-format", "DWRF"),
baseDataDir);
if (prestoServerPath.isPresent()) {
checkArgument(baseDataDir.isPresent(), "Path to data files must be specified when testing external workers");
}

checkArgument(baseDataDir.isPresent(), "Path to data files must be specified when testing external workers");

// Make TPC-H tables in DWRF format using Java-based workers
HiveQueryRunner.createQueryRunner(
DistributedQueryRunner defaultQueryRunner = HiveQueryRunner.createQueryRunner(
ImmutableList.of(NATION),
ImmutableMap.of(),
"sql-standard",
ImmutableMap.of("hive.storage-format", "DWRF"),
baseDataDir).close();
baseDataDir);

// DWRF doesn't support date type. Convert date columns to varchar for lineitem and orders.
createLineitem(defaultQueryRunner);
createOrders(defaultQueryRunner);

if (!prestoServerPath.isPresent()) {
return defaultQueryRunner;
}

defaultQueryRunner.close();

Path tempDirectoryPath = Files.createTempDirectory(TestHiveExternalWorkersQueries.class.getSimpleName());

// Make query runner with external workers for tests
DistributedQueryRunner queryRunner = HiveQueryRunner.createQueryRunner(ImmutableList.of(NATION),
DistributedQueryRunner queryRunner = HiveQueryRunner.createQueryRunner(ImmutableList.of(),
ImmutableMap.of("optimizer.optimize-hash-generation", "false"),
ImmutableMap.of(),
"sql-standard",
Expand Down Expand Up @@ -104,6 +106,27 @@ private static QueryRunner createQueryRunner(Optional<String> prestoServerPath,
return queryRunner;
}

private static void createLineitem(QueryRunner queryRunner)
{
if (!queryRunner.tableExists(queryRunner.getDefaultSession(), "lineitem")) {
queryRunner.execute("CREATE TABLE lineitem AS " +
"SELECT orderkey, partkey, suppkey, linenumber, quantity, extendedprice, discount, tax, " +
" returnflag, linestatus, cast(shipdate as varchar) as shipdate, cast(commitdate as varchar) as commitdate, " +
" cast(receiptdate as varchar) as receiptdate, shipinstruct, shipmode, comment " +
"FROM tpch.tiny.lineitem");
}
}

private static void createOrders(QueryRunner queryRunner)
{
if (!queryRunner.tableExists(queryRunner.getDefaultSession(), "orders")) {
queryRunner.execute("CREATE TABLE orders AS " +
"SELECT orderkey, custkey, orderstatus, totalprice, cast(orderdate as varchar) as orderdate, " +
" orderpriority, clerk, shippriority, comment " +
"FROM tpch.tiny.orders");
}
}

@Test
public void testFiltersAndProjections()
{
Expand All @@ -123,5 +146,13 @@ public void testAggregations()
{
assertQuery("SELECT count(*) FROM nation");
assertQuery("SELECT regionkey, count(*) FROM nation GROUP BY regionkey");

assertQuery("SELECT avg(discount), avg(quantity) FROM lineitem");
assertQuery("SELECT linenumber, avg(discount), avg(quantity) FROM lineitem GROUP BY linenumber");

assertQuery("SELECT sum(totalprice) FROM orders");
assertQuery("SELECT orderpriority, sum(totalprice) FROM orders GROUP BY orderpriority");

assertQuery("SELECT custkey, min(totalprice), max(orderkey) FROM orders GROUP BY custkey");
}
}

0 comments on commit ec9b5cf

Please sign in to comment.