Gabriel Segers
10/03/2025, 6:23 PMkapa.ai
10/03/2025, 6:24 PMpython import re from airbyte_cdk.sources.utils.transform import TransformConfig, Transformer from airbyte_cdk.sources.streams.core import Stream class MyStream(Stream): transformer = Transformer(TransformConfig.CustomSchemaNormalization) @transformer.registerCustomTransform def transform_year_month_to_date(original_value, field_schema): # Check if the field is a string and matches the "YYYY-MM" pattern if ( isinstance(original_value, str) and re.match(r"^\d{4}-\d{2}$", original_value) and field_schema.get("format") == "date" ): return f"{original_value}-01" return original_value - This function checks if the value is a string in the "YYYY-MM" format and the schema expects a "date" format. - If so, it appends "-01" to make it a full date string. You can adapt the field_schema check as needed for your use case. This approach is supported by Airbyte’s custom schema type transformation mechanism, which allows you to define such logic for your connector streams [see documentation](https://docs.airbyte.com/platform/next/connector-development/cdk-python/schemas#custom-schema-type-transformation). If you want to combine this with the default type transformation, you can use: python transformer = Transformer( TransformConfig.DefaultSchemaNormalization | TransformConfig.CustomSchemaNormalization ) so that both default and custom transformations are applied, with the custom one running after the default [see documentation](https://docs.airbyte.com/platform/next/connector-development/cdk-python/schemas#custom-schema-type-transformation). > Note: This solution is for connectors built with the Python CDK and requires you to define the transformation in your stream class.Gabriel Segers
10/03/2025, 6:24 PMkapa.ai
10/03/2025, 6:24 PMkapa.ai
10/03/2025, 6:25 PM"2025-05" to "2025-05-01" using a Jinja expression in Airbyte's connector builder, you can use Jinja's string concatenation directly in your interpolation: jinja {{ record['ano_mes'] ~ '-01' }} This expression takes the value of record['ano_mes'] and appends -01 to it, resulting in "2025-05-01". There is no built-in Jinja filter in Airbyte specifically for this transformation, but Jinja's ~ operator for string concatenation is supported in string interpolation contexts in the builder [see documentation](https://docs.airbyte.com/platform/1.7/connector-development/config-based/advanced-topics/string-interpolation). If you need to ensure the value matches the "YYYY-MM" format before appending, you could use a conditional expression, but for most use cases, the above is sufficient. Example usage in a YAML file: yaml date_field: "{{ record['ano_mes'] ~ '-01' }}" This will output "2025-05-01" when record['ano_mes'] is "2025-05".Gabriel Segers
10/03/2025, 6:25 PMkapa.ai
10/03/2025, 6:25 PMkapa.ai
10/03/2025, 6:26 PM"2025-05" into a date type (not just a string) in the Airbyte Connector Builder using Jinja, you can use the str_to_datetime macro provided by Airbyte. This macro converts a string to a datetime object with UTC timezone. You can first concatenate -01 to your string, then wrap it with `str_to_datetime`: jinja {{ str_to_datetime(record['ano_mes'] ~ '-01') }} This will produce a date object for "2025-05-01" instead of a plain string. The str_to_datetime macro is documented as converting a string to a datetime object with UTC timezone [see documentation](https://docs.airbyte.com/platform/1.7/connector-development/config-based/understanding-the-yaml-file/reference#str_to_datetime). Example: yaml date_field: "{{ str_to_datetime(record['ano_mes'] ~ '-01') }}" This approach ensures the field is treated as a date type in downstream processing, not just as a string.