From 73ff9f9047d69d55bf880e629efeec07ce92e528 Mon Sep 17 00:00:00 2001 From: Adarsh Sanjeev Date: Fri, 6 Sep 2024 09:56:35 +0530 Subject: [PATCH] Convert MSQTerminalStageSpecFactory into an interface (#16996) * Convert MSQTerminalStageSpecFactory into an interface * Rename class and remove useless constructor --- .../apache/druid/msq/guice/MSQSqlModule.java | 2 +- .../guice/MSQTerminalStageSpecFactory.java | 11 ++---- ...entGenerationTerminalStageSpecFactory.java | 37 +++++++++++++++++++ .../druid/msq/sql/MSQTaskSqlEngine.java | 7 ---- .../druid/msq/exec/TestMSQSqlModule.java | 3 +- .../apache/druid/msq/test/MSQTestBase.java | 4 +- 6 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/SegmentGenerationTerminalStageSpecFactory.java diff --git a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/MSQSqlModule.java b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/MSQSqlModule.java index a523fd6c012e..5d837940e19e 100644 --- a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/MSQSqlModule.java +++ b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/MSQSqlModule.java @@ -54,7 +54,7 @@ public void configure(Binder binder) // We want this module to bring InputSourceModule along for the ride. binder.install(new InputSourceModule()); - binder.bind(MSQTerminalStageSpecFactory.class).toInstance(new MSQTerminalStageSpecFactory()); + binder.bind(MSQTerminalStageSpecFactory.class).to(SegmentGenerationTerminalStageSpecFactory.class).in(LazySingleton.class); binder.bind(MSQTaskSqlEngine.class).in(LazySingleton.class); diff --git a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/MSQTerminalStageSpecFactory.java b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/MSQTerminalStageSpecFactory.java index d347322a7fb4..d5a1bd79455a 100644 --- a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/MSQTerminalStageSpecFactory.java +++ b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/MSQTerminalStageSpecFactory.java @@ -19,19 +19,14 @@ package org.apache.druid.msq.guice; -import org.apache.druid.msq.indexing.destination.SegmentGenerationStageSpec; import org.apache.druid.msq.indexing.destination.TerminalStageSpec; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.DruidQuery; -public class MSQTerminalStageSpecFactory +public interface MSQTerminalStageSpecFactory { /** - * Creates a {@link TerminalStageSpec} which determines the final of a query. Currently, always returns a segment - * generation spec, but this can be used to configure a wide range of behaviours. + * Creates a {@link TerminalStageSpec} which determines the final of a query. */ - public TerminalStageSpec createTerminalStageSpec(DruidQuery druidQuery, PlannerContext plannerContext) - { - return SegmentGenerationStageSpec.instance(); - } + TerminalStageSpec createTerminalStageSpec(DruidQuery druidQuery, PlannerContext plannerContext); } diff --git a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/SegmentGenerationTerminalStageSpecFactory.java b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/SegmentGenerationTerminalStageSpecFactory.java new file mode 100644 index 000000000000..f761c0616a6c --- /dev/null +++ b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/guice/SegmentGenerationTerminalStageSpecFactory.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.msq.guice; + +import org.apache.druid.msq.indexing.destination.SegmentGenerationStageSpec; +import org.apache.druid.msq.indexing.destination.TerminalStageSpec; +import org.apache.druid.sql.calcite.planner.PlannerContext; +import org.apache.druid.sql.calcite.rel.DruidQuery; + +/** + * Configures ingestion queries to create new segments with the results in all cases. + */ +public class SegmentGenerationTerminalStageSpecFactory implements MSQTerminalStageSpecFactory +{ + @Override + public TerminalStageSpec createTerminalStageSpec(DruidQuery druidQuery, PlannerContext plannerContext) + { + return SegmentGenerationStageSpec.instance(); + } +} diff --git a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/MSQTaskSqlEngine.java b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/MSQTaskSqlEngine.java index 01d87805f784..9e07a909f4e5 100644 --- a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/MSQTaskSqlEngine.java +++ b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/MSQTaskSqlEngine.java @@ -20,7 +20,6 @@ package org.apache.druid.msq.sql; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.inject.Inject; @@ -90,12 +89,6 @@ public class MSQTaskSqlEngine implements SqlEngine private final MSQTerminalStageSpecFactory terminalStageSpecFactory; @Inject - public MSQTaskSqlEngine(final OverlordClient overlordClient, final ObjectMapper jsonMapper) - { - this(overlordClient, jsonMapper, new MSQTerminalStageSpecFactory()); - } - - @VisibleForTesting public MSQTaskSqlEngine( final OverlordClient overlordClient, final ObjectMapper jsonMapper, diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/TestMSQSqlModule.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/TestMSQSqlModule.java index e5a0f1cb06ea..5bf4bbd44dc4 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/TestMSQSqlModule.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/TestMSQSqlModule.java @@ -26,6 +26,7 @@ import org.apache.druid.guice.LazySingleton; import org.apache.druid.initialization.ServerInjectorBuilderTest.TestDruidModule; import org.apache.druid.msq.guice.MultiStageQuery; +import org.apache.druid.msq.guice.SegmentGenerationTerminalStageSpecFactory; import org.apache.druid.msq.sql.MSQTaskSqlEngine; import org.apache.druid.msq.test.MSQTestBase; import org.apache.druid.msq.test.MSQTestOverlordServiceClient; @@ -53,7 +54,7 @@ public MSQTaskSqlEngine createEngine( ObjectMapper queryJsonMapper, MSQTestOverlordServiceClient indexingServiceClient) { - return new MSQTaskSqlEngine(indexingServiceClient, queryJsonMapper); + return new MSQTaskSqlEngine(indexingServiceClient, queryJsonMapper, new SegmentGenerationTerminalStageSpecFactory()); } @Provides diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java index fe725528f404..bb8691b93225 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java @@ -91,8 +91,8 @@ import org.apache.druid.msq.guice.MSQExternalDataSourceModule; import org.apache.druid.msq.guice.MSQIndexingModule; import org.apache.druid.msq.guice.MSQSqlModule; -import org.apache.druid.msq.guice.MSQTerminalStageSpecFactory; import org.apache.druid.msq.guice.MultiStageQuery; +import org.apache.druid.msq.guice.SegmentGenerationTerminalStageSpecFactory; import org.apache.druid.msq.indexing.InputChannelFactory; import org.apache.druid.msq.indexing.MSQControllerTask; import org.apache.druid.msq.indexing.MSQSpec; @@ -551,7 +551,7 @@ public String getFormatString() final SqlEngine engine = new MSQTaskSqlEngine( indexingServiceClient, qf.queryJsonMapper().copy().registerModules(new MSQSqlModule().getJacksonModules()), - new MSQTerminalStageSpecFactory() + new SegmentGenerationTerminalStageSpecFactory() ); PlannerFactory plannerFactory = new PlannerFactory(