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

Adds logical and fixed types to code generation #340

Merged
merged 36 commits into from Oct 15, 2020

Conversation

dzanot
Copy link
Contributor

@dzanot dzanot commented Sep 30, 2020

This is the first step to replacing avro hugger code generation with skeuomorph codegen in sbt-mu-srcgen outlined in this ticket.
It adds the logical types that are supported in the 1.10.0 avro compiler, as well as modifying the MuF.TByteArray type to include the info of the avro fixed types.

@codecov
Copy link

codecov bot commented Sep 30, 2020

Codecov Report

Merging #340 into master will increase coverage by 1.18%.
The diff coverage is 66.43%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #340      +/-   ##
==========================================
+ Coverage   84.02%   85.20%   +1.18%     
==========================================
  Files          29       29              
  Lines        1909     1954      +45     
  Branches       26       28       +2     
==========================================
+ Hits         1604     1665      +61     
+ Misses        305      289      -16     
Impacted Files Coverage Δ
...kindness/skeuomorph/mu/comparison/Comparison.scala 76.84% <14.28%> (-1.66%) ⬇️
...cala/higherkindness/skeuomorph/avro/Protocol.scala 35.71% <24.00%> (+3.89%) ⬆️
...in/scala/higherkindness/skeuomorph/mu/schema.scala 65.33% <54.16%> (+1.04%) ⬆️
.../scala/higherkindness/skeuomorph/avro/schema.scala 62.22% <77.08%> (+4.59%) ⬆️
...n/scala/higherkindness/skeuomorph/mu/codegen.scala 91.83% <89.47%> (+2.82%) ⬆️
...la/higherkindness/skeuomorph/SkeuomorphError.scala 40.00% <100.00%> (+40.00%) ⬆️
.../scala/higherkindness/skeuomorph/mu/Optimize.scala 100.00% <100.00%> (+45.00%) ⬆️
...scala/higherkindness/skeuomorph/mu/Transform.scala 93.33% <100.00%> (+21.90%) ⬆️
.../scala/higherkindness/skeuomorph/mu/protocol.scala 97.29% <100.00%> (+0.15%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24e7bf1...c3d5e45. Read the comment docs.

@juanpedromoreno juanpedromoreno changed the title Marlow 543 Replace avrohugger with skeuomorph Oct 2, 2020
@dzanot dzanot changed the title Replace avrohugger with skeuomorph Adds logical and fixed types to code generation Oct 6, 2020
build.sbt Outdated
"io.circe" %% "circe-parser" % "0.13.0",
"io.circe" %% "circe-yaml" % "0.13.1",
"org.scalameta" %% "scalameta" % "4.3.22",
"com.julianpeeters" %% "avrohugger-core" % "1.0.0-RC22" % Test,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed avro-compiler in favor of avrohugger-core as the latter with remove imported structures from the resulting org.apache.avro.Protocol structure.
This caused some incompatibility issue with the scala-collection-compat library so I removed that dependency as well which didn't cause any apparent failures.

options = Nil,
declarations = proto.types.map(toMu),
services = List(
val services = if (proto.messages.isEmpty) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to prevent an empty service when there are no rpc methods defined in the avdl

L-Lavigne
L-Lavigne previously approved these changes Oct 7, 2020
Copy link
Contributor

@L-Lavigne L-Lavigne left a comment

Choose a reason for hiding this comment

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

Good work! Approved with some nitpicks in one of the tests.

def checkGenerated(idlName: String) = {
val idlResourceName = s"avro/${idlName}.avdl"
val idlUri = Try(getClass.getClassLoader.getResource(idlResourceName).toURI)
.getOrElse(throw new Exception(s"No avdl found for name: ${idlName}"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a nitpick for a few places in this file: if I don't have a specific exception to throw I like to shorten throw new Exception to sys.error. Also some of the interpolated strings here don't need curly brackets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed both of these

case Right(protocol) => protocol
}
val avroProto = avroProtos
.find(p => p.getName == idlName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Another nitpick: we can probably combine this check with the collect partial function above (changing it to collectFirst).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good spot, changed this

@@ -89,53 +112,41 @@ class AvroSpec extends Specification with ScalaCheck {
t"Stream[$f, $a]"
}

val actual = codegen.protocol(muProto, streamCtor).right.get
val actual = codegen.protocol(muProto, streamCtor).fold(s => throw new Exception(s), identity)
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we could wrap expected in an Either Right so we don't need to extract actual before comparing them.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dzanot I see this wasn't applied so just curious, would there be issues with such a change? Perhaps it would hinder the custom comparison message in which case we'd probably have to keep the test as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This actually changed but the test is in the new AvroProtocolSpec.scala file here https://github.com/higherkindness/skeuomorph/pull/340/files#diff-791c60e0123c350ef43edff0c1b159887e0163be800c85b7b700494cab9edfa7R117
Not sure why github is still showing this one though

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah I think this is because we are calling .isEqual for comparison. I tried refactoring so both actual and expected were Either, but using the specs2 shouldEqual matcher is using different equality. I can keep poking to see if I can configure specs2 it to use the scala meta isEqual

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah no worries then, it would be a nice to have but not worth spending too much time on IMO.

@dzanot dzanot requested a review from L-Lavigne October 14, 2020 16:10
@dzanot
Copy link
Contributor Author

dzanot commented Oct 14, 2020

@L-Lavigne I've addressed your comments, and made some changes since merging latest master. Can you take another look?

L-Lavigne
L-Lavigne previously approved these changes Oct 14, 2020
@dzanot
Copy link
Contributor Author

dzanot commented Oct 14, 2020

Sorry @L-Lavigne ... I removed some unused imports and dismissed your approval

Copy link
Contributor

@L-Lavigne L-Lavigne left a comment

Choose a reason for hiding this comment

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

@dzanot Could you add some labels to the PR for the auto-changelog?

@dzanot dzanot added enhancement New feature or request tests Improves or modifies tests labels Oct 15, 2020
@dzanot dzanot merged commit 05118bc into higherkindness:master Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tests Improves or modifies tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants