question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Map Builders should preserve order

See original GitHub issue

Object Builders for maps use an InternalMap which is a sub-class of a hash map:

https://github.com/elastic/elasticsearch-java/blob/75feae536d2c9bce755236c979416fd9d0652803/java-client/src/main/java/co/elastic/clients/util/ObjectBuilderBase.java#L91

Hash maps are unordered, the order is defined by the internal hashing function and can be different for different runtime environments. Although the JSON standard does not define dictionaries to be ordered, it would be good to switch to a linked hash map with insertion order:

  • for a user the order might have a meaning and it is easier for them if the order is preserved the way the user specified it, e.g. the output might be a ML job or transform configuration
  • in some cases order can be important at runtime: https://github.com/elastic/elasticsearch/issues/82350

Because this does not seems performance-critical, I suggest to switch to a linked hash map with insertion order

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hendrikmuhscommented, Jan 20, 2022

We have discussed the underlying issue in the backend team:

The transform API parses/stores/serializes the configuration in question in a way that preserves order, this works if the REST API is used directly. This is out of the specification and inconsistent to other parts of the stack. The reason for this feature is performance. Starting with 7.15 transform has some builtin optimizations for improving performance by optimizing the group by query. That’s one of the reasons why we’ve decided to keep the API the way it is and not change/enhance the syntax (make it order-aware or add sort criteria). We will rather spend more time on improving the optimizations. As a result we will adjust the documentation accordingly. If you are using REST it will still preserve order, but that’s considered an implementation detail.

That’s for the technical aspect of it. From a usability perspective I still think that consistent order helps UX. But that’s not my decision.

Thanks for your time, I will close the corresponding HLRC issue.

0reactions
hendrikmuhscommented, Jan 13, 2022

Let’s take this offline, it looks like gh is not the right place to discuss this, we seem to discuss different issues. I am very aware that JSON dictionaries do not define an order, I’ve never claimed so.

We will discuss in backend and get in touch afterwards.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Map that could be iterated in the order of values - Stack Overflow
I would do this with Guava as follows: Ordering<Map.Entry<Key, Value>> entryOrdering = Ordering.from(valueComparator) .onResultOf(new Function<Entry<Key, ...
Read more >
YOUR GUIDE TO MAPMAKER - National Geographic Society
Manage your maps: Each map you save is stored under Menu > My Maps. To delete a map, select the trash can icon...
Read more >
TABS Map Creator TUTORIAL - How to Use + Tips and Tricks!
TABS Map Creator TUTORIAL - How to Use + Tips and Tricks! 54K views · 1 month ago ...more. Plastic Scot. 83.4K. Subscribe....
Read more >
Configure the form—ArcGIS Field Maps | Documentation
If you use Map Viewer to edit or save the map, the form you configured in the Field Maps web app will be...
Read more >
Immutable objects
Without ordering annotations, ordered sets and maps attributes will be generated as regular attributes to support construction with custom comparators, etc. All ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found