Skip to content

Commit 73ff9f9

Browse files
Convert MSQTerminalStageSpecFactory into an interface (#16996)
* Convert MSQTerminalStageSpecFactory into an interface * Rename class and remove useless constructor
1 parent 476b205 commit 73ff9f9

File tree

6 files changed

+45
-19
lines changed

6 files changed

+45
-19
lines changed

extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/MSQSqlModule.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void configure(Binder binder)
5454
// We want this module to bring InputSourceModule along for the ride.
5555
binder.install(new InputSourceModule());
5656

57-
binder.bind(MSQTerminalStageSpecFactory.class).toInstance(new MSQTerminalStageSpecFactory());
57+
binder.bind(MSQTerminalStageSpecFactory.class).to(SegmentGenerationTerminalStageSpecFactory.class).in(LazySingleton.class);
5858

5959
binder.bind(MSQTaskSqlEngine.class).in(LazySingleton.class);
6060

extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/MSQTerminalStageSpecFactory.java

+3-8
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,14 @@
1919

2020
package org.apache.druid.msq.guice;
2121

22-
import org.apache.druid.msq.indexing.destination.SegmentGenerationStageSpec;
2322
import org.apache.druid.msq.indexing.destination.TerminalStageSpec;
2423
import org.apache.druid.sql.calcite.planner.PlannerContext;
2524
import org.apache.druid.sql.calcite.rel.DruidQuery;
2625

27-
public class MSQTerminalStageSpecFactory
26+
public interface MSQTerminalStageSpecFactory
2827
{
2928
/**
30-
* Creates a {@link TerminalStageSpec} which determines the final of a query. Currently, always returns a segment
31-
* generation spec, but this can be used to configure a wide range of behaviours.
29+
* Creates a {@link TerminalStageSpec} which determines the final of a query.
3230
*/
33-
public TerminalStageSpec createTerminalStageSpec(DruidQuery druidQuery, PlannerContext plannerContext)
34-
{
35-
return SegmentGenerationStageSpec.instance();
36-
}
31+
TerminalStageSpec createTerminalStageSpec(DruidQuery druidQuery, PlannerContext plannerContext);
3732
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.druid.msq.guice;
21+
22+
import org.apache.druid.msq.indexing.destination.SegmentGenerationStageSpec;
23+
import org.apache.druid.msq.indexing.destination.TerminalStageSpec;
24+
import org.apache.druid.sql.calcite.planner.PlannerContext;
25+
import org.apache.druid.sql.calcite.rel.DruidQuery;
26+
27+
/**
28+
* Configures ingestion queries to create new segments with the results in all cases.
29+
*/
30+
public class SegmentGenerationTerminalStageSpecFactory implements MSQTerminalStageSpecFactory
31+
{
32+
@Override
33+
public TerminalStageSpec createTerminalStageSpec(DruidQuery druidQuery, PlannerContext plannerContext)
34+
{
35+
return SegmentGenerationStageSpec.instance();
36+
}
37+
}

extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/MSQTaskSqlEngine.java

-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.apache.druid.msq.sql;
2121

2222
import com.fasterxml.jackson.databind.ObjectMapper;
23-
import com.google.common.annotations.VisibleForTesting;
2423
import com.google.common.collect.ImmutableList;
2524
import com.google.common.collect.ImmutableSet;
2625
import com.google.inject.Inject;
@@ -90,12 +89,6 @@ public class MSQTaskSqlEngine implements SqlEngine
9089
private final MSQTerminalStageSpecFactory terminalStageSpecFactory;
9190

9291
@Inject
93-
public MSQTaskSqlEngine(final OverlordClient overlordClient, final ObjectMapper jsonMapper)
94-
{
95-
this(overlordClient, jsonMapper, new MSQTerminalStageSpecFactory());
96-
}
97-
98-
@VisibleForTesting
9992
public MSQTaskSqlEngine(
10093
final OverlordClient overlordClient,
10194
final ObjectMapper jsonMapper,

extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/TestMSQSqlModule.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.druid.guice.LazySingleton;
2727
import org.apache.druid.initialization.ServerInjectorBuilderTest.TestDruidModule;
2828
import org.apache.druid.msq.guice.MultiStageQuery;
29+
import org.apache.druid.msq.guice.SegmentGenerationTerminalStageSpecFactory;
2930
import org.apache.druid.msq.sql.MSQTaskSqlEngine;
3031
import org.apache.druid.msq.test.MSQTestBase;
3132
import org.apache.druid.msq.test.MSQTestOverlordServiceClient;
@@ -53,7 +54,7 @@ public MSQTaskSqlEngine createEngine(
5354
ObjectMapper queryJsonMapper,
5455
MSQTestOverlordServiceClient indexingServiceClient)
5556
{
56-
return new MSQTaskSqlEngine(indexingServiceClient, queryJsonMapper);
57+
return new MSQTaskSqlEngine(indexingServiceClient, queryJsonMapper, new SegmentGenerationTerminalStageSpecFactory());
5758
}
5859

5960
@Provides

extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@
9191
import org.apache.druid.msq.guice.MSQExternalDataSourceModule;
9292
import org.apache.druid.msq.guice.MSQIndexingModule;
9393
import org.apache.druid.msq.guice.MSQSqlModule;
94-
import org.apache.druid.msq.guice.MSQTerminalStageSpecFactory;
9594
import org.apache.druid.msq.guice.MultiStageQuery;
95+
import org.apache.druid.msq.guice.SegmentGenerationTerminalStageSpecFactory;
9696
import org.apache.druid.msq.indexing.InputChannelFactory;
9797
import org.apache.druid.msq.indexing.MSQControllerTask;
9898
import org.apache.druid.msq.indexing.MSQSpec;
@@ -551,7 +551,7 @@ public String getFormatString()
551551
final SqlEngine engine = new MSQTaskSqlEngine(
552552
indexingServiceClient,
553553
qf.queryJsonMapper().copy().registerModules(new MSQSqlModule().getJacksonModules()),
554-
new MSQTerminalStageSpecFactory()
554+
new SegmentGenerationTerminalStageSpecFactory()
555555
);
556556

557557
PlannerFactory plannerFactory = new PlannerFactory(

0 commit comments

Comments
 (0)