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

Magnolify API #5286

Merged
merged 30 commits into from
Apr 10, 2024
Merged

Magnolify API #5286

merged 30 commits into from
Apr 10, 2024

Conversation

kellen
Copy link
Contributor

@kellen kellen commented Mar 2, 2024

Adds magnolify-based 'typed' APIs.

This is a kind of brute-force change that adds several ugly but easily renamed APIs while not conflicting with the existing macro-based APIs, which we hope to deprecate in a future version. I attempted some advanced type gymnastics to allow better naming, but Miles Sabin I am not.

Deprecates AvroType and BigQueryType, breaks binary compatibility.

Avro

  • Adds the horrifically-named sc.typedAvroFileMagnolify, avoiding conflicts with avroFile and macro-based typedAvroFile. Alternative: typedAvro (no File)
  • Adds coll.saveAsAvroFile

Bigtable

  • Adds typedBigtable
  • Adds saveAsBigtable

BigQuery

  • Adds sc.typedBigQuerySelect, typedBigQueryTable; Select and Table to avoid conflicts with the macro read variants
  • Adds abhorrent typedBigQueryStorageMagnolify, avoiding conflicts with bigQueryStorage and macro-based typedBigQueryStorage
  • Adds saveAsBigQueryTable, avoiding macro-based saveAsTypedBigQueryTable. Other saveAsBigQueryTable variants are scoped to TableRow and GenericRecord.

Datastore

  • Adds typedDatastore
  • Adds saveAsDatastore

Protobuf

  • Adds typedProtobufFile
  • Adds saveAsProtobufFile

Tensorflow

  • Adds typedTfRecordFile
  • Adds saveAsTfRecordFile

Copy link

codecov bot commented Mar 2, 2024

Codecov Report

Attention: Patch coverage is 48.59813% with 110 lines in your changes are missing coverage. Please review.

Project coverage is 62.55%. Comparing base (a658edb) to head (c65354f).
Report is 9 commits behind head on v0.15.x.

❗ Current head c65354f differs from pull request most recent head 9bc45a1. Consider uploading reports for the commit 9bc45a1 to get more accurate results

Files Patch % Lines
...n/scala/com/spotify/scio/bigtable/BigTableIO.scala 11.32% 47 Missing ⚠️
...n/scala/com/spotify/scio/bigquery/BigQueryIO.scala 22.72% 17 Missing ⚠️
...scala/com/spotify/scio/datastore/DatastoreIO.scala 19.04% 17 Missing ⚠️
...otify/scio/bigtable/syntax/ScioContextSyntax.scala 38.46% 8 Missing ⚠️
...io/bigquery/dynamic/syntax/SCollectionSyntax.scala 0.00% 6 Missing ⚠️
...otify/scio/bigtable/syntax/SCollectionSyntax.scala 50.00% 4 Missing ⚠️
...scala/com/spotify/scio/tensorflow/TFRecordIO.scala 84.00% 4 Missing ⚠️
.../main/scala/com/spotify/scio/avro/ProtobufIO.scala 76.92% 3 Missing ⚠️
...main/scala/com/spotify/scio/avro/AvroTypedIO.scala 81.81% 2 Missing ⚠️
...rc/main/scala/com/spotify/scio/bigquery/taps.scala 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           v0.15.x    #5286      +/-   ##
===========================================
- Coverage    62.63%   62.55%   -0.09%     
===========================================
  Files          301      302       +1     
  Lines        10842    11013     +171     
  Branches       748      746       -2     
===========================================
+ Hits          6791     6889      +98     
- Misses        4051     4124      +73     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kellen kellen marked this pull request as ready for review March 8, 2024 03:17
build.sbt Outdated Show resolved Hide resolved
Comment on lines 104 to 106
data
.map(t => pt.to(t))
.write(underlying)(params.copy(metadata = metadata))
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be wrapped in a transform too ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately when calling write on an underlying IO, the returned tap obscures the contained steps. Specifically, this doesn't work:

data.transform { scoll =>
  scoll
      .map(t => pt.to(t))
      .write(underlying)(params.copy(metadata = metadata))
}

You can use writeWithContext directly ala:

underlying.writeWithContext(
  data.map(t => pt.to(t)),
  params.copy(metadata = metadata)
}

but this doesn't solve our issue as there is a single map step here so we wouldn't be combining any steps inside a transform (data.transform(_.map(t=>pt.to(t))) == data.map(t=>pt.to(t))) and any steps in the underlying transform are chained afterwards.

For these cases we'd need some way to capture or rewrite previous steps in the graph.

@kellen kellen changed the base branch from main to v0.15.x March 13, 2024 14:21
build.sbt Outdated Show resolved Hide resolved
* Read avro data from `path` as `GenericRecord` and convert to `T` via the implicitly-available
* `magnolify.avro.AvroType[T]`
*/
def typedAvroFileMagnolify[T: MagnolifyAvroType: Coder](
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO this was a mistake to name that typedAvro.... This should have been avroTyped....
This improves developer experience when APIs are grouped by prefix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, I've always found the typed prefix annoying. We could scalafix it I guess?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, the question is if we want that change for 0.15? We can discuss this later anyway. I'd better get this change in another PR

}
}

final class TypedMagnolifyAvroSCollectionOps[T](private val self: SCollection[T]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make T: AvroMagnolifyType part of TypedMagnolifyAvroSCollectionOps's context bound so that all methods have access to it?

Copy link
Contributor

@RustedBones RustedBones Mar 20, 2024

Choose a reason for hiding this comment

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

I vouched for the opposite in another comment :)
Reason: I'd rather have the method available to the IDE completion suggestion, even if there is no implicit found. This is also consistent with the coder behavior, required on the method rather that the implicit extensions

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense! I'm in favor of making APIs more IDE-friendly 👍

Copy link
Contributor

@RustedBones RustedBones left a comment

Choose a reason for hiding this comment

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

Note: since all Scio IOs are public, we should create scalafix migration rules to change to the new names

Copy link
Contributor

@RustedBones RustedBones left a comment

Choose a reason for hiding this comment

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

Great work.
Deprecation of the BQ api makes sense on the AvroType and toTable.

BQ from* does not really have an equivalent. I feel the redirection to magnolify can be confusing but I don't have better alternative.

Comment on lines +81 to +82
successfulInsertsPropagation: Boolean,
extendedErrorInfo: Boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

should we create overload ?

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'm ambivalent to/slightly against providing every possible override combination, so did not do that here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with that

@kellen kellen merged commit bcd7d5e into v0.15.x Apr 10, 2024
1 check passed
@kellen kellen deleted the kellen/magnolify-bt branch April 10, 2024 13:50
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.

3 participants