graphcast.util.merge
¶
Document merging and discrimination utilities.
This module provides functions for merging and discriminating between documents based on various criteria. It supports merging documents with common keys, discriminating based on specific values, and handling different document structures.
Key Functions
- discriminate_by_key: Filter documents based on index fields and key presence
- merge_doc_basis: Merge documents based on common index keys
discriminate_by_key(items, indexes, discriminant_key, fast=False)
¶
Filter documents based on index fields and key presence.
This function filters a list of documents based on the presence of index fields and a specific key. It can operate in fast mode to return after finding the first match.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items
|
List of documents (dictionaries) to filter |
required | |
indexes
|
List of index field names to check for presence |
required | |
discriminant_key
|
Key to check for presence |
required | |
fast
|
Whether to return after first match (default: False) |
False
|
Returns:
Type | Description |
---|---|
list[dict]: Filtered list of documents |
Source code in graphcast/util/merge.py
merge_doc_basis(docs, index_keys, discriminant_key=None)
¶
Merge documents based on common index keys.
This function merges documents that share common index key-value combinations. Documents without index keys are merged with the first relevant document that has the discriminant key.
Note
Currently works best with two groups of documents: those with and without the discriminant key. Future versions will support multiple discriminant value groups.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs
|
list[dict]
|
List of documents to merge |
required |
index_keys
|
tuple[str, ...]
|
Tuple of key names to use for merging |
required |
discriminant_key
|
Optional key to use for merging documents without index keys |
None
|
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: Merged documents |