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


##########
processing/src/main/java/org/apache/druid/query/aggregation/AbstractSerializableLongObjectPairSerde.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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;
+
+import org.apache.druid.collections.SerializablePair;
+import org.apache.druid.data.input.InputRow;
+import org.apache.druid.segment.GenericColumnSerializer;
+import org.apache.druid.segment.column.ColumnBuilder;
+import org.apache.druid.segment.data.GenericIndexed;
+import org.apache.druid.segment.serde.ComplexColumnPartSupplier;
+import org.apache.druid.segment.serde.ComplexMetricExtractor;
+import org.apache.druid.segment.serde.ComplexMetricSerde;
+import 
org.apache.druid.segment.serde.LargeColumnSupportedComplexColumnSerializer;
+import org.apache.druid.segment.writeout.SegmentWriteOutMedium;
+
+import javax.annotation.Nullable;
+import java.nio.ByteBuffer;
+
+public abstract class AbstractSerializableLongObjectPairSerde<T extends 
SerializablePair<Long, ?>> extends
+    ComplexMetricSerde
+{
+  private final Class<T> pairClass;
+
+  public AbstractSerializableLongObjectPairSerde(Class<T> pairClass)
+  {
+    this.pairClass = pairClass;
+  }
+
+  @Override
+  public ComplexMetricExtractor<?> getExtractor()
+  {
+    return new ComplexMetricExtractor<Object>()
+    {
+      @Override
+      public Class<T> extractedClass()
+      {
+        return pairClass;
+      }
+
+      @Nullable
+      @Override
+      public Object extractValue(InputRow inputRow, String metricName)
+      {
+        return inputRow.getRaw(metricName);
+      }
+    };
+  }
+
+  @Override
+  public void deserializeColumn(ByteBuffer buffer, ColumnBuilder columnBuilder)
+  {
+    final GenericIndexed<?> column = GenericIndexed.read(buffer, 
getObjectStrategy(), columnBuilder.getFileMapper());
+    columnBuilder.setComplexColumnSupplier(new 
ComplexColumnPartSupplier(getTypeName(), column));
+  }
+
+  @Override
+  public GenericColumnSerializer<T> getSerializer(SegmentWriteOutMedium 
segmentWriteOutMedium, String column)
+  {
+    return LargeColumnSupportedComplexColumnSerializer.create(
+        segmentWriteOutMedium,
+        column,
+        getObjectStrategy()
+    );
+  }

Review Comment:
   nit: We can use generics to remove the unchecked type warnings that we are 
seeing. This will also get rid of the deprecated warning.
   ```suggestion
     }
     
     @Override
     public abstract ObjectStrategy<T> getObjectStrategy();
   ```



##########
processing/src/main/java/org/apache/druid/query/aggregation/AbstractSerializableLongObjectPairSerde.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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;
+
+import org.apache.druid.collections.SerializablePair;
+import org.apache.druid.data.input.InputRow;
+import org.apache.druid.segment.GenericColumnSerializer;
+import org.apache.druid.segment.column.ColumnBuilder;
+import org.apache.druid.segment.data.GenericIndexed;
+import org.apache.druid.segment.serde.ComplexColumnPartSupplier;
+import org.apache.druid.segment.serde.ComplexMetricExtractor;
+import org.apache.druid.segment.serde.ComplexMetricSerde;
+import 
org.apache.druid.segment.serde.LargeColumnSupportedComplexColumnSerializer;
+import org.apache.druid.segment.writeout.SegmentWriteOutMedium;
+
+import javax.annotation.Nullable;
+import java.nio.ByteBuffer;
+
+public abstract class AbstractSerializableLongObjectPairSerde<T extends 
SerializablePair<Long, ?>> extends
+    ComplexMetricSerde
+{
+  private final Class<T> pairClass;
+
+  public AbstractSerializableLongObjectPairSerde(Class<T> pairClass)
+  {
+    this.pairClass = pairClass;
+  }
+
+  @Override
+  public ComplexMetricExtractor<?> getExtractor()
+  {
+    return new ComplexMetricExtractor<Object>()
+    {
+      @Override
+      public Class<T> extractedClass()
+      {
+        return pairClass;
+      }
+
+      @Nullable
+      @Override
+      public Object extractValue(InputRow inputRow, String metricName)
+      {
+        return inputRow.getRaw(metricName);
+      }
+    };
+  }
+
+  @Override
+  public void deserializeColumn(ByteBuffer buffer, ColumnBuilder columnBuilder)
+  {
+    final GenericIndexed<?> column = GenericIndexed.read(buffer, 
getObjectStrategy(), columnBuilder.getFileMapper());

Review Comment:
   ```suggestion
       final GenericIndexed<T> column = GenericIndexed.read(buffer, 
getObjectStrategy(), columnBuilder.getFileMapper());
   ```
   If we create an abstract method as below, we can get rid of the wildcard 



##########
processing/src/main/java/org/apache/druid/query/aggregation/first/StringFirstLastUtils.java:
##########
@@ -57,8 +58,8 @@ public static boolean selectorNeedsFoldCheck(
 
     // Check if the selector class could possibly be a 
SerializablePairLongString (either a superclass or subclass).

Review Comment:
   ```suggestion
       // Check if the selector class could possibly be a 'pairClass' (either a 
superclass or subclass).
   ```



##########
processing/src/main/java/org/apache/druid/query/aggregation/SerializablePairLongFloatComplexMetricSerde.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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;
+
+import org.apache.druid.collections.SerializablePair;
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.segment.data.ObjectStrategy;
+
+import javax.annotation.Nullable;
+import java.nio.ByteBuffer;
+import java.util.Comparator;
+
+public class SerializablePairLongFloatComplexMetricSerde extends 
AbstractSerializableLongObjectPairSerde<SerializablePairLongFloat>
+{
+  public static final String TYPE_NAME = "serializablePairLongFloat";
+
+  private static final Comparator<SerializablePair<Long, Float>> COMPARATOR = 
SerializablePair.createNullHandlingComparator(
+      Float::compare,
+      true
+  );
+
+  public SerializablePairLongFloatComplexMetricSerde()
+  {
+    super(SerializablePairLongFloat.class);
+  }
+
+  @Override
+  public String getTypeName()
+  {
+    return TYPE_NAME;
+  }
+
+  @Override
+  public ObjectStrategy<SerializablePairLongFloat> getObjectStrategy()
+  {
+    return new ObjectStrategy<SerializablePairLongFloat>()
+    {
+      @Override
+      public int compare(SerializablePairLongFloat o1, 
SerializablePairLongFloat o2)
+      {
+        return COMPARATOR.compare(o1, o2);
+      }
+
+      @Override
+      public Class<? extends SerializablePairLongFloat> getClazz()
+      {
+        return SerializablePairLongFloat.class;
+      }
+
+      @Override
+      public SerializablePairLongFloat fromByteBuffer(ByteBuffer buffer, int 
numBytes)
+      {
+        final ByteBuffer readOnlyBuffer = buffer.asReadOnlyBuffer();
+        long lhs = readOnlyBuffer.getLong();
+        boolean isNotNull = readOnlyBuffer.get() == 
NullHandling.IS_NOT_NULL_BYTE;
+        if (isNotNull) {
+          return new SerializablePairLongFloat(lhs, readOnlyBuffer.getFloat());
+        } else {
+          return new SerializablePairLongFloat(lhs, null);
+        }
+      }
+
+      @Override
+      public byte[] toBytes(@Nullable SerializablePairLongFloat inPair)
+      {
+        if (inPair == null) {
+          return new byte[]{};
+        }
+
+        ByteBuffer bbuf = ByteBuffer.allocate(Long.BYTES + Byte.BYTES + 
Float.BYTES);

Review Comment:
   Similar comment as above, in case it is null, we should avoid allocating the 
space for Float.BYTES. (Should apply for the remaining factories as well)



##########
processing/src/main/java/org/apache/druid/query/aggregation/SerializablePairLongDoubleComplexMetricSerde.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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;
+
+import org.apache.druid.collections.SerializablePair;
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.segment.data.ObjectStrategy;
+
+import javax.annotation.Nullable;
+import java.nio.ByteBuffer;
+import java.util.Comparator;
+
+public class SerializablePairLongDoubleComplexMetricSerde extends 
AbstractSerializableLongObjectPairSerde<SerializablePairLongDouble>
+{
+  public static final String TYPE_NAME = "serializablePairLongDouble";
+
+  private static final Comparator<SerializablePair<Long, Double>> COMPARATOR = 
SerializablePair.createNullHandlingComparator(
+      Double::compare,
+      true
+  );
+
+  public SerializablePairLongDoubleComplexMetricSerde()
+  {
+    super(SerializablePairLongDouble.class);
+  }
+
+  @Override
+  public String getTypeName()
+  {
+    return TYPE_NAME;
+  }
+
+  @Override
+  public ObjectStrategy<SerializablePairLongDouble> getObjectStrategy()
+  {
+    return new ObjectStrategy<SerializablePairLongDouble>()
+    {
+      @Override
+      public int compare(SerializablePairLongDouble o1, 
SerializablePairLongDouble o2)
+      {
+        return COMPARATOR.compare(o1, o2);
+      }
+
+      @Override
+      public Class<? extends SerializablePairLongDouble> getClazz()
+      {
+        return SerializablePairLongDouble.class;
+      }
+
+      @Override
+      public SerializablePairLongDouble fromByteBuffer(ByteBuffer buffer, int 
numBytes)
+      {
+        final ByteBuffer readOnlyBuffer = buffer.asReadOnlyBuffer();
+        long lhs = readOnlyBuffer.getLong();
+        boolean isNotNull = readOnlyBuffer.get() == 
NullHandling.IS_NOT_NULL_BYTE;
+        if (isNotNull) {
+          return new SerializablePairLongDouble(lhs, 
readOnlyBuffer.getDouble());
+        } else {
+          return new SerializablePairLongDouble(lhs, null);
+        }
+      }
+
+      @Override
+      public byte[] toBytes(@Nullable SerializablePairLongDouble inPair)
+      {
+        if (inPair == null) {
+          return new byte[]{};
+        }
+
+        ByteBuffer bbuf = ByteBuffer.allocate(Long.BYTES + Byte.BYTES + 
Double.BYTES);

Review Comment:
   Bumping up this comment. 



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