Builders
One-to-One Map Builder and a simple CopyBuilder implementation.
CopyBuilder
¶
Bases: MapBuilder
Sync a source store with a target store.
Source code in src/maggma/builders/map_builder.py
211 212 213 214 215 216 217 218 219 220 |
|
unary_function(item)
¶
Identity function for copy builder map operation.
Source code in src/maggma/builders/map_builder.py
214 215 216 217 218 219 220 |
|
MapBuilder
¶
Bases: Builder
Apply a unary function to yield a target document for each source document.
Supports incremental building, where a source document gets built only if it has newer (by last_updated_field) data than the corresponding (by key) target document.
Source code in src/maggma/builders/map_builder.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
__init__(source, target, query=None, projection=None, delete_orphans=False, timeout=0, store_process_time=True, retry_failed=False, **kwargs)
¶
Apply a unary function to each source document.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
Store
|
source store |
required |
target |
Store
|
target store |
required |
query |
Optional[dict]
|
optional query to filter source store |
None
|
projection |
Optional[list]
|
list of keys to project from the source for processing. Limits data transfer to improve efficiency. |
None
|
delete_orphans |
bool
|
Whether to delete documents on target store with key values not present in source store. Deletion happens after all updates, during Builder.finalize. |
False
|
timeout |
int
|
maximum running time per item in seconds |
0
|
store_process_time |
bool
|
If True, add "_process_time" key to document for profiling purposes |
True
|
retry_failed |
bool
|
If True, will retry building documents that previously failed |
False
|
Source code in src/maggma/builders/map_builder.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
ensure_indexes()
¶
Ensures indices on critical fields for MapBuilder.
Source code in src/maggma/builders/map_builder.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
finalize()
¶
Finalize MapBuilder operations including removing orphaned documents.
Source code in src/maggma/builders/map_builder.py
186 187 188 189 190 191 192 193 194 195 196 197 |
|
get_items()
¶
Generic get items for Map Builder designed to perform incremental building.
Source code in src/maggma/builders/map_builder.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
prechunk(number_splits)
¶
Generic prechunk for map builder to perform domain-decomposition by the key field.
Source code in src/maggma/builders/map_builder.py
89 90 91 92 93 94 95 96 97 98 99 |
|
process_item(item)
¶
Generic process items to process a dictionary using a map function.
Source code in src/maggma/builders/map_builder.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
unary_function(item)
abstractmethod
¶
Unary function to process item
You do not need to provide values for source.key and source.last_updated_field in the output. Any uncaught exceptions will be caught by process_item and logged to the "error" field in the target document.
Source code in src/maggma/builders/map_builder.py
199 200 201 202 203 204 205 206 207 208 |
|
update_targets(items)
¶
Generic update targets for Map Builder.
Source code in src/maggma/builders/map_builder.py
173 174 175 176 177 178 179 180 181 182 183 184 |
|
Many-to-Many GroupBuilder.
GroupBuilder
¶
Bases: Builder
Group source docs and produces merged documents for each group Supports incremental building, where a source group gets (re)built only if it has a newer (by last_updated_field) doc than the corresponding (by key) target doc.
This is a Many-to-One or Many-to-Many Builder. As a result, this builder can't determine when a source document is orphaned.
Source code in src/maggma/builders/group_builder.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
__init__(source, target, grouping_keys, query=None, projection=None, timeout=0, store_process_time=True, retry_failed=False, **kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
Store
|
source store |
required |
target |
Store
|
target store |
required |
query |
Optional[dict]
|
optional query to filter items from the source store. |
None
|
projection |
Optional[list]
|
list of keys to project from the source for processing. Limits data transfer to improve efficiency. |
None
|
delete_orphans |
Whether to delete documents on target store with key values not present in source store. Deletion happens after all updates, during Builder.finalize. |
required | |
timeout |
int
|
maximum running time per item in seconds |
0
|
store_process_time |
bool
|
If True, add "_process_time" key to document for profiling purposes |
True
|
retry_failed |
bool
|
If True, will retry building documents that previously failed. |
False
|
Source code in src/maggma/builders/group_builder.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
ensure_indexes()
¶
Ensures indices on critical fields for GroupBuilder which include the plural version of the target's key field.
Source code in src/maggma/builders/group_builder.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
get_groups_from_keys(keys)
¶
Get the groups by grouping_keys for these documents.
Source code in src/maggma/builders/group_builder.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
get_ids_to_process()
¶
Gets the IDs that need to be processed.
Source code in src/maggma/builders/group_builder.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
prechunk(number_splits)
¶
Generic prechunk for group builder to perform domain-decomposition by the grouping keys.
Source code in src/maggma/builders/group_builder.py
94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
unary_function(items)
abstractmethod
¶
Processing function for GroupBuilder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items |
list[dict]
|
list of of documents with matching grouping keys |
required |
Returns:
Type | Description |
---|---|
dict
|
Dictionary mapping: tuple of source document keys that are in the grouped document to the grouped and processed document |
Source code in src/maggma/builders/group_builder.py
170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
update_targets(items)
¶
Generic update targets for Group Builder.
Source code in src/maggma/builders/group_builder.py
158 159 160 161 162 163 164 165 166 167 168 |
|