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 2018/07/27 06:47:00 UTC

[GitHub] andresgomezfrr commented on a change in pull request #5789: Add stringLast and stringFirst aggregators extension

andresgomezfrr commented on a change in pull request #5789: Add stringLast and stringFirst aggregators extension
URL: https://github.com/apache/incubator-druid/pull/5789#discussion_r205681438
 
 

 ##########
 File path: processing/src/main/java/io/druid/query/aggregation/first/StringFirstBufferAggregator.java
 ##########
 @@ -0,0 +1,151 @@
+/*
+ * Licensed to Metamarkets Group Inc. (Metamarkets) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. Metamarkets 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 io.druid.query.aggregation.first;
+
+import io.druid.java.util.common.StringUtils;
+import io.druid.query.aggregation.BufferAggregator;
+import io.druid.query.aggregation.SerializablePairLongString;
+import io.druid.query.monomorphicprocessing.RuntimeShapeInspector;
+import io.druid.segment.BaseLongColumnValueSelector;
+import io.druid.segment.BaseObjectColumnValueSelector;
+
+import java.nio.ByteBuffer;
+
+// TODO: Unit Test
+public class StringFirstBufferAggregator implements BufferAggregator
+{
+  private final BaseLongColumnValueSelector timeSelector;
+  private final BaseObjectColumnValueSelector valueSelector;
+  private final int maxStringBytes;
+
+  public StringFirstBufferAggregator(
+      BaseLongColumnValueSelector timeSelector,
+      BaseObjectColumnValueSelector valueSelector,
+      int maxStringBytes
+  )
+  {
+    this.timeSelector = timeSelector;
+    this.valueSelector = valueSelector;
+    this.maxStringBytes = maxStringBytes;
+  }
+
+  @Override
+  public void init(ByteBuffer buf, int position)
+  {
+    buf.putLong(position, Long.MAX_VALUE);
+    buf.putInt(position + Long.BYTES, 0);
+  }
+
+  @Override
+  public void aggregate(ByteBuffer buf, int position)
+  {
+    ByteBuffer mutationBuffer = buf.duplicate();
+    mutationBuffer.position(position);
+
+    Object value = valueSelector.getObject();
+
+    long time = Long.MAX_VALUE;
+    String firstString = null;
+
+    if (value instanceof SerializablePairLongString) {
+      SerializablePairLongString serializablePair = (SerializablePairLongString) value;
+      time = serializablePair.lhs;
+      firstString = serializablePair.rhs;
+    } else if (value instanceof String) {
+      time = timeSelector.getLong();
+      firstString = (String) value;
+    } else if (value != null) {
+      throw new IllegalStateException(
+          "Try to aggregate unsuported class type ["
+          + value.getClass().getName() +
+          "]. Supported class types: String or SerializablePairLongString"
+      );
+    }
+
+    long lastTime = mutationBuffer.getLong(position);
+    if (firstString != null && time < lastTime) {
 
 Review comment:
   @jihoonson Maybe we can add an aggregation option `filterNullValues` (by default: `false`). What do you think?

----------------------------------------------------------------
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:
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