-
Notifications
You must be signed in to change notification settings - Fork 514
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
To.safe #3767
base: main
Are you sure you want to change the base?
To.safe #3767
Conversation
else Some(ls.collect { case Some(x) => x }) | ||
|
||
private def interpret[T: scala.quoted.Type](using Quotes): Option[Schema[T]] = | ||
Type.of[T] match { |
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.
(copying my comment here since I originally made it on your fork)
Unless I'm missing something this means that the possible set of supported schema types is effectively limited to those already defined in scio.
If a user adds a given
instance of Schema
for type that isn't supported (say for example a Java class), the derivation will simply ignore it. This could be a problem for aliaswa support in Schema
but probably something we can live with. We don't really expect users to define their own instances of Schema
.
I'd be curious to see how the implementation looks like for Java beans and Avro's SpecificRecord
.
* Temporarily silence other jobs * Refactor scala3 version into a variable * Create ci job testing and compiling each subproject * Disable fail-fast * Use RC1 syntax for givens * Fix isJavaBean * Fix shadowing of BitSetCoder by private class * Remove call to showAnsiColored which does not exist anymore * Fix ambiguous resolution of implicit * Disable subprojects that don't build * Disable scio-core Co-authored-by: vincenzobaz <[email protected]>
…rides scio-macros depends only on java libs and scalatest. Scalatest is now available as a 3.0.0 lib as well, so withDottyCompat is not needed anymore.
To match the Scala 2 signature
More general types must be at the bottom
This PR proposes a solution to the To.safe blocker in Scala 3 on which @MaximeKjaer, @liufengyun and I worked.
It took us some time to get familiar with the API and we tested different strategies before landing on this code, but we think it shows the strengths of Scala 3 macros and reflection by combining the two APIs in a relatively concise and idiomatic function that does not need
eval
You can see a smaller diff here
The critical section is the file
scio-core/src/main/scala-3/com/spotify/scio/schemas/To.scala
where we use Scala 3 macros to pattern match on the type argumentT
ofExpr[Schema[T]]
to derive aSchema[T]
at compile time which can then be used to invokeTo.checkCompatibility
. To deal with case class and compile time derivedSchema
s we rely on the reflection API which allows us to access the names and types of the fields of the case class.You can see this the implementation here
This draft pr brings along many changes, in particular to build and syntax, that we adopted to use RC2, sbt 1.5, new syntax and to reduce the number of warnings.
We would like to have your opinion on this approach.
A few steps might be needed to finalize this pr:
caseFields
and<: Product
is a strong-enough conditionmain
as it progresses.