<@U04S8PLJWMT> Is it only possible to AddFields to...
# ask-ai
l
@kapa.ai Is it only possible to AddFields to a stream based on the output of stream? Is it possible to AddFields from the parent stream at all?
k
You can add fields to a stream using the AddFields transformation, and the value can be derived from various sources, including the current record, stream slices, or partition values. Specifically, when using parent streams (i.e., partitioning), you can add fields to the child stream's records based on values from the parent stream. This is typically done by referencing the partition value (which comes from the parent stream) using the interpolation syntax, such as
{{ stream_partition.<identifier> }}
. For example, you can add a field to each record in the child stream with the value of the parent key:
Copy code
yaml transformations:   - type: AddFields     fields:       - path: [ "parent_id" ]         value: "{{ stream_partition.parent_id }}"
Additionally, for more advanced use cases, you can include extra fields from the parent record in the stream slice using the
extra_fields
property in the
ParentStreamConfig
. These extra fields can then be accessed in the child stream via
{{ stream_slice.extra_fields.<field_name> }}
and added to records using AddFields transformations. This allows you to enrich child records with arbitrary data from the parent stream, not just the partition key itself [Advanced Configuration](https://docs.airbyte.com/platform/next/connector-development/connector-builder-ui/partitioning#advanced-configuration) [ParentStreamConfig Reference](https://docs.airbyte.com/platform/next/connector-development/config-based/understanding-the-yaml-file/reference#/definitions/ParentStreamConfig). So, yes, it is possible to AddFields to a stream based on values from the parent stream, not just the output of the current stream.
l
@kapa.ai Ok, do you see anything wrong with my code to add a composite_key (which comes from the parent_stream) transformations: - type: AddFields fields: - path: ["composite_key"] value: "{{ stream_partition.composite_key }}"
k
A message from kapa.ai
Your code for adding a composite_key from the parent stream using:
Copy code
yaml transformations:   - type: AddFields     fields:       - path: ["composite_key"]         value: "{{ stream_partition.composite_key }}"
is correct according to the documented approach for adding partition (parent) values to child stream records. The documentation shows that you should use the
{{ stream_partition.<identifier> }}
syntax to reference values from the parent stream when adding fields via transformations [Adding the partition value to the record](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/partitioning#adding-the-partition-value-to-the-record). However, be aware of a known issue: in some Airbyte versions (e.g., 1.5.1 and 1.6.1), there have been bugs where
{{ stream_partition["parent_id"] }}
did not always resolve correctly inside transformations, sometimes returning the same value for all records or being offset from the correct value. This is described in a [GitHub issue](https://github.com/airbytehq/airbyte/issues/59117). If you encounter unexpected results, it may be due to this bug rather than a problem with your code. Summary: Your code is correct per the documentation, but if you see incorrect values, it may be due to a known Airbyte bug in certain versions, not an error in your configuration.