-
Notifications
You must be signed in to change notification settings - Fork 513
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
(scio-smb) Support mixed FileOperations per BucketedInput #5064
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9f8072e
Support mixed FileOperations per source in SortedBucketSource
clairemcginty 52bd353
cleanup
clairemcginty b072035
Include filenameSuffix with fileOperations
clairemcginty 87cf839
fix Coder compat check; fix test
clairemcginty 1be2bbe
Refactor partition-compatibility check to use hashed value
clairemcginty 95f75f9
cleanup
clairemcginty 563fb43
Less wasteful ptransform serialization
clairemcginty 00f41da
ParquetAvroFileOperations getCoder should match AvroFileOperations ge…
clairemcginty d62b24f
Test specific + generic reads
clairemcginty a45419c
fetchMetadata must use a List for deterministic batching
clairemcginty 2825981
Make SortedBucketIO.Read extendable for multi-format
clairemcginty a4e2193
Fixup SortedBucketIO.Read signature
clairemcginty 1925d7e
Make getInputDirectories() public for extensions
clairemcginty 875ae0e
PR comments
clairemcginty ab1ec15
Encode BucketedInput as indexed map of FileOperations/FileSuffixes
clairemcginty 25dbe46
Add BucketedInput#getInputs to unlock SMB taps
clairemcginty 0350664
Use AvroCoder.reflect
clairemcginty ae11f9a
Use local variable
clairemcginty 8f39bd1
Use SerializableCoder
clairemcginty 4271462
cleanup
clairemcginty 29a6295
move coders to static variables
clairemcginty 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
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -23,8 +23,8 @@ | |
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.function.BiFunction; | ||
import org.apache.beam.sdk.extensions.smb.SMBFilenamePolicy.FileAssignment; | ||
import org.apache.beam.sdk.io.FileSystems; | ||
import org.apache.beam.sdk.io.fs.ResourceId; | ||
import org.apache.beam.sdk.values.KV; | ||
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting; | ||
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions; | ||
|
||
|
@@ -69,15 +69,14 @@ int leastNumBuckets() { | |
this.batchSize = batchSize; | ||
} | ||
|
||
private <V> Map<ResourceId, BucketMetadata<?, ?, V>> fetchMetadata(List<String> directories) { | ||
private <V> Map<ResourceId, BucketMetadata<?, ?, V>> fetchMetadata(List<ResourceId> directories) { | ||
final int total = directories.size(); | ||
final Map<ResourceId, BucketMetadata<?, ?, V>> metadata = new ConcurrentHashMap<>(); | ||
int start = 0; | ||
while (start < total) { | ||
directories.stream() | ||
.skip(start) | ||
.limit(batchSize) | ||
.map(dir -> FileSystems.matchNewResource(dir, true)) | ||
.parallel() | ||
.forEach(dir -> metadata.put(dir, BucketMetadata.get(dir))); | ||
start += batchSize; | ||
|
@@ -86,11 +85,11 @@ int leastNumBuckets() { | |
} | ||
|
||
private <V> SourceMetadata<V> getSourceMetadata( | ||
List<String> directories, | ||
String filenameSuffix, | ||
Map<ResourceId, KV<String, FileOperations<V>>> directories, | ||
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. Nit: This is now a bit more than direcories. Would probably be nice to change naming for smth more precise like |
||
BiFunction<BucketMetadata<?, ?, V>, BucketMetadata<?, ?, V>, Boolean> | ||
compatibilityCompareFn) { | ||
final Map<ResourceId, BucketMetadata<?, ?, V>> bucketMetadatas = fetchMetadata(directories); | ||
final Map<ResourceId, BucketMetadata<?, ?, V>> bucketMetadatas = | ||
fetchMetadata(new ArrayList<>(directories.keySet())); | ||
Preconditions.checkState(!bucketMetadatas.isEmpty(), "Failed to find metadata"); | ||
|
||
Map<ResourceId, SourceMetadataValue<V>> mapping = new HashMap<>(); | ||
|
@@ -107,24 +106,22 @@ private <V> SourceMetadata<V> getSourceMetadata( | |
metadata, | ||
first.getValue()); | ||
final FileAssignment fileAssignment = | ||
new SMBFilenamePolicy(dir, metadata.getFilenamePrefix(), filenameSuffix) | ||
new SMBFilenamePolicy( | ||
dir, metadata.getFilenamePrefix(), directories.get(dir).getKey()) | ||
.forDestination(); | ||
mapping.put(dir, new SourceMetadataValue<>(metadata, fileAssignment)); | ||
}); | ||
return new SourceMetadata<>(mapping); | ||
} | ||
|
||
public <V> SourceMetadata<V> getPrimaryKeyedSourceMetadata( | ||
List<String> directories, String filenameSuffix) { | ||
return getSourceMetadata( | ||
directories, filenameSuffix, BucketMetadata::isPartitionCompatibleForPrimaryKey); | ||
Map<ResourceId, KV<String, FileOperations<V>>> directories) { | ||
return getSourceMetadata(directories, BucketMetadata::isPartitionCompatibleForPrimaryKey); | ||
} | ||
|
||
public <V> SourceMetadata<V> getPrimaryAndSecondaryKeyedSourceMetadata( | ||
List<String> directories, String filenameSuffix) { | ||
Map<ResourceId, KV<String, FileOperations<V>>> directories) { | ||
return getSourceMetadata( | ||
directories, | ||
filenameSuffix, | ||
BucketMetadata::isPartitionCompatibleForPrimaryAndSecondaryKey); | ||
directories, BucketMetadata::isPartitionCompatibleForPrimaryAndSecondaryKey); | ||
} | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.
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.
the secondary key impl. (lexicographic) we have today is one way of implementing it, which in some cases like analytics is less efficient/common as opposed to sth like z-ordering. Might be nice to think a bit more to find out with a more future proof API e.g. support N keys?