[fix] Fix BatchMeta.union semantics#95
Merged
Merged
Conversation
Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>
CLA Signature Pass0oshowero0, thanks for your pull request. All authors of the commits have signed the CLA. 👍 |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes BatchMeta.union from “deduplicate by global_index” semantics to “merge field schemas for the same samples”, requiring identical global_indexes and partition_ids and combining metadata/flags accordingly. It updates the tutorial to reflect the new meaning of union vs concat and adds tests covering the revised behavior.
Changes:
- Redefined
BatchMeta.unionto require matching indices/partitions and to mergefield_schema,production_status,extra_info, and per-sample metadata. - Updated the metadata tutorial example and explanation to match the new “append columns/fields” union semantics.
- Added unit tests validating success cases, overlap behavior, conservative readiness merging, and mismatch errors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tutorial/03_metadata_concepts.py | Updates tutorial example/output to demonstrate field-merge union semantics. |
| transfer_queue/metadata.py | Reimplements BatchMeta.union to merge fields for identical samples and adds validation. |
| tests/test_metadata.py | Adds tests for the new union behavior and validation errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+631
to
+643
| if self.global_indexes != other.global_indexes: | ||
| raise ValueError( | ||
| f"BatchMeta.union: global_indexes do not match. " | ||
| f"self.global_indexes={self.global_indexes}, " | ||
| f"other.global_indexes={other.global_indexes}" | ||
| ) | ||
|
|
||
| if not unique_indices_in_other: | ||
| return self | ||
| if self.partition_ids != other.partition_ids: | ||
| raise ValueError( | ||
| f"BatchMeta.union: partition_ids do not match. " | ||
| f"self.partition_ids={self.partition_ids}, " | ||
| f"other.partition_ids={other.partition_ids}" | ||
| ) |
Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>
CLA Signature Pass0oshowero0, thanks for your pull request. All authors of the commits have signed the CLA. 👍 |
BatchMeta.union functionalityBatchMeta.union semantics
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
PR https://gitcode.com/Ascend/TransferQueue/pull/28 incorrectly rewrote
BatchMeta.unionto behave likeconcatwith global_index deduplication.global_indexes(row-aligned, column-expanded).otherwhoseglobal_indexesare not present inself.This broke the design boundary between
union(same rows, merge columns) andconcat(same columns, append rows).Changes
1. Restore
BatchMeta.union(transfer_queue/metadata.py)size,global_indexes, andpartition_ids.field_schemawithotheroverridingselfon name conflicts.production_statusconservatively vianp.bitwise_and(both sides must report ready).extra_info,custom_meta, and_custom_backend_metaper sample.2. Update tutorial (
tutorial/03_metadata_concepts.py)attention_maskpresent in both batches) to demonstrate the override behavior.concat(append rows) vsunion(merge columns).3. Update unit tests (
tests/test_metadata.py)