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

Fixes #45: Capture annotations in record schemas #66

Merged
merged 8 commits into from
May 17, 2021

Conversation

thinkharderdev
Copy link
Contributor

Fixes #45
Capture annotations in Record schemas:

  1. Macro derivation should capture both class and field-level annotations
  2. Introduce Schema.Field[A] type to encapsulate fields in Record schema
  3. Encode record fields as Seq[Schema.Field[_]] instead of ListMap[String,Schema[_]]. By using ListMap we lose O(1) lookups anyway so this seemed like the better encoding.

@thinkharderdev thinkharderdev requested a review from a team as a code owner May 17, 2021 13:57
@CLAassistant
Copy link

CLAassistant commented May 17, 2021

CLA assistant check
All committers have signed the CLA.

}

final case class GenericRecord(override val structure: ListMap[String, Schema[_]]) extends Record[ListMap[String, _]]
final case class GenericRecord(override val structure: Seq[Field[_]]) extends Record[ListMap[String, _]]
Copy link
Member

Choose a reason for hiding this comment

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

It's ok for Seq to appear in contravariant position (as an input to a method), but it should not appear in covariant position (as an output from a method) because it provides no Big Oh guarantees on any of its methods.

Instead, I suggest we refactor this to be Chunk[Field[_]] here and elsewhere, so that users have guaranteed O(1) random access, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense


sealed trait Record[R] extends Schema[R] {
def structure: Seq[Field[_]]
def annotations: Seq[Any] = Nil
Copy link
Member

Choose a reason for hiding this comment

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

Ditto for all covariant uses of Seq.

@jdegoes jdegoes merged commit c914158 into zio:main May 17, 2021
@jdegoes
Copy link
Member

jdegoes commented May 17, 2021

@thinkharderdev Thanks for your work on this! One step closer to the Ultimate Goal.

@thinkharderdev thinkharderdev deleted the issue/45 branch May 17, 2021 20:44
landlockedsurfer pushed a commit to landlockedsurfer/zio-schema that referenced this pull request May 28, 2022
* Fixes zio#45: Capture annotations in record schemas

* vscode settings

* Use zio.Chunk instead of Seq

* Add embeded metals.sbt to gitignore

* Remove embedded metals.sbt

* formatting

* reformatting
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

Successfully merging this pull request may close these issues.

Add support for annotations into Schema
3 participants