clintropolis commented on a change in pull request #7925: Use 
ComplexMetrics.registerSerde() across the codebase
URL: https://github.com/apache/incubator-druid/pull/7925#discussion_r296929098
 
 

 ##########
 File path: 
processing/src/main/java/org/apache/druid/segment/serde/ComplexMetrics.java
 ##########
 @@ -37,11 +38,13 @@ public static ComplexMetricSerde getSerdeForType(String 
type)
     return complexSerializers.get(type);
   }
 
-  public static void registerSerde(String type, ComplexMetricSerde serde)
+  public static void registerSerde(String type, Supplier<ComplexMetricSerde> 
serdeSupplier)
   {
-    if (complexSerializers.containsKey(type)) {
-      throw new ISE("Serializer for type[%s] already exists.", type);
+    if (ComplexMetrics.getSerdeForType(type) == null) {
+      if (complexSerializers.containsKey(type)) {
 
 Review comment:
   Seeing these 2 checks next to each other makes me wonder what is the purpose 
of this inner check because it seems like it shouldn't happen with the outer 
one baked in like this. I suspect the original intent was to fail with an 
exception if the same complex type was registered with different serializers, 
however that might have been lost along the way. Maybe it would be best to 
rework this to check that a serde _of the expected type_ is registered, and if 
it's not, register it, and if it is but not the same type, fail with the 
exception. Maybe something like:
   
   ```
     public static <T extends ComplexMetricSerde> void registerSerde(String 
type, Class<T> clazz, Supplier<T> serdeSupplier)
     {
       if (complexSerializers.containsKey(type)) {
         if 
(!complexSerializers.get(type).getClass().getCanonicalName().equals(clazz.getCanonicalName()))
 {
           throw new ISE(
               "Incompatible serializer for type[%s] already exists. Expected 
[%s], found [%s].",
               clazz.getCanonicalName(),
               complexSerializers.get(type).getClass().getCanonicalName()
           );
         }
       } else {
         complexSerializers.put(type, serdeSupplier.get());
       }
     }
   ```
   
   Maybe there is a more elegant way to implement this that doesn't involve 
passing the class, or maybe this is too strict and something like checking if 
is assignable is more appropriate, i'm not certain. @leventov do you have any 
thoughts on this?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

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

Reply via email to