Skip to content

Commit

Permalink
Convert MSQTerminalStageSpecFactory into an interface (apache#16996)
Browse files Browse the repository at this point in the history
* Convert MSQTerminalStageSpecFactory into an interface

* Rename class and remove useless constructor
  • Loading branch information
adarshsanjeev authored Sep 6, 2024
1 parent 476b205 commit 73ff9f9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,7 +54,7 @@ public MSQTaskSqlEngine createEngine(
ObjectMapper queryJsonMapper,
MSQTestOverlordServiceClient indexingServiceClient)
{
return new MSQTaskSqlEngine(indexingServiceClient, queryJsonMapper);
return new MSQTaskSqlEngine(indexingServiceClient, queryJsonMapper, new SegmentGenerationTerminalStageSpecFactory());
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 73ff9f9

Please sign in to comment.