Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shift to use ordered maps for Schema.Record and Schema.Enumeration #5

Closed
jdegoes opened this issue Nov 22, 2020 · 1 comment
Closed

Comments

@jdegoes
Copy link
Member

jdegoes commented Nov 22, 2020

Currently, we are using a Map for the keys in records and enumerations, which means that we cannot rely on the key ordering. Yet for some protocols, such as grpc, the ordering is very important: it must be stable and ideally reflected by case class / subtype ordering. In order to accommodate this, we need to switch to a map type that allows linear ordering of keys.

Scala has SortedMap, which could be used, but is not really ideal (it wants to order based on a property of the keys, but that would force us to store (Int, String) in the map, which is unpleasant to work with). Possibly we could use an ordinary map, together with an array that maintains key ordering; or we could create our own OrderedMap type.

@eriktim eriktim mentioned this issue Nov 29, 2020
2 tasks
@V-Lamp
Copy link

V-Lamp commented May 5, 2021

Hey, you could use ListMap

List map iterators and traversal methods visit key-value pairs in the order they were first inserted.

thinkharderdev added a commit to thinkharderdev/zio-schema that referenced this issue May 6, 2021
thinkharderdev added a commit to thinkharderdev/zio-schema that referenced this issue May 6, 2021
Add UnorderedRecord for case classes with arity > 22 and CaseObject for objects

Use ListMap for case class encoding to guarantee preserved insert order

Use 2.12 compatible SortedMap and ListMap
@jdegoes jdegoes closed this as completed in fb5e766 May 8, 2021
landlockedsurfer pushed a commit to landlockedsurfer/zio-schema that referenced this issue May 28, 2022
* Fixes zio#5: Use SortedMap for generic Record and Enumeration schemas

Add UnorderedRecord for case classes with arity > 22 and CaseObject for objects

Use ListMap for case class encoding to guarantee preserved insert order

Use 2.12 compatible SortedMap and ListMap

* Resolve conflicts after rebase

* Use ListMap for generic structure encoding

* Merge upstream/main

* work around yet another jdk8 bug

Co-authored-by: thinkharder <thinkharderdev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants