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

Update FixAvroCoder to match transformed Avro SCollections #5351

Merged
merged 2 commits into from
May 2, 2024

Conversation

clairemcginty
Copy link
Contributor

Our Scalafix rule was missing utility-type classes that contain helper methods for SCollections, like:

  def someMethod(data: SCollection[A]): SCollection[(String, A)] = {
    data.map(r => ("foo", r))
  }

This updates the rule to check for method that returns SCollection[T <: SpecificRecord]. There's a tiny chance of a false positive if the method doesn't actually invoke any SCollection mapper functions but I don't think that usage is very common. I could update the method to inspect the function body for usage of functions with a Coder bound but I think that would be very error-prone

@clairemcginty clairemcginty marked this pull request as ready for review May 2, 2024 10:23
.exists {
case TypeSignature(_, _, TypeRef(_, maybeAvroType, _)) =>
AvroMatcher.matches(maybeAvroType)
case _ => false
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 was getting a compiler warning about this line, so added the exhaustive matcher

package fix.v0_14_0

import com.spotify.scio.values.SCollection
import com.spotify.scio.avro._
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we add the import here ? It is a false positive ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is needed in this case -- without it, data.map(r => ("foo", r)) throws a Compilation error:

[error] /Users/clairem/scio/scalafix/output-0_14/src/main/scala/fix/v0_14_0/FixAvroCoder16.scala:9:13: 
[error] Cannot find an implicit Coder instance for type:
[error] 
[error]   >> (String, fix.v0_14_0.A)

Copy link
Contributor

Choose a reason for hiding this comment

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

I forgot A is not a generic type but a SpecificRecord 🤦‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha, we probably could have given it a better class name 😅

@clairemcginty clairemcginty merged commit da05566 into main May 2, 2024
12 checks passed
@clairemcginty clairemcginty deleted the avro-coder-rule-update branch May 2, 2024 12:48
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.

2 participants