-
Notifications
You must be signed in to change notification settings - Fork 54
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
Support java-class stringable property #724
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #724 +/- ##
==========================================
- Coverage 70.74% 70.61% -0.13%
==========================================
Files 44 44
Lines 1839 1865 +26
Branches 317 317
==========================================
+ Hits 1301 1317 +16
- Misses 538 548 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
ratatool-scalacheck/src/main/scala/com/spotify/ratatool/scalacheck/AvroGenerator.scala
Outdated
Show resolved
Hide resolved
@RustedBones I'll take a look on Monday, thanks for opening! |
@RustedBones the tests make sense, although I don't fully understand all of the details. Maybe you could explain a little more in detail about what your change fixes? Other than that, I don't have a problem just merging. |
@@ -95,18 +103,30 @@ class AvroGeneratorTest extends AnyFlatSpec with Matchers with ScalaCheckPropert | |||
.name("javaStringField").`type`().stringBuilder().prop(GenericData.STRING_PROP, "String").endString().noDefault() | |||
.name("charSequenceField").`type`().stringBuilder().prop(GenericData.STRING_PROP, "CharSequence").endString().noDefault() | |||
.name("utf8Field").`type`().stringBuilder().prop(GenericData.STRING_PROP, "CharSequence").endString().noDefault() | |||
.name("stringableBigDecimalField").`type`().stringBuilder().prop(SpecificData.CLASS_PROP, classOf[java.math.BigDecimal].getName).endString().noDefault() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avsc
equivalent for
{"type": "string", "java-class": "java.math.BigDecimal"}
@@ -95,18 +103,30 @@ class AvroGeneratorTest extends AnyFlatSpec with Matchers with ScalaCheckPropert | |||
.name("javaStringField").`type`().stringBuilder().prop(GenericData.STRING_PROP, "String").endString().noDefault() | |||
.name("charSequenceField").`type`().stringBuilder().prop(GenericData.STRING_PROP, "CharSequence").endString().noDefault() | |||
.name("utf8Field").`type`().stringBuilder().prop(GenericData.STRING_PROP, "CharSequence").endString().noDefault() | |||
.name("stringableBigDecimalField").`type`().stringBuilder().prop(SpecificData.CLASS_PROP, classOf[java.math.BigDecimal].getName).endString().noDefault() | |||
.name("stringableDefaultField").`type`().stringBuilder().prop(SpecificData.CLASS_PROP, classOf[StringableCustom].getName).endString().noDefault() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avsc
equivalent for
{"type": "string", "java-class": "com.spotify.ratatool.scalacheck.StringableCustom"}
Called default because no custom stringableGen
passed for this class
.name("mapDefaultKeyField").`type`().map().values().longType().noDefault() | ||
.name("mapJavaStringKeyField").`type`().map().prop(GenericData.STRING_PROP, "String").values().longType().noDefault() | ||
.name("mapStringableBigIntegerKeyField").`type`().map().prop(SpecificData.KEY_CLASS_PROP, classOf[java.math.BigInteger].getName).values().longType().noDefault() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avsc
equivalent for
{"type": "string", "java-class": "java.math.BigInteger"}
val stringableGens = Map[Class[_], Gen[_]]( | ||
classOf[java.math.BigDecimal] -> Gen.choose(BigDecimal(-1), BigDecimal(1)).map(_.bigDecimal), | ||
classOf[java.math.BigInteger] -> Gen | ||
.choose(BigInt(0), BigInt(Long.MaxValue)) | ||
.map(_.bigInteger) | ||
) | ||
val gen = avroOf(schema, stringableGens) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without those custom stringableGens
, random strings would be generated to create BigDecimal
and BigInteger
that most likely creates a parse exception.
Here we give custom generators for those types and bypass the conversion from string.
The StringableCustom
type not being part of the map will be constructed with random string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for helping me understand these changes, LGTM!
Attempt to support
java-class
andjava-key-class
as defined in the avro specificationjava-element-class
is only used in the reflect API