<@U04S8PLJWMT> When building a custom connector, I...
# ask-ai
j
@kapa.ai When building a custom connector, I want to include the value of the parent key from a parent stream in the output stream of the child. How can I do this?
k
To include the value of the parent key from a parent stream in the output of a child (sub)stream when building a custom connector in Airbyte, you should use the partitioning features provided by Airbyte's connector builder. ### Config-based Connectors When using the config-based approach, you define a
SubstreamPartitionRouter
in your child stream. In the
parent_stream_configs
, you specify: - The parent stream reference. - The
parent_key
(the field in the parent record you want to propagate). - The
partition_field
(the variable name you will use to reference the parent key in the child stream). Example:
Copy code
yaml partition_router:   type: SubstreamPartitionRouter   parent_stream_configs:     - stream: "#/repositories_stream"       parent_key: "id"       partition_field: "repository"
You can then reference the parent key in your child stream using the
stream_slice
or
stream_partition
variable, e.g.,
{{ stream_slice.repository }}
or
{{ stream_partition.repository }}
in the URL path, request parameters, or transformations. This will inject the parent key value into each child record as needed. For more details, see the [SubstreamPartitionRouter documentation](https://docs.airbyte.com/platform/1.6/connector-development/config-based/understanding-the-yaml-file/partition-router#substreampartitionrouter). ### Connector Builder UI If you are using the Connector Builder UI, configure the "Parent Stream" component: - Set the "Parent Key" to the field you want from the parent stream (e.g.,
id
). - Set the "Current Parent Key Value Identifier" (e.g.,
order
). - In your child stream, you can then use
{{ stream_partition.order }}
to reference the parent key value in the output, such as in the URL path or in transformations. Example: If your parent stream is "orders" and the key is
id
, set the identifier to
order
. In the child stream, you can use:
Copy code
/orders/{{ stream_partition.order }}/notes
This will ensure each child record is associated with the correct parent key value in the output stream. For more, see the [Parent Stream documentation](https://docs.airbyte.com/platform/1.6/connector-development/connector-builder-ui/partitioning#parent-stream). ### Known Limitation There is a known issue where using
{{ stream_partition["parent_id"] }}
inside a transformation may not always resolve to the correct value for each record; it works reliably in the URL path but may not in transformations. As a workaround, you can use
{{ stream_partition }}
to get the full partition object, but this returns the entire object, not just the value. This issue is tracked in [this GitHub issue](https://github.com/airbytehq/airbyte/issues/59117). --- Summary: Use the `partition_field`/identifier in your partition router and reference it via
{{ stream_partition.<identifier> }}
in your child stream's configuration to include the parent key value in the output. Be aware of the current limitations in transformations and check for updates if you encounter issues.
j
@kapa.ai In the Connector Builder UI, I am able to inject stream_partition.parent_id into the request and to retrieve statistics for each stream, but parent_id is not represented in the records and so it is not represented in the output of the stream, which leaves no method for identifying the parent_id for each child stream.
k
A message from kapa.ai
New message text here