|
13 | 13 | */ |
14 | 14 | package io.trino.plugin.tpcds; |
15 | 15 |
|
16 | | -import com.google.common.collect.ImmutableMap; |
17 | 16 | import io.airlift.log.Logger; |
18 | | -import io.trino.Session; |
19 | 17 | import io.trino.testing.DistributedQueryRunner; |
20 | 18 | import io.trino.testing.QueryRunner; |
21 | 19 |
|
22 | | -import java.util.Map; |
23 | | - |
| 20 | +import static io.airlift.testing.Closeables.closeAllSuppress; |
24 | 21 | import static io.trino.testing.TestingSession.testSessionBuilder; |
25 | 22 |
|
26 | 23 | public final class TpcdsQueryRunner |
27 | 24 | { |
28 | 25 | private TpcdsQueryRunner() {} |
29 | 26 |
|
30 | | - // TODO convert to builder |
31 | | - public static QueryRunner createQueryRunner() |
32 | | - throws Exception |
| 27 | + public static Builder builder() |
33 | 28 | { |
34 | | - return createQueryRunner(ImmutableMap.of()); |
| 29 | + return new Builder(); |
35 | 30 | } |
36 | 31 |
|
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> |
40 | 34 | { |
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()); |
55 | 42 | } |
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 | + } |
59 | 58 | } |
60 | 59 | } |
61 | 60 |
|
62 | 61 | public static void main(String[] args) |
63 | 62 | throws Exception |
64 | 63 | { |
65 | | - QueryRunner queryRunner = createQueryRunner(ImmutableMap.of("http-server.http.port", "8080")); |
| 64 | + QueryRunner queryRunner = builder() |
| 65 | + .addCoordinatorProperty("http-server.http.port", "8080") |
| 66 | + .build(); |
66 | 67 | Logger log = Logger.get(TpcdsQueryRunner.class); |
67 | 68 | log.info("======== SERVER STARTED ========"); |
68 | 69 | log.info("\n====\n%s\n====", queryRunner.getCoordinator().getBaseUrl()); |
|
0 commit comments