You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "LakshSingla (via GitHub)" <gi...@apache.org> on 2024/05/29 05:54:24 UTC

[PR] Deserialize dimensions in group by queries to their respective types when reading from their serialized format (druid)

LakshSingla opened a new pull request, #16511:
URL: https://github.com/apache/druid/pull/16511

   ### Description
   [Grouping on complex columns](https://github.com/apache/druid/pull/16068) allowed the dimensions to be of complex types. When reading the dimensions from their serialized format, we must deserialize them in their desired complex type. Otherwise, Druid deserializes the dimension into a generic java object equivalent to `objectMapper.readValue(serializedValue, Object.class)` 
   
   We read the dimensions from their serialized form:
   1. When reading dimensions from the segments
   2. When reading dimensions over the wire (in native queries)
   
   This wasn't discovered at the time of the original PR because only JSON columns support groupability at the moment, and they are designed to handle the generic Java object that the object mapper deserializes to by default. However, this is required for most other complex types that require groupability. 
   
   #### Release note
   (none) 
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * `MyFoo`
    * `OurBar`
    * `TheirBaz`
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   
   - [ ] been self-reviewed.
      - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] a release note entry in the PR description.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Deserialize dimensions in group by queries to their respective types when reading from their serialized format (druid)

Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #16511:
URL: https://github.com/apache/druid/pull/16511#discussion_r1634250727


##########
processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/RowBasedGrouperHelper.java:
##########
@@ -186,6 +188,7 @@ public static Pair<Grouper<RowBasedKey>, Accumulator<AggregateResult, ResultRow>
       @Nullable final ReferenceCountingResourceHolder<ByteBuffer> combineBufferHolder,
       final int concurrencyHint,
       final LimitedTemporaryStorage temporaryStorage,
+      final ObjectMapper jsonMapper,
       final ObjectMapper spillMapper,

Review Comment:
   should jsonMapper and spillMapper be different? I know spillMapper is usually smile, though isn't results from historicals also smile? regardless, probably worth a comment somewhere of why we have different mappers



##########
processing/src/main/java/org/apache/druid/segment/column/ObjectStrategyComplexTypeStrategy.java:
##########
@@ -39,22 +39,25 @@ public class ObjectStrategyComplexTypeStrategy<T> implements TypeStrategy<T>
   private final TypeSignature<?> typeSignature;
   @Nullable
   private final Hash.Strategy<T> hashStrategy;
+  @Nullable
+  private final Class<?> complexDimensionType;
 
   public ObjectStrategyComplexTypeStrategy(ObjectStrategy<T> objectStrategy, TypeSignature<?> signature)
   {
-    this(objectStrategy, signature, null);
+    this(objectStrategy, signature, null, null);
   }
 
   public ObjectStrategyComplexTypeStrategy(
       ObjectStrategy<T> objectStrategy,
       TypeSignature<?> signature,
-      @Nullable final Hash.Strategy<T> hashStrategy
+      @Nullable final Hash.Strategy<T> hashStrategy,
+      @Nullable final Class<?> complexDimensionType

Review Comment:
   should this just use `getClazz` of `ObjectStrategy`?



##########
processing/src/main/java/org/apache/druid/segment/column/TypeStrategy.java:
##########
@@ -216,4 +216,9 @@ default boolean equals(T a, T b)
   {
     throw DruidException.defensive("Not implemented. Check groupable() first");
   }
+
+  default Class<?> complexDimensionType()

Review Comment:
   nit: maybe `getComplexClass` or the classic `getClazz` would be a better name since it probably isn't a different type when used as a dimension (and we have the separate `groupable` to determine if it can be used as a dimension or not)



-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Deserialize dimensions in group by queries to their respective types when reading from their serialized format (druid)

Posted by "asdf2014 (via GitHub)" <gi...@apache.org>.
asdf2014 merged PR #16511:
URL: https://github.com/apache/druid/pull/16511


-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Deserialize dimensions in group by queries to their respective types when reading from their serialized format (druid)

Posted by "LakshSingla (via GitHub)" <gi...@apache.org>.
LakshSingla commented on code in PR #16511:
URL: https://github.com/apache/druid/pull/16511#discussion_r1636858245


##########
processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/RowBasedGrouperHelper.java:
##########
@@ -186,6 +188,7 @@ public static Pair<Grouper<RowBasedKey>, Accumulator<AggregateResult, ResultRow>
       @Nullable final ReferenceCountingResourceHolder<ByteBuffer> combineBufferHolder,
       final int concurrencyHint,
       final LimitedTemporaryStorage temporaryStorage,
+      final ObjectMapper jsonMapper,
       final ObjectMapper spillMapper,

Review Comment:
   Retested stuff, serde in (2) is not required. 



-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Deserialize dimensions in group by queries to their respective types when reading from their serialized format (druid)

Posted by "LakshSingla (via GitHub)" <gi...@apache.org>.
LakshSingla commented on PR #16511:
URL: https://github.com/apache/druid/pull/16511#issuecomment-2167534323

   Thanks for the review @clintropolis @asdf2014 


-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Deserialize dimensions in group by queries to their respective types when reading from their serialized format (druid)

Posted by "LakshSingla (via GitHub)" <gi...@apache.org>.
LakshSingla commented on code in PR #16511:
URL: https://github.com/apache/druid/pull/16511#discussion_r1635854626


##########
processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/RowBasedGrouperHelper.java:
##########
@@ -186,6 +188,7 @@ public static Pair<Grouper<RowBasedKey>, Accumulator<AggregateResult, ResultRow>
       @Nullable final ReferenceCountingResourceHolder<ByteBuffer> combineBufferHolder,
       final int concurrencyHint,
       final LimitedTemporaryStorage temporaryStorage,
+      final ObjectMapper jsonMapper,
       final ObjectMapper spillMapper,

Review Comment:
   When writing the code, this seemed natural, since we are using spillMapper for the spilling runner, and nothing else. After going through the group by code again, I think we should still be using the jsonMapper. 
   The input rows which get further deserialized according to the complex types are sourced from:
   1. https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/GroupByRowProcessor.java#L90 - The input rows are from the processed subqueries. 
   2. https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/GroupByMergingQueryRunner.java#L254C54-L254C55 - The input rows are to the mergeRunner, which has already been read from the segments by the createRunner. 



-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org