druid icon indicating copy to clipboard operation
druid copied to clipboard

Sort JSON keys to fix comparator inconsistency

Open aho135 opened this issue 6 months ago • 1 comments

Fixes #18156

Description

When sorting StructuredData objects there is scenario that causes an IllegalArgumentException in TimSort. This occurs when there are two equivalent JSON objects with different key ordering being compared with a third object. This is demonstrated in the test case.

I am not sure if we should sort the keys at ingestion time, or just sort them for the purposes of the hash computation in StructuredData.

Release note

Sort keys in JSON objects to resolve a transitivity bug in the StructuredData comparator


Key changed/added classes in this PR
  • ColumnSerializerUtils
  • StructuredDataTest

This PR has:

  • [X] been self-reviewed.
  • [ ] added documentation for new or modified features or behaviors.
  • [X] 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.
  • [X] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • [ ] added integration tests.
  • [X] been tested in a test Druid cluster.

aho135 avatar Jun 23 '25 21:06 aho135