clintropolis commented on code in PR #16863:
URL: https://github.com/apache/druid/pull/16863#discussion_r1730418311


##########
processing/src/main/java/org/apache/druid/segment/serde/ComplexMetricSerde.java:
##########
@@ -142,14 +120,100 @@ public Object fromBytes(byte[] data, int start, int 
numBytes)
   }
 
   /**
-   * This method provides the ability for a ComplexMetricSerde to control its 
own serialization.
-   * For large column (i.e columns greater than {@link Integer#MAX_VALUE}) use
-   * {@link LargeColumnSupportedComplexColumnSerializer}
+   * Deserializes a ByteBuffer and adds it to the ColumnBuilder.  This method 
allows for the ComplexMetricSerde
+   * to implement it's own versioning scheme to allow for changes of binary 
format in a forward-compatible manner.
    *
-   * @return an instance of GenericColumnSerializer used for serialization.
+   * @param buffer  the buffer to deserialize
+   * @param builder ColumnBuilder to add the column to
+   * @param columnConfig ColumnConfiguration used during deserialization
+   */
+  public void deserializeColumn(
+      ByteBuffer buffer,
+      ColumnBuilder builder,
+      ColumnConfig columnConfig
+  )
+  {
+    deserializeColumn(buffer, builder);
+  }
+
+
+  /**
+   * {@link ComplexMetricSerde#deserializeColumn(ByteBuffer, ColumnBuilder, 
ColumnConfig)} should be used instead of this.
+   * This method is left for backward compatibility.
    */
+  @Deprecated
+  public void deserializeColumn(ByteBuffer buffer, ColumnBuilder builder)
+  {
+    // default implementation to match default serializer implementation
+    final int position = buffer.position();
+    final byte version = buffer.get();
+    if (version == CompressedComplexColumnSerializer.IS_COMPRESSED) {
+      CompressedComplexColumnSupplier supplier = 
CompressedComplexColumnSupplier.read(
+          buffer,
+          builder,
+          getTypeName(),
+          getObjectStrategy()
+      );
+      builder.setComplexColumnSupplier(supplier);
+      builder.setNullValueIndexSupplier(supplier.getNullValues());
+      builder.setHasNulls(!supplier.getNullValues().isEmpty());
+    } else {
+      buffer.position(position);
+      builder.setComplexColumnSupplier(
+          new ComplexColumnPartSupplier(
+              getTypeName(),
+              GenericIndexed.read(buffer, getObjectStrategy(), 
builder.getFileMapper())
+          )
+      );
+    }
+  }
+
+  /**
+   * {@link ComplexMetricSerde#getSerializer(SegmentWriteOutMedium, String, 
IndexSpec)} should be used instead of this.
+   * This method is left for backward compatibility.
+   */
+  @Nullable
+  @Deprecated
   public GenericColumnSerializer getSerializer(SegmentWriteOutMedium 
segmentWriteOutMedium, String column)
   {
-    return ComplexColumnSerializer.create(segmentWriteOutMedium, column, 
this.getObjectStrategy());
+    return null;
+  }
+
+  /**
+   * This method provides the ability for a ComplexMetricSerde to control its 
own serialization.
+   * Default implementation uses {@link CompressedComplexColumnSerializer} if 
{@link IndexSpec#complexMetricCompression}
+   * is not null or uncompressed/none, or {@link 
LargeColumnSupportedComplexColumnSerializer} if no compression is
+   * specified.
+   *
+   * @return an instance of {@link GenericColumnSerializer} used for 
serialization.
+   */
+  public GenericColumnSerializer getSerializer(
+      SegmentWriteOutMedium segmentWriteOutMedium,
+      String column,
+      IndexSpec indexSpec
+  )
+  {
+    // backwards compatibility, if defined use it
+    final GenericColumnSerializer serializer = 
getSerializer(segmentWriteOutMedium, column);
+    if (serializer != null) {
+      return serializer;
+    }
+
+    // otherwise, use compressed or generic indexed based serializer
+    CompressionStrategy strategy = indexSpec.getComplexMetricCompression();
+    if (strategy == null || CompressionStrategy.NONE == strategy || 
CompressionStrategy.UNCOMPRESSED == strategy) {
+      return LargeColumnSupportedComplexColumnSerializer.create(

Review Comment:
   `LargeColumnSupportedComplexColumnSerializer` is basically identical to 
`ComplexColumnSerializer`, they both use `GenericIndexedWriter` with a filename 
of `StringUtils.format("%s.complex_column", filenameBase)`, the main difference 
is that  `LargeColumnSupportedComplexColumnSerializer` passes the 
`FileSmoosher` through to the writer allowing it to write v2 `GenericIndexed` 
which has the multi file support. So I think there shouldn't be any 
compatibility concerns because on the read side since both of these just use 
`GenericIndexed.read`



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