Allow query through router when load moving average extension (#11276)
* init commit
* change NoopQuerySegmentWalker name
* change doc
* move NoopQuerySegmentWalker and add document
* fix doc
Co-authored-by: yuanyi <yuanyi@freewheel.tv>
diff --git a/docs/development/extensions-contrib/moving-average-query.md b/docs/development/extensions-contrib/moving-average-query.md
index 083d656..aa7fdb8 100644
--- a/docs/development/extensions-contrib/moving-average-query.md
+++ b/docs/development/extensions-contrib/moving-average-query.md
@@ -52,14 +52,14 @@
## Operations
### Installation
-Use [pull-deps](../../operations/pull-deps.md) tool shipped with Druid to install this [extension](../../development/extensions.md#community-extensions) on all Druid broker nodes.
+Use [pull-deps](../../operations/pull-deps.md) tool shipped with Druid to install this [extension](../../development/extensions.md#community-extensions) on all Druid broker and router nodes.
```bash
java -classpath "<your_druid_dir>/lib/*" org.apache.druid.cli.Main tools pull-deps -c org.apache.druid.extensions.contrib:druid-moving-average-query:{VERSION}
```
### Enabling
-After installation, to enable this extension, just add `druid-moving-average-query` to `druid.extensions.loadList` in brokers' `runtime.properties` file and then restart broker nodes.
+After installation, to enable this extension, just add `druid-moving-average-query` to `druid.extensions.loadList` in broker and routers' `runtime.properties` file and then restart broker and router nodes.
For example:
@@ -71,7 +71,6 @@
There are currently no configuration properties specific to Moving Average.
## Limitations
-* movingAverage is not supported by Druid router(including the Web Console), all queries should be sent to broker nodes directly.
* movingAverage is missing support for the following groupBy properties: `subtotalsSpec`, `virtualColumns`.
* movingAverage is missing support for the following timeseries properties: `descending`.
* movingAverage is missing support for [SQL-compatible null handling](https://github.com/apache/druid/issues/4349) (So setting druid.generic.useDefaultValueForNull in configuration will give an error).
diff --git a/server/src/main/java/org/apache/druid/server/NoopQuerySegmentWalker.java b/server/src/main/java/org/apache/druid/server/NoopQuerySegmentWalker.java
new file mode 100644
index 0000000..fea04e0
--- /dev/null
+++ b/server/src/main/java/org/apache/druid/server/NoopQuerySegmentWalker.java
@@ -0,0 +1,48 @@
+/*
+ * 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.server;
+
+import org.apache.druid.query.Query;
+import org.apache.druid.query.QueryRunner;
+import org.apache.druid.query.QuerySegmentWalker;
+import org.apache.druid.query.SegmentDescriptor;
+import org.joda.time.Interval;
+
+/**
+ * An empty implementation of {@link QuerySegmentWalker}.
+ *
+ * Some extentions need implementation of QuerySegmentWalker, but this class will not be used in
+ * router. Bind {@link NoopQuerySegmentWalker} in router to allow router load some extentions, which
+ * makes query can run through router.
+ */
+public class NoopQuerySegmentWalker implements QuerySegmentWalker
+{
+ @Override
+ public <T> QueryRunner<T> getQueryRunnerForIntervals(Query<T> query, Iterable<Interval> intervals)
+ {
+ return null;
+ }
+
+ @Override
+ public <T> QueryRunner<T> getQueryRunnerForSegments(Query<T> query, Iterable<SegmentDescriptor> specs)
+ {
+ return null;
+ }
+}
diff --git a/services/src/main/java/org/apache/druid/cli/CliRouter.java b/services/src/main/java/org/apache/druid/cli/CliRouter.java
index 21ab630..6248ed3 100644
--- a/services/src/main/java/org/apache/druid/cli/CliRouter.java
+++ b/services/src/main/java/org/apache/druid/cli/CliRouter.java
@@ -38,8 +38,10 @@
import org.apache.druid.guice.annotations.Self;
import org.apache.druid.guice.http.JettyHttpClientModule;
import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.query.QuerySegmentWalker;
import org.apache.druid.query.lookup.LookupSerdeModule;
import org.apache.druid.server.AsyncQueryForwardingServlet;
+import org.apache.druid.server.NoopQuerySegmentWalker;
import org.apache.druid.server.http.RouterResource;
import org.apache.druid.server.http.SelfDiscoveryResource;
import org.apache.druid.server.initialization.jetty.JettyServerInitializer;
@@ -91,6 +93,8 @@
JsonConfigProvider.bind(binder, "druid.router.avatica.balancer", AvaticaConnectionBalancer.class);
JsonConfigProvider.bind(binder, "druid.router.managementProxy", ManagementProxyConfig.class);
+ binder.bind(QuerySegmentWalker.class).to(NoopQuerySegmentWalker.class).in(LazySingleton.class);
+
binder.bind(CoordinatorRuleManager.class);
LifecycleModule.register(binder, CoordinatorRuleManager.class);