-
Notifications
You must be signed in to change notification settings - Fork 526
Report Beam Lineage from Parquet reads #5850
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
Draft
shnapz
wants to merge
9
commits into
main
Choose a base branch
from
akabas/parquet-lineage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+182
−72
Draft
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e0dc0a4
Report Beam Lineage from Parquet reads
shnapz 88cc967
Fix issues
shnapz d651108
refactor
shnapz 785ae4a
simplify docs
shnapz 4ea6923
Refactor a lil bit
shnapz 4a650a7
Move LineageDoFn outside of the object
shnapz fe790e7
move metrics report to processElement
shnapz 4c920e3
Update scio-parquet/src/main/scala/com/spotify/scio/parquet/HadoopPar…
shnapz b0a3741
Update scio-parquet/src/main/scala/com/spotify/scio/parquet/HadoopPar…
shnapz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
scio-parquet/src/main/scala/com/spotify/scio/parquet/LineageReportingDoFn.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright 2026 Spotify AB. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package com.spotify.scio.parquet | ||
|
|
||
| import org.apache.beam.sdk.io.FileSystems | ||
| import org.apache.beam.sdk.transforms.DoFn | ||
| import org.apache.beam.sdk.transforms.DoFn.{ProcessElement, Setup} | ||
| import org.slf4j.LoggerFactory | ||
|
|
||
| /** | ||
| * DoFn that reports directory-level source lineage for legacy Parquet reads. | ||
| * | ||
| * @param filePattern | ||
| * The file pattern or path to report lineage for | ||
| */ | ||
| private[parquet] class LineageReportingDoFn[T](filePattern: String) extends DoFn[T, T] { | ||
|
|
||
| @transient | ||
| private lazy val logger = LoggerFactory.getLogger(classOf[LineageReportingDoFn[T]]) | ||
|
|
||
| @Setup | ||
| def setup(): Unit = { | ||
| try { | ||
| val isDirectory = filePattern.endsWith("/") | ||
| val resourceId = FileSystems.matchNewResource(filePattern, isDirectory) | ||
| val directory = resourceId.getCurrentDirectory | ||
| FileSystems.reportSourceLineage(directory) | ||
| } catch { | ||
| case e: Exception => | ||
| logger.warn( | ||
| s"Error when reporting lineage for pattern: $filePattern", | ||
| e | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @ProcessElement | ||
| def processElement(@DoFn.Element element: T, out: DoFn.OutputReceiver[T]): Unit = | ||
| out.output(element) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ import com.spotify.scio.coders.{Coder, CoderMaterializer} | |
| import com.spotify.scio.io.{ScioIO, Tap, TapOf, TapT} | ||
| import com.spotify.scio.parquet.ParquetConfiguration | ||
| import com.spotify.scio.parquet.read.{ParquetRead, ParquetReadConfiguration, ReadSupportFactory} | ||
| import com.spotify.scio.parquet.{BeamInputFile, GcsConnectorUtil} | ||
| import com.spotify.scio.parquet.{BeamInputFile, GcsConnectorUtil, LineageReportingDoFn} | ||
| import com.spotify.scio.testing.TestDataManager | ||
| import com.spotify.scio.util.ScioUtil | ||
| import com.spotify.scio.util.FilenamePolicySupplier | ||
|
|
@@ -39,8 +39,8 @@ import org.apache.beam.sdk.io.hadoop.format.HadoopFormatIO | |
| import org.apache.beam.sdk.io._ | ||
| import org.apache.beam.sdk.io.fs.ResourceId | ||
| import org.apache.beam.sdk.options.ValueProvider.StaticValueProvider | ||
| import org.apache.beam.sdk.transforms.SerializableFunctions | ||
| import org.apache.beam.sdk.transforms.SimpleFunction | ||
| import org.apache.beam.sdk.transforms.{ParDo, SerializableFunctions, SimpleFunction} | ||
| import org.apache.beam.sdk.values.KV | ||
| import org.apache.hadoop.conf.Configuration | ||
| import org.apache.hadoop.mapreduce.Job | ||
| import org.apache.parquet.filter2.predicate.FilterPredicate | ||
|
|
@@ -100,7 +100,8 @@ final case class ParquetExampleIO(path: String) extends ScioIO[Example] { | |
| params: ReadP | ||
| ): SCollection[Example] = { | ||
| val job = Job.getInstance(conf) | ||
| GcsConnectorUtil.setInputPaths(sc, job, path) | ||
| val filePattern = ScioUtil.filePattern(path, params.suffix) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am surprised suffix was not used initially. Or was it intentional? |
||
| GcsConnectorUtil.setInputPaths(sc, job, filePattern) | ||
| job.setInputFormatClass(classOf[TensorflowExampleParquetInputFormat]) | ||
| job.getConfiguration.setClass("key.class", classOf[Void], classOf[Void]) | ||
| job.getConfiguration.setClass("value.class", classOf[Example], classOf[Example]) | ||
|
|
@@ -122,7 +123,14 @@ final case class ParquetExampleIO(path: String) extends ScioIO[Example] { | |
| override def apply(input: Void): JBoolean = true | ||
| }) | ||
| .withConfiguration(job.getConfiguration) | ||
| sc.applyTransform(source).map(_.getValue) | ||
|
|
||
| sc.applyTransform(source) | ||
| .applyTransform( | ||
| ParDo.of( | ||
| new LineageReportingDoFn[KV[JBoolean, Example]](filePattern) | ||
| ) | ||
| ) | ||
| .map(_.getValue) | ||
| } | ||
|
|
||
| override protected def readTest(sc: ScioContext, params: ReadP): SCollection[Example] = { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is different than the hadoop one insofar as we get every file here, right? That seems bad/annoying for using the lineage for anything
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.
Actually file-level lineage is the default approach in Beam. Which we might not need directly. Both Lineage Metric implementations (legacy and new one) work ok with many files:
StringSet has internal truncation to 100
BoundedTrie is a data structure that stores hierarchical data very well