jihoonson commented on a change in pull request #6430: Contributing Moving-Average Query to open source. URL: https://github.com/apache/incubator-druid/pull/6430#discussion_r260118600
########## File path: extensions-contrib/moving-average-query/src/main/java/org/apache/druid/query/movingaverage/MovingAverageQueryToolChest.java ########## @@ -0,0 +1,145 @@ +/* + * 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.query.movingaverage; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.google.common.base.Function; +import com.google.common.base.Functions; +import com.google.inject.Inject; +import org.apache.druid.data.input.MapBasedRow; +import org.apache.druid.data.input.Row; +import org.apache.druid.query.QueryMetrics; +import org.apache.druid.query.QueryRunner; +import org.apache.druid.query.QuerySegmentWalker; +import org.apache.druid.query.QueryToolChest; +import org.apache.druid.query.QueryToolChestWarehouse; +import org.apache.druid.query.aggregation.AggregatorFactory; +import org.apache.druid.query.aggregation.MetricManipulationFn; +import org.apache.druid.query.movingaverage.averagers.AveragerFactory; +import org.apache.druid.server.log.RequestLogger; + +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.Map; + +/** + * The QueryToolChest for MovingAverage Query + */ +public class MovingAverageQueryToolChest extends QueryToolChest<Row, MovingAverageQuery> +{ + + private final QuerySegmentWalker walker; + private final RequestLogger requestLogger; + private QueryToolChestWarehouse warehouse; + + public static final String MOVING_AVERAGE_MERGE_KEY = "movingAverageMerge"; + + private final MovingAverageQueryMetricsFactory movingAverageQueryMetricsFactory; + + /** + * Construct a MovingAverageQueryToolChest for processing moving-average queries. + * MovingAverage queries are expected to be processed on broker nodes and never hit historical nodes. + * + * @param walker + * @param requestLogger + */ + @Inject + public MovingAverageQueryToolChest(@Nullable QuerySegmentWalker walker, RequestLogger requestLogger) Review comment: This produces the below error at brokers: ``` 1) Error injecting constructor, java.lang.IllegalStateException: This is a proxy used to support circular references. The object we're proxying is not constructed yet. Please wait until after injection has completed to use this object. at org.apache.druid.client.CachingClusteredClient.<init>(CachingClusteredClient.java:115) at org.apache.druid.cli.CliBroker.lambda$getModules$0(CliBroker.java:94) (via modules: com.google.inject.util.Modules$OverrideModule -> com.google.inject.util.Modules$OverrideModule -> org.apache.druid.cli.CliBroker$$Lambda$8/1129869771) while locating org.apache.druid.client.CachingClusteredClient for the 2nd parameter of org.apache.druid.server.ClientQuerySegmentWalker.<init>(ClientQuerySegmentWalker.java:68) while locating org.apache.druid.server.ClientQuerySegmentWalker at org.apache.druid.cli.CliBroker.lambda$getModules$0(CliBroker.java:107) (via modules: com.google.inject.util.Modules$OverrideModule -> com.google.inject.util.Modules$OverrideModule -> org.apache.druid.cli.CliBroker$$Lambda$8/1129869771) while locating org.apache.druid.query.QuerySegmentWalker for the 1st parameter of org.apache.druid.query.movingaverage.MovingAverageQueryToolChest.<init>(MovingAverageQueryToolChest.java:65) at org.apache.druid.query.movingaverage.MovingAverageQueryModule.configure(MovingAverageQueryModule.java:48) (via modules: com.google.inject.util.Modules$OverrideModule -> org.apache.druid.query.movingaverage.MovingAverageQueryModule) while locating org.apache.druid.query.movingaverage.MovingAverageQueryToolChest while locating org.apache.druid.query.QueryToolChest annotated with @com.google.inject.multibindings.Element(setName=,uniqueId=182, type=MAPBINDER, keyType=java.lang.Class<? extends org.apache.druid.query.Query>) at org.apache.druid.guice.DruidBinders.queryToolChestBinder(DruidBinders.java:47) (via modules: com.google.inject.util.Modules$OverrideModule -> org.apache.druid.query.movingaverage.MovingAverageQueryModule -> com.google.inject.multibindings.MapBinder$RealMapBinder) while locating java.util.Map<java.lang.Class<? extends org.apache.druid.query.Query>, org.apache.druid.query.QueryToolChest> for the 1st parameter of org.apache.druid.query.MapQueryToolChestWarehouse.<init>(MapQueryToolChestWarehouse.java:35) while locating org.apache.druid.query.MapQueryToolChestWarehouse while locating org.apache.druid.query.QueryToolChestWarehouse for the 1st parameter of org.apache.druid.client.BrokerServerView.<init>(BrokerServerView.java:98) at org.apache.druid.client.BrokerServerView.class(BrokerServerView.java:63) while locating org.apache.druid.client.BrokerServerView ``` This is because of the circular references among `ClientQuerySegmentWalker`, `MapQueryToolChestWarehouse`, and `MovingAverageQueryToolChest`. `MovingAverageQueryToolChest` requires `ClientQuerySegmentWalker` to be injected which requires `QueryToolChestWarehouse` to be injected, which in turn requires `MovingAverageQueryToolChest` to be injected. @yurmix are you using this extension in the production environment? How did you solve this problem? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
