-
Notifications
You must be signed in to change notification settings - Fork 23
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
merge_manifests fix for rows with no guid #196
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
45fafc7
merge_manifests fix for rows with no guid
SpencerAxelrod 172b64f
Apply automatic documentation changes
SpencerAxelrod b9349e0
remove comment
SpencerAxelrod 63843e0
Merge remote-tracking branch 'refs/remotes/origin/fix/merge_bucket_ma…
SpencerAxelrod 559f35f
Apply automatic documentation changes
SpencerAxelrod 2de3a7c
fix comments
SpencerAxelrod 603e9c9
Apply automatic documentation changes
SpencerAxelrod 7993675
Revert "Apply automatic documentation changes"
SpencerAxelrod a7b78d1
Revert "Apply automatic documentation changes"
SpencerAxelrod 2b7a646
Revert "Apply automatic documentation changes"
SpencerAxelrod 58ba20f
Merge branch 'master' into fix/merge_bucket_manifest_fix
SpencerAxelrod 58470f5
Apply automatic documentation changes
SpencerAxelrod 40f9e45
add test for no guid merge order
SpencerAxelrod 48d3015
Apply automatic documentation changes
SpencerAxelrod 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -106,17 +106,23 @@ def merge_bucket_manifests( | |
|
||
headers = set() | ||
all_rows = {} | ||
records_with_no_guid = [] | ||
for manifest in files: | ||
records_from_file, _ = get_and_verify_fileinfos_from_manifest( | ||
manifest, include_additional_columns=True | ||
) | ||
records_with_no_guid = [] | ||
for record in records_from_file: | ||
# simple case where this is the first time we've seen this hash | ||
headers.update(record.keys()) | ||
if record[MD5_STANDARD_KEY] not in all_rows: | ||
record_to_write = copy.deepcopy(record) | ||
all_rows[record_to_write[MD5_STANDARD_KEY]] = [record_to_write] | ||
|
||
new_guid = record.get(GUID_STANDARD_KEY) | ||
if not new_guid: | ||
# since there's no guid specified to differentiate this from other | ||
# entries, we will add metadata to all records later | ||
records_with_no_guid.append(record) | ||
else: | ||
# if the hash already exists, we need to try and update existing | ||
# entries with any new data (and ensure we don't add duplicates) | ||
|
@@ -143,36 +149,35 @@ def merge_bucket_manifests( | |
) | ||
all_rows[record[MD5_STANDARD_KEY]] = updated_records.values() | ||
|
||
# for the entries where there was no GUID specified, we will add that metadata | ||
# to all previous records | ||
for record in records_with_no_guid: | ||
updated_records = _get_updated_records( | ||
record=record, | ||
existing_records=all_rows.get(record[MD5_STANDARD_KEY], []), | ||
continue_after_error=continue_after_error, | ||
allow_mult_guids_per_hash=allow_mult_guids_per_hash, | ||
columns_with_arrays=columns_with_arrays, | ||
) | ||
# it's possible a record without a GUID got added if it was the FIRST | ||
# instance of that md5, so we just need to make sure that it's removed | ||
# if there was another GUID provided later on | ||
# | ||
# this also handles the edge case where there were multiple rows for the md5 | ||
# and NO guid was provided (e.g. we want a single combined row of updated values) | ||
any_guid_provided = [ | ||
record.get(GUID_STANDARD_KEY) | ||
# for the entries where there was no GUID specified, we will add that metadata | ||
# to all previous records | ||
for record in records_with_no_guid: | ||
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. see above comment re: moving this loop outside of |
||
updated_records = _get_updated_records( | ||
record=record, | ||
existing_records=all_rows.get(record[MD5_STANDARD_KEY], []), | ||
continue_after_error=continue_after_error, | ||
allow_mult_guids_per_hash=allow_mult_guids_per_hash, | ||
columns_with_arrays=columns_with_arrays, | ||
) | ||
# it's possible a record without a GUID got added if it was the FIRST | ||
# instance of that md5, so we just need to make sure that it's removed | ||
# if there was another GUID provided later on | ||
# | ||
# this also handles the edge case where there were multiple rows for the md5 | ||
# and NO guid was provided (e.g. we want a single combined row of updated values) | ||
any_guid_provided = [ | ||
record.get(GUID_STANDARD_KEY) | ||
for record in updated_records.values() | ||
if record.get(GUID_STANDARD_KEY) | ||
] | ||
if not any_guid_provided: | ||
all_rows[record[MD5_STANDARD_KEY]] = updated_records.values() | ||
else: | ||
all_rows[record[MD5_STANDARD_KEY]] = [ | ||
record | ||
for record in updated_records.values() | ||
if record.get(GUID_STANDARD_KEY) | ||
] | ||
if not any_guid_provided: | ||
all_rows[record[MD5_STANDARD_KEY]] = updated_records.values() | ||
else: | ||
all_rows[record[MD5_STANDARD_KEY]] = [ | ||
record | ||
for record in updated_records.values() | ||
if record.get(GUID_STANDARD_KEY) | ||
] | ||
|
||
_create_output_file( | ||
output_manifest, headers, all_rows, output_manifest_file_delimiter | ||
) | ||
|
2 changes: 2 additions & 0 deletions
2
tests/merge_manifests/no_guid_same_md5_order/expected-merged-output-manifest.tsv
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
guid size md5 acl authz urls metadata | ||
dg.4503/1234abcd 1193060 2de45cf5e6b2639c98b56b679cffc119 admin phsXXXXXX.c1 AUTHZ_HERE gs://path s3://path some_data |
2 changes: 2 additions & 0 deletions
2
tests/merge_manifests/no_guid_same_md5_order/input/manifest_WITHOUT_guid.tsv
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
guid size md5 acl authz urls metadata | ||
1193060 2de45cf5e6b2639c98b56b679cffc119 phsXXXXXX.c1 admin AUTHZ_HERE gs://path s3://path some_data |
2 changes: 2 additions & 0 deletions
2
tests/merge_manifests/no_guid_same_md5_order/input/manifest_with_guid.tsv
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
guid size md5 acl authz urls metadata | ||
dg.4503/1234abcd 1193060 2de45cf5e6b2639c98b56b679cffc119 phsXXXXXX.c1 admin AUTHZ_HERE gs://path s3://path some_data |
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
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.
move
records_with_no_guid
initialization, as well as thefor record in records_with_no_guid
loop to outside thefor manifest in files:
loop. This would process the records with no guid after all manifests rows have been initially processed.