Support For Derived Or Wrapper-Level Transforms In Sequin
Introduction
As a developer integrating Sequin with Tinybird, I have encountered a limitation that could be a meaningful opportunity for improvement. While Sequin provides a great transformation feature, there is currently no built-in way to apply flattening or restructuring transforms directly within Sequin for scenarios where the payload contains wrapper objects or deeply nested structures. In this article, we will explore the need for support for derived or wrapper-level transforms in Sequin and propose a feature enhancement to address this limitation.
The Current Limitation
Sequin's transformation feature is a powerful tool for data processing and manipulation. However, when dealing with payloads that contain wrapper objects or deeply nested structures, users are forced to set up external servers to unwrap or restructure the payload. This adds unnecessary complexity and duplication of logic across multiple services.
For example, consider a JSON payload with a nested structure:
{
"data": [
{
"record": {
"id": "1",
"name": "Alice"
}
},
{
"record": {
"id": "2",
"name": "Bob"
}
}
]
}
To ingest this properly into Tinybird or similar systems, we need to flatten data[*].record.*
to emit one row per item. Currently, this requires setting up an external server to unwrap or restructure the payload.
Feature Proposal: Wrapper-Level Transforms
To address the current limitation, I propose introducing wrapper-level transforms or supporting derived fields that can apply to items inside array objects. This would enable users to apply flattening or restructuring transforms directly within Sequin, without the need for external infrastructure.
Benefits of Wrapper-Level Transforms
The introduction of wrapper-level transforms would bring several benefits:
- Reduced complexity: Users integrating with streaming analytics platforms like Tinybird would no longer need to manage additional infrastructure to adjust the output payload format.
- End-to-end transformations: Sequin transformations would become truly end-to-end, even for batched or nested formats.
- Avoid unnecessary duplication of logic: Users would no longer need to duplicate logic across multiple services, reducing the complexity and maintenance burden.
Example Use Case
To illustrate the benefits of wrapper-level transforms, let's consider an example use case:
Suppose we have a JSON payload with a nested structure:
{
"data": [
{
"record": {
"id": "1",
"name": "Alice"
}
},
{
"record": {
"id": "2",
"name": "Bob"
}
}
]
}
With wrapper-level transforms, we could apply a transformation to flatten data[*].record.*
to emit one row per item, without the need for external infrastructure. The resulting transformed payload would look like this:
[
{
"id": "1",
"name": "Alice"
},
{
"id": "2",
"name": "Bob"
}
]
Conclusion
In conclusion, the introduction of wrapper-level transforms or support for derived fields that can apply to items inside array objects would be a significant enhancement to Sequin's transformation feature. This would enable users to apply flattening or restructuring transforms directly within Sequin, reducing complexity, making transformations truly end-to-end, and avoiding unnecessary duplication of logic across multiple services.
Additional Context
For additional context and a detailed explanation of the ingestion workflow, please refer to the video explanation provided: Video Explanation.
Acknowledgement
Introduction
In our previous article, we explored the need for support for derived or wrapper-level transforms in Sequin. We proposed a feature enhancement to introduce wrapper-level transforms or support derived fields that can apply to items inside array objects. In this article, we will answer some frequently asked questions (FAQs) related to this feature proposal.
Q: What are wrapper-level transforms, and how do they differ from existing transforms in Sequin?
A: Wrapper-level transforms are a new type of transform that can apply to items inside array objects. Unlike existing transforms in Sequin, which operate on individual fields or values, wrapper-level transforms can operate on entire objects or arrays. This allows for more complex and flexible data transformations.
Q: How would wrapper-level transforms be implemented in Sequin?
A: Wrapper-level transforms would be implemented as a new type of transform in Sequin, similar to existing transforms such as map
, filter
, and reduce
. They would be defined using a new syntax and would operate on entire objects or arrays, rather than individual fields or values.
Q: What are the benefits of wrapper-level transforms in Sequin?
A: The benefits of wrapper-level transforms in Sequin include:
- Reduced complexity: Users integrating with streaming analytics platforms like Tinybird would no longer need to manage additional infrastructure to adjust the output payload format.
- End-to-end transformations: Sequin transformations would become truly end-to-end, even for batched or nested formats.
- Avoid unnecessary duplication of logic: Users would no longer need to duplicate logic across multiple services, reducing the complexity and maintenance burden.
Q: How would wrapper-level transforms be used in practice?
A: Wrapper-level transforms would be used in practice to perform complex data transformations, such as:
- Flattening nested arrays: Transforming a nested array of objects into a flat array of objects.
- Unwrapping wrapper objects: Transforming a wrapper object into a flat object.
- Restructuring data: Transforming data from one format to another, such as from a JSON object to a CSV string.
Q: Are there any potential drawbacks or limitations to wrapper-level transforms in Sequin?
A: Yes, there are potential drawbacks or limitations to wrapper-level transforms in Sequin, including:
- Increased complexity: Wrapper-level transforms may introduce additional complexity to the Sequin API and user interface.
- Performance overhead: Wrapper-level transforms may incur a performance overhead due to the additional processing required.
- Security risks: Wrapper-level transforms may introduce security risks if not implemented correctly.
Q: How would wrapper-level transforms be tested and validated in Sequin?
A: Wrapper-level transforms would be tested and validated in Sequin using a combination of unit tests, integration tests, and end-to-end tests. This would ensure that the transforms work correctly and do not introduce any security risks or performance overhead.
Conclusion
In conclusion, wrapper-level transforms are a powerful new feature that would enable users to perform complex data transformations in Sequin. While there are potential drawbacks or limitations to this feature, the benefits of reduced complexity, end-to-end transformations, and avoided duplication of logic make it a valuable addition to the Sequin API.