LakshSingla commented on code in PR #14462:
URL: https://github.com/apache/druid/pull/14462#discussion_r1393622850


##########
processing/src/main/java/org/apache/druid/query/aggregation/first/StringFirstAggregatorFactory.java:
##########


Review Comment:
   Can this also use the `GenericFirstAggregateCombiner` that you have created, 
and we can remove the `StringFirstAggregateCombiner`? 



##########
processing/src/main/java/org/apache/druid/query/aggregation/first/FirstLastUtils.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.first;
+
+import org.apache.druid.segment.BaseObjectColumnValueSelector;
+import org.apache.druid.segment.NilColumnValueSelector;
+import org.apache.druid.segment.column.ColumnCapabilities;
+import org.apache.druid.segment.column.ValueType;
+
+import javax.annotation.Nullable;
+
+public class FirstLastUtils
+{
+
+  /**
+   * Returns whether a given value selector *might* contain 
SerializablePairLongString objects.

Review Comment:
   This comment is obsolete since this is not limited to the Pair<Long, String> 
object. Also, it would be good if Javadoc mentioned what the "fold" check 
means. 



##########
processing/src/main/java/org/apache/druid/query/aggregation/first/DoubleFirstAggregator.java:
##########
@@ -19,30 +19,36 @@
 
 package org.apache.druid.query.aggregation.first;
 
-import org.apache.druid.collections.SerializablePair;
-import org.apache.druid.segment.BaseDoubleColumnValueSelector;
+import org.apache.druid.query.aggregation.SerializablePairLongDouble;
 import org.apache.druid.segment.BaseLongColumnValueSelector;
+import org.apache.druid.segment.ColumnValueSelector;
 
-public class DoubleFirstAggregator extends 
NumericFirstAggregator<BaseDoubleColumnValueSelector>
+public class DoubleFirstAggregator extends NumericFirstAggregator
 {
   double firstValue;
 
-  public DoubleFirstAggregator(BaseLongColumnValueSelector timeSelector, 
BaseDoubleColumnValueSelector valueSelector)
+  public DoubleFirstAggregator(BaseLongColumnValueSelector timeSelector, 
ColumnValueSelector valueSelector, boolean needsFoldCheck)

Review Comment:
   Still confused as to why doubles wouldn't require a folds check. 



##########
processing/src/main/java/org/apache/druid/query/aggregation/first/FirstLastUtils.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.first;
+
+import org.apache.druid.segment.BaseObjectColumnValueSelector;
+import org.apache.druid.segment.NilColumnValueSelector;
+import org.apache.druid.segment.column.ColumnCapabilities;
+import org.apache.druid.segment.column.ValueType;
+
+import javax.annotation.Nullable;
+
+public class FirstLastUtils
+{
+
+  /**
+   * Returns whether a given value selector *might* contain 
SerializablePairLongString objects.
+   */
+  public static boolean selectorNeedsFoldCheck(
+      final BaseObjectColumnValueSelector<?> valueSelector,
+      @Nullable final ColumnCapabilities valueSelectorCapabilities,
+      Class pairClass
+  )
+  {
+    if (valueSelectorCapabilities != null && 
!valueSelectorCapabilities.is(ValueType.COMPLEX)) {
+      // Known, non-complex type.
+      return false;
+    }
+
+    if (valueSelector instanceof NilColumnValueSelector) {
+      // Nil column, definitely no SerializablePairLongStrings.
+      return false;
+    }
+
+    // Check if the selector class could possibly be a 
SerializablePairLongString (either a superclass or subclass).
+    final Class<?> clazz = valueSelector.classOfObject();
+    return clazz.isAssignableFrom(pairClass)
+           || pairClass.isAssignableFrom(clazz);
+  }
+
+  /**
+   * Returns whether an object *might* contain SerializablePairLongString 
objects.

Review Comment:
   Outdated javadoc



##########
processing/src/main/java/org/apache/druid/query/aggregation/first/FirstLastUtils.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.first;
+
+import org.apache.druid.segment.BaseObjectColumnValueSelector;
+import org.apache.druid.segment.NilColumnValueSelector;
+import org.apache.druid.segment.column.ColumnCapabilities;
+import org.apache.druid.segment.column.ValueType;
+
+import javax.annotation.Nullable;
+
+public class FirstLastUtils
+{
+
+  /**
+   * Returns whether a given value selector *might* contain 
SerializablePairLongString objects.
+   */
+  public static boolean selectorNeedsFoldCheck(
+      final BaseObjectColumnValueSelector<?> valueSelector,
+      @Nullable final ColumnCapabilities valueSelectorCapabilities,
+      Class pairClass
+  )
+  {
+    if (valueSelectorCapabilities != null && 
!valueSelectorCapabilities.is(ValueType.COMPLEX)) {
+      // Known, non-complex type.
+      return false;
+    }
+
+    if (valueSelector instanceof NilColumnValueSelector) {
+      // Nil column, definitely no SerializablePairLongStrings.
+      return false;
+    }
+
+    // Check if the selector class could possibly be a 
SerializablePairLongString (either a superclass or subclass).
+    final Class<?> clazz = valueSelector.classOfObject();
+    return clazz.isAssignableFrom(pairClass)
+           || pairClass.isAssignableFrom(clazz);
+  }
+
+  /**
+   * Returns whether an object *might* contain SerializablePairLongString 
objects.
+   */
+  public static boolean objectNeedsFoldCheck(Object obj, Class pairClass)
+  {
+    if (obj == null) {
+      return false;
+    }
+    final Class<?> clazz = obj.getClass();
+    return clazz.isAssignableFrom(pairClass)
+           || pairClass.isAssignableFrom(clazz);
+  }
+
+
+  public static boolean[] getNullVector(Object[] objectVector)

Review Comment:
   Please add the following annotation because it might not be intuitive that 
it can return null. Also, can you please add a javadoc describing the behaviour 
for the same. 
   ```suggestion
     @Nullable
     public static boolean[] getNullVector(Object[] objectVector)
   ```



##########
processing/src/main/java/org/apache/druid/query/aggregation/SerializablePairLongStringColumnSerializer.java:
##########


Review Comment:
   This should also inherit from the 
`AbstractSerializablePairLongObjectColumnSerializer` class.



##########
processing/src/main/java/org/apache/druid/query/aggregation/AbstractSerializablePairLongObjectBufferStore.java:
##########


Review Comment:
   The String methods could also inherit from this class I suppose. 



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to