Skip to content

Commit

Permalink
Add builder to MemoryQueryRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
losipiuk committed Mar 2, 2022
1 parent a0d8caa commit 9d67738
Showing 1 changed file with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.plugin.memory;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.airlift.log.Logger;
import io.airlift.log.Logging;
Expand All @@ -21,12 +22,14 @@
import io.trino.testing.DistributedQueryRunner;
import io.trino.tpch.TpchTable;

import java.util.List;
import java.util.Map;

import static io.airlift.testing.Closeables.closeAllSuppress;
import static io.trino.plugin.tpch.TpchMetadata.TINY_SCHEMA_NAME;
import static io.trino.testing.QueryAssertions.copyTpchTables;
import static io.trino.testing.TestingSession.testSessionBuilder;
import static java.util.Objects.requireNonNull;

public final class MemoryQueryRunner
{
Expand All @@ -39,29 +42,62 @@ public static DistributedQueryRunner createMemoryQueryRunner(
Iterable<TpchTable<?>> tables)
throws Exception
{
Session session = testSessionBuilder()
.setCatalog(CATALOG)
.setSchema("default")
.build();

DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session)
return builder()
.setExtraProperties(extraProperties)
.setInitialTables(tables)
.build();
}

public static Builder builder()
{
return new Builder();
}

public static class Builder
extends DistributedQueryRunner.Builder<Builder>
{
private List<TpchTable<?>> initialTables = ImmutableList.of();

protected Builder()
{
super(createSession());
}

try {
queryRunner.installPlugin(new MemoryPlugin());
queryRunner.createCatalog(CATALOG, "memory", ImmutableMap.of());
public Builder setInitialTables(Iterable<TpchTable<?>> initialTables)
{
this.initialTables = ImmutableList.copyOf(requireNonNull(initialTables, "initialTables is null"));
return self();
}

queryRunner.installPlugin(new TpchPlugin());
queryRunner.createCatalog("tpch", "tpch", ImmutableMap.of());
@Override
public DistributedQueryRunner build()
throws Exception
{
DistributedQueryRunner queryRunner = super.build();

copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, session, tables);
try {
queryRunner.installPlugin(new MemoryPlugin());
queryRunner.createCatalog(CATALOG, "memory", ImmutableMap.of());

return queryRunner;
queryRunner.installPlugin(new TpchPlugin());
queryRunner.createCatalog("tpch", "tpch", ImmutableMap.of());

copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, createSession(), initialTables);

return queryRunner;
}
catch (Exception e) {
closeAllSuppress(e, queryRunner);
throw e;
}
}
catch (Exception e) {
closeAllSuppress(e, queryRunner);
throw e;

private static Session createSession()
{
return testSessionBuilder()
.setCatalog(CATALOG)
.setSchema("default")
.build();
}
}

Expand Down

0 comments on commit 9d67738

Please sign in to comment.