Skip to content

Commit

Permalink
Allow query through router when load moving average extension (#11276)
Browse files Browse the repository at this point in the history
* init commit

* change NoopQuerySegmentWalker name

* change doc

* move NoopQuerySegmentWalker and add document

* fix doc

Co-authored-by: yuanyi <yuanyi@freewheel.tv>
  • Loading branch information
bananaaggle and yuanyi committed Jun 10, 2021
1 parent 9047fa3 commit 8de0d36
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
5 changes: 2 additions & 3 deletions docs/development/extensions-contrib/moving-average-query.md
Expand Up @@ -52,14 +52,14 @@ It runs the query in two main phases:
## 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:

Expand All @@ -71,7 +71,6 @@ druid.extensions.loadList=["druid-moving-average-query"]
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).
Expand Down
@@ -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;
}
}
4 changes: 4 additions & 0 deletions services/src/main/java/org/apache/druid/cli/CliRouter.java
Expand Up @@ -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;
Expand Down Expand Up @@ -91,6 +93,8 @@ protected List<? extends Module> getModules()
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);

Expand Down

0 comments on commit 8de0d36

Please sign in to comment.