Objective
To split large input files into smaller files based on unique Order_ID values and generate individual output files for each order. These files will be uploaded to the target SFTP location.
Problem Statement
Currently, the system generates large files (400MB–600MB), each containing records for multiple Order_IDs. To enhance processing efficiency and manageability, we need to split these files into smaller, more granular files — one per unique Order_ID.
Example: If the input file contains records with 3 unique Order_IDs, the output should include 3 separate files — each corresponding to one Order_ID — on the target SFTP location.
Proposed Solution Using Adeptia: Step-by-Step Implementation
-
Define Source File and Layout:
- Configure the source activity to read the input file (e.g., FTP Source).
- Create a Schema/Layout based on the structure of the input file.
-
Extract Unique Order_ID Values:
- Create another text layout containing only the Order_ID field. This layout is used only for extracting distinct Order_IDs.
- Create another text layout containing only the Order_ID field. This layout is used only for extracting distinct Order_IDs.
-
Create Data Mapping for Unique Order_IDs:
- Source Layout: Use the layout created in step 1.b above.
- Target Layout: Use the layout created in step 2.a above.
-
Mapping Rules:
- Apply a for-each at the record level.
- Use the following predicate to filter unique values:
[not (preceding :: ORDER_ID=ORDER_ID)]
-
Add a Data Splitter and Setup Gateway:
- Use a Data Splitter to iterate through each unique Order_ID and split the records accordingly.
- Configure a Gateway Condition to control the flow for each Order_ID.
- Refer to this documentation for plugin configuration: https://support.adeptia.com/hc/en-us/articles/207875483-Data-Splitter-Custom-Plugin
-
Store Order ID in Context Schema:
- Create a Data Mapping to store each unique Order_ID into a Context Variable using a ContextSchema.
- Source Layout: Use the layout from step 2.a above.
- Target Layout: Use a Context Schema with a variable named Order_ID.
-
Mapping Rules:
- Map Order_ID → Order_ID in context.
- Create a Data Mapping to store each unique Order_ID into a Context Variable using a ContextSchema.
-
Transform Data per Order ID:
- Create a new Data Mapping to transform the filtered records to JSON format:
- Source Layout: Use the main input layout, created in step 1.b above.
- Target Layout: Use a JSON layout.
-
Mapping Rules:
- At the root level of the target layout, create a Local Variable to fetch the current Order_ID from context:
- Variable Name: varGetOrderID
- Variable Value: get-context (‘Order_ID ’,’’)
- At the root level of the target layout, create a Local Variable to fetch the current Order_ID from context:
- Create a new Data Mapping to transform the filtered records to JSON format:
-
-
-
-
Apply for-each rule and use the following mapping condition:
- Apply for-each at the Record level of the JSON layout i.e. ‘item’ here
- Define the given condition as a predicate to fetch the distinct Order Ids: $Input_Source_Layout/Root/Record[ORDER_ID=$varGetOrderID]
-
Apply for-each rule and use the following mapping condition:
-
-
-
Write Output Files to Target Location:
- Attach the target JSON layout.
- Configure the required target location (e.g., FTP Target).
- Save the Process Flow and execute it
-
Expected Output:
- Each iteration produces one JSON file containing records for a single Order_ID.
- The files are uploaded to the specified target location.
-
Benefits of This Approach:
- Efficient handling of large files.
- Improved system performance.
- Simplified downstream processing.
- Modular and maintainable data output with one file per Order_ID.
Please find the attached ZIP file containing the sample process flow for the reference.
Comments
0 comments
Please sign in to leave a comment.