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_r259175648
########## 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) + { + + this.walker = walker; + this.requestLogger = requestLogger; + this.movingAverageQueryMetricsFactory = DefaultMovingAverageQueryMetricsFactory.instance(); + } + + @Inject(optional = true) + public void setWarehouse(QueryToolChestWarehouse warehouse) + { + this.warehouse = warehouse; + } + + @Override + public QueryRunner<Row> mergeResults(QueryRunner<Row> runner) + { + return new MovingAverageQueryRunner(warehouse, walker, requestLogger); + } + + @Override + public QueryMetrics<? super MovingAverageQuery> makeMetrics(MovingAverageQuery query) + { + MovingAverageQueryMetrics movingAverageQueryMetrics = movingAverageQueryMetricsFactory.makeMetrics(); + movingAverageQueryMetrics.query(query); + return movingAverageQueryMetrics; + } + + @Override + public Function<Row, Row> makePostComputeManipulatorFn(MovingAverageQuery query, MetricManipulationFn fn) + { + + return new Function<Row, Row>() + { + + @Override + public Row apply(Row result) + { + MapBasedRow mRow = (MapBasedRow) result; + final Map<String, Object> values = new HashMap(mRow.getEvent()); Review comment: `new HashMap<>(mRow.getEvent());` ---------------------------------------------------------------- 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]
