Skip to content

Commit b42773b

Browse files
committed
Convert TpcdsQueryRunner to builder
1 parent e7f87a1 commit b42773b

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

plugin/trino-tpcds/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@
133133
<scope>test</scope>
134134
</dependency>
135135

136+
<dependency>
137+
<groupId>io.airlift</groupId>
138+
<artifactId>testing</artifactId>
139+
<scope>test</scope>
140+
</dependency>
141+
136142
<dependency>
137143
<groupId>io.trino</groupId>
138144
<artifactId>trino-main</artifactId>

plugin/trino-tpcds/src/test/java/io/trino/plugin/tpcds/TestTpcds.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class TestTpcds
3737
protected QueryRunner createQueryRunner()
3838
throws Exception
3939
{
40-
return TpcdsQueryRunner.createQueryRunner();
40+
return TpcdsQueryRunner.builder().build();
4141
}
4242

4343
@Test

plugin/trino-tpcds/src/test/java/io/trino/plugin/tpcds/TpcdsQueryRunner.java

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,57 @@
1313
*/
1414
package io.trino.plugin.tpcds;
1515

16-
import com.google.common.collect.ImmutableMap;
1716
import io.airlift.log.Logger;
18-
import io.trino.Session;
1917
import io.trino.testing.DistributedQueryRunner;
2018
import io.trino.testing.QueryRunner;
2119

22-
import java.util.Map;
23-
20+
import static io.airlift.testing.Closeables.closeAllSuppress;
2421
import static io.trino.testing.TestingSession.testSessionBuilder;
2522

2623
public final class TpcdsQueryRunner
2724
{
2825
private TpcdsQueryRunner() {}
2926

30-
// TODO convert to builder
31-
public static QueryRunner createQueryRunner()
32-
throws Exception
27+
public static Builder builder()
3328
{
34-
return createQueryRunner(ImmutableMap.of());
29+
return new Builder();
3530
}
3631

37-
// TODO convert to builder
38-
private static QueryRunner createQueryRunner(Map<String, String> coordinatorProperties)
39-
throws Exception
32+
public static final class Builder
33+
extends DistributedQueryRunner.Builder<Builder>
4034
{
41-
Session session = testSessionBuilder()
42-
.setSource("test")
43-
.setCatalog("tpcds")
44-
.setSchema("sf1")
45-
.build();
46-
47-
QueryRunner queryRunner = DistributedQueryRunner.builder(session)
48-
.setCoordinatorProperties(coordinatorProperties)
49-
.build();
50-
51-
try {
52-
queryRunner.installPlugin(new TpcdsPlugin());
53-
queryRunner.createCatalog("tpcds", "tpcds");
54-
return queryRunner;
35+
private Builder()
36+
{
37+
super(testSessionBuilder()
38+
.setSource("test")
39+
.setCatalog("tpcds")
40+
.setSchema("sf1")
41+
.build());
5542
}
56-
catch (Exception e) {
57-
queryRunner.close();
58-
throw e;
43+
44+
@Override
45+
public DistributedQueryRunner build()
46+
throws Exception
47+
{
48+
DistributedQueryRunner queryRunner = super.build();
49+
try {
50+
queryRunner.installPlugin(new TpcdsPlugin());
51+
queryRunner.createCatalog("tpcds", "tpcds");
52+
return queryRunner;
53+
}
54+
catch (Throwable e) {
55+
closeAllSuppress(e, queryRunner);
56+
throw e;
57+
}
5958
}
6059
}
6160

6261
public static void main(String[] args)
6362
throws Exception
6463
{
65-
QueryRunner queryRunner = createQueryRunner(ImmutableMap.of("http-server.http.port", "8080"));
64+
QueryRunner queryRunner = builder()
65+
.addCoordinatorProperty("http-server.http.port", "8080")
66+
.build();
6667
Logger log = Logger.get(TpcdsQueryRunner.class);
6768
log.info("======== SERVER STARTED ========");
6869
log.info("\n====\n%s\n====", queryRunner.getCoordinator().getBaseUrl());

0 commit comments

Comments
 (0)