I've got a question about how to implement parent-...
# singer-tap-development
m
I've got a question about how to implement parent-child streams where the child streams only should run on specific records. In my example I'm syncing a parent "objects" stream (all the object records have the same schema) but there is a "object_type" and I need each child stream to only process the parent records that match a specific object type while ignoring all others. So say there are child streams "foo_object" and "bar_object", and each need the primary key of the parent "object" stream but foo_object only should process parent records where "object_type" = "foo" and ignore all other parent records (otherwise the endpoint will error if a bar_object is requested), and bar_object similarly only processes parent records where "object_type" = "bar". What's the best way for the child streams to only run on the matching the parent records and ignore the rest?
👀 2
r
There might be a better way, but we do this in a
get_records
override having passed the record property we want to filter on in context: https://github.com/Matatika/tap-iterable-msdk/blob/43bce0c92e7e2af96c664283634c7978529a31a6/tap_iterable/streams.py#L168-L173 You would need to pass
object_type
as context to the child stream, i.e. in your parent stream class:
Copy code
def get_child_context(self, record, context):
        return {"object_type": record["object_type"]}
e
If generate_child_contexts yields
None
, then the child sync for that parent record will be skipped, but I think @mark_estey's request is subtly more complex. IIUC, the parent stream has 2 child streams, each of which should only be synced for a specific type of record/context. Kind of like case 2 in https://github.com/meltano/sdk/discussions/2846, but conditional and for different child streams.
r
each of which should only be synced for a specific type of record/context
That is this, no?
m
Yeah I was thinking that I might have to just intercept the requests in
get_records
for each child and have it only pass through the ones that match like you did @Reuben (Matatika) but was curious if there was a better way. To me it could be useful if there was a way for each child to declare how they would like to receive context from the parent. This would also be useful in cases where multiple children need different pieces of context from the parent in addition to being able to control if a context record is generated from the parent or not on a per-child basis.
âž• 1