Skip to content

allow string dimension indexer to handle byte[] as base64 strings#13573

Merged
kfaraz merged 4 commits intoapache:masterfrom
clintropolis:string-dimension-indexer-bytes
Dec 16, 2022
Merged

allow string dimension indexer to handle byte[] as base64 strings#13573
kfaraz merged 4 commits intoapache:masterfrom
clintropolis:string-dimension-indexer-bytes

Conversation

@clintropolis
Copy link
Copy Markdown
Member

Description

This PR expands StringDimensionIndexer to handle conversion of byte[] to base64 encoded strings, rather than the current behavior of calling java toString.

This issue was uncovered by a regression of sorts introduced by #13519, which updated the protobuf extension to directly convert stuff to java types, resulting in bytes typed values being converted as byte[] instead of a base64 string which the previous JSON based conversion created. While outputting byte[] is more consistent with other input formats, and preferable when the bytes can be consumed directly (such as complex types serde), when fed to a StringDimensionIndexer, it resulted in an ugly java toString because processRowValsToUnsortedEncodedKeyComponent is fed the output of row.getRaw(..). Converting byte[] to a base64 string within StringDimensionIndexer is consistent with the behavior of calling row.getDimension(..) which does do this coercion (and why many tests on binary types appeared to be doing the expected thing).

I added some protobuf bytes tests, but they don't really hit the new StringDimensionIndexer behavior because they operate on the InputRow directly, and call getDimension to validate stuff. The parser based version still uses the old conversion mechanisms, so when not using a flattener incorrectly calls toString on the ByteString. I have encoded this behavior in the test for now, if we either update the parser to use the new flattener or just .. remove parsers we can remove this test stuff.


This PR has:

  • been self-reviewed.
  • 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
  • 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 is met.
  • added integration tests.
  • been tested in a test Druid cluster.

Copy link
Copy Markdown
Contributor

@kfaraz kfaraz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, +1 after CI passes

@clintropolis clintropolis force-pushed the string-dimension-indexer-bytes branch from ee90948 to 09561ca Compare December 15, 2022 22:17
@clintropolis clintropolis added this to the 25.0 milestone Dec 15, 2022
@kfaraz kfaraz merged commit d9e5245 into apache:master Dec 16, 2022
kfaraz pushed a commit to kfaraz/druid that referenced this pull request Dec 16, 2022
…ache#13573)

This PR expands `StringDimensionIndexer` to handle conversion of `byte[]` to base64 encoded strings, rather than the current behavior of calling java `toString`. 

This issue was uncovered by a regression of sorts introduced by apache#13519, which updated the protobuf extension to directly convert stuff to java types, resulting in `bytes` typed values being converted as `byte[]` instead of a base64 string which the previous JSON based conversion created. While outputting `byte[]` is more consistent with other input formats, and preferable when the bytes can be consumed directly (such as complex types serde), when fed to a `StringDimensionIndexer`, it resulted in an ugly java `toString` because `processRowValsToUnsortedEncodedKeyComponent` is fed the output of `row.getRaw(..)`. Converting `byte[]` to a base64 string within `StringDimensionIndexer` is consistent with the behavior of calling `row.getDimension(..)` which does do this coercion (and why many tests on binary types appeared to be doing the expected thing).

I added some protobuf `bytes` tests, but they don't really hit the new `StringDimensionIndexer` behavior because they operate on the `InputRow` directly, and call `getDimension` to validate stuff. The parser based version still uses the old conversion mechanisms, so when not using a flattener incorrectly calls `toString` on the `ByteString`. I have encoded this behavior in the test for now, if we either update the parser to use the new flattener or just .. remove parsers we can remove this test stuff.
kfaraz added a commit that referenced this pull request Dec 16, 2022
…3573) (#13582)

This PR expands `StringDimensionIndexer` to handle conversion of `byte[]` to base64 encoded strings, rather than the current behavior of calling java `toString`. 

This issue was uncovered by a regression of sorts introduced by #13519, which updated the protobuf extension to directly convert stuff to java types, resulting in `bytes` typed values being converted as `byte[]` instead of a base64 string which the previous JSON based conversion created. While outputting `byte[]` is more consistent with other input formats, and preferable when the bytes can be consumed directly (such as complex types serde), when fed to a `StringDimensionIndexer`, it resulted in an ugly java `toString` because `processRowValsToUnsortedEncodedKeyComponent` is fed the output of `row.getRaw(..)`. Converting `byte[]` to a base64 string within `StringDimensionIndexer` is consistent with the behavior of calling `row.getDimension(..)` which does do this coercion (and why many tests on binary types appeared to be doing the expected thing).

I added some protobuf `bytes` tests, but they don't really hit the new `StringDimensionIndexer` behavior because they operate on the `InputRow` directly, and call `getDimension` to validate stuff. The parser based version still uses the old conversion mechanisms, so when not using a flattener incorrectly calls `toString` on the `ByteString`. I have encoded this behavior in the test for now, if we either update the parser to use the new flattener or just .. remove parsers we can remove this test stuff.

Co-authored-by: Clint Wylie <cwylie@apache.org>
@clintropolis clintropolis deleted the string-dimension-indexer-bytes branch December 21, 2022 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants