From 22d8a4b872e3561a693e02d71694bccf52410bf1 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 6 Aug 2024 07:37:24 +0000 Subject: [PATCH] add compositemodule --- .../initialization/CompositeDruidModule.java | 54 +++++++++++++++++++ .../apache/druid/quidem/TestSqlModule.java | 2 - .../sql/calcite/util/SqlTestFramework.java | 8 +-- 3 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 processing/src/main/java/org/apache/druid/initialization/CompositeDruidModule.java diff --git a/processing/src/main/java/org/apache/druid/initialization/CompositeDruidModule.java b/processing/src/main/java/org/apache/druid/initialization/CompositeDruidModule.java new file mode 100644 index 00000000000..84c9490fe44 --- /dev/null +++ b/processing/src/main/java/org/apache/druid/initialization/CompositeDruidModule.java @@ -0,0 +1,54 @@ +/* + * 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.initialization; + +import com.fasterxml.jackson.databind.Module; +import com.google.common.collect.ImmutableList; +import com.google.inject.Binder; + +import java.util.List; + +public class CompositeDruidModule implements DruidModule +{ + protected final DruidModule[] modules; + + public CompositeDruidModule(DruidModule... modules) + { + this.modules = modules; + } + + @Override + public List getJacksonModules() + { + ImmutableList.Builder builder = ImmutableList.builder(); + for (DruidModule druidModule : modules) { + builder.addAll(druidModule.getJacksonModules()); + } + return builder.build(); + } + + @Override + public void configure(Binder binder) + { + for (DruidModule druidModule : modules) { + binder.install(druidModule); + } + } +} diff --git a/sql/src/test/java/org/apache/druid/quidem/TestSqlModule.java b/sql/src/test/java/org/apache/druid/quidem/TestSqlModule.java index 51e56258785..2b4ca258507 100644 --- a/sql/src/test/java/org/apache/druid/quidem/TestSqlModule.java +++ b/sql/src/test/java/org/apache/druid/quidem/TestSqlModule.java @@ -25,7 +25,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.inject.Binder; import com.google.inject.TypeLiteral; -import org.apache.druid.guice.BuiltInTypesModule; import org.apache.druid.guice.LazySingleton; import org.apache.druid.initialization.ServerInjectorBuilderTest.TestDruidModule; import org.apache.druid.java.util.emitter.service.ServiceEmitter; @@ -68,6 +67,5 @@ public class TestSqlModule extends TestDruidModule binder.bind(AuthenticatorMapper.class).toInstance(CalciteTests.TEST_AUTHENTICATOR_MAPPER); binder.bind(AuthorizerMapper.class).toInstance(CalciteTests.TEST_AUTHORIZER_MAPPER); binder.bind(Escalator.class).toInstance(CalciteTests.TEST_AUTHENTICATOR_ESCALATOR); - binder.install(new BuiltInTypesModule()); } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java index 22e5057477e..9f61004badd 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java @@ -26,13 +26,14 @@ import com.google.inject.Binder; import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.Provides; +import org.apache.druid.guice.BuiltInTypesModule; import org.apache.druid.guice.DruidInjectorBuilder; import org.apache.druid.guice.ExpressionModule; import org.apache.druid.guice.LazySingleton; import org.apache.druid.guice.SegmentWranglerModule; import org.apache.druid.guice.StartupInjectorBuilder; +import org.apache.druid.initialization.CompositeDruidModule; import org.apache.druid.initialization.CoreInjectorBuilder; -import org.apache.druid.initialization.DruidModule; import org.apache.druid.initialization.ServiceInjectorBuilder; import org.apache.druid.java.util.common.RE; import org.apache.druid.java.util.common.io.Closer; @@ -545,22 +546,23 @@ public class SqlTestFramework * This is an intermediate solution: the ultimate solution is to create things * in Guice itself. */ - private class TestSetupModule implements DruidModule + private class TestSetupModule extends CompositeDruidModule { private final Builder builder; public TestSetupModule(Builder builder) { + super(new BuiltInTypesModule(), new TestSqlModule()); this.builder = builder; } @Override public void configure(Binder binder) { + super.configure(binder); binder.bind(DruidOperatorTable.class).in(LazySingleton.class); binder.bind(DataSegment.PruneSpecsHolder.class).toInstance(DataSegment.PruneSpecsHolder.DEFAULT); binder.bind(DefaultColumnFormatConfig.class).toInstance(new DefaultColumnFormatConfig(null, null)); - binder.install(new TestSqlModule()); } @Provides