You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2019/09/24 19:33:11 UTC

[GitHub] [incubator-druid] himanshug commented on a change in pull request #8459: doubleMean aggregator to be used at query time

himanshug commented on a change in pull request #8459: doubleMean aggregator to be used at query time
URL: https://github.com/apache/incubator-druid/pull/8459#discussion_r327795866
 
 

 ##########
 File path: processing/src/main/java/org/apache/druid/query/aggregation/mean/DoubleMeanAggregatorFactory.java
 ##########
 @@ -0,0 +1,180 @@
+/*
+ * 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.aggregation.mean;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.query.aggregation.Aggregator;
+import org.apache.druid.query.aggregation.AggregatorFactory;
+import org.apache.druid.query.aggregation.AggregatorUtil;
+import org.apache.druid.query.aggregation.BufferAggregator;
+import org.apache.druid.query.aggregation.VectorAggregator;
+import org.apache.druid.query.cache.CacheKeyBuilder;
+import org.apache.druid.segment.ColumnSelectorFactory;
+import org.apache.druid.segment.vector.VectorColumnSelectorFactory;
+
+import javax.annotation.Nullable;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ */
+public class DoubleMeanAggregatorFactory extends AggregatorFactory
+{
+  private final String name;
+  private final String fieldName;
+
+  @JsonCreator
+  public DoubleMeanAggregatorFactory(
+      @JsonProperty("name") String name,
+      @JsonProperty("fieldName") final String fieldName
+  )
+  {
+    this.name = Preconditions.checkNotNull(name, "null name");
+    this.fieldName = Preconditions.checkNotNull(fieldName, "null fieldName");
+  }
+
+  @Override
+  @JsonProperty
+  public String getName()
+  {
+    return name;
+  }
+
+  @JsonProperty
+  public String getFieldName()
+  {
+    return fieldName;
+  }
+
+  @Override
+  public List<String> requiredFields()
+  {
+    return Collections.singletonList(fieldName);
+  }
+
+  @Override
+  public String getTypeName()
+  {
+    return "doubleMean";
+  }
+
+  @Override
+  public int getMaxIntermediateSize()
+  {
+    return DoubleMeanHolder.MAX_INTERMEDIATE_SIZE;
+  }
+
+  @Override
+  public Aggregator factorize(ColumnSelectorFactory metricFactory)
+  {
+    return new DoubleMeanAggregator(metricFactory.makeColumnValueSelector(fieldName));
+  }
+
+  @Override
+  public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory)
+  {
+    return new DoubleMeanBufferAggregator(metricFactory.makeColumnValueSelector(fieldName));
+  }
+
+  @Override
+  public VectorAggregator factorizeVector(final VectorColumnSelectorFactory selectorFactory)
+  {
+    return new DoubleMeanVectorAggregator(selectorFactory.makeValueSelector(fieldName));
+  }
+
+  @Override
+  public boolean canVectorize()
+  {
+    return true;
+  }
+
+  @Override
+  public Comparator getComparator()
+  {
+    return DoubleMeanHolder.COMPARATOR;
+  }
+
+  @Nullable
+  @Override
+  public Object combine(@Nullable Object lhs, @Nullable Object rhs)
+  {
+    if (lhs instanceof DoubleMeanHolder && rhs instanceof DoubleMeanHolder) {
+      return ((DoubleMeanHolder) lhs).update((DoubleMeanHolder) rhs);
+    } else {
+      throw new IAE(
+          "lhs[%s] or rhs[%s] not of type [%s]",
+          lhs.getClass().getName(),
+          rhs.getClass().getName(),
 
 Review comment:
   they can't be null because doubleMean aggregator impls never return null.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org