求助:如何通过ADF将分页API的复杂JSON导入SQLDB?
ADF Data Flow Solution for Paginated API with Columns/Rows Structure
Step 1: Configure REST Source with Pagination
- Use a REST Dataset pointing to your API endpoint.
- In the source transformation's Pagination settings:
- Select the appropriate pagination type (e.g., "Page number" if the API uses a
pageparameter). - Set start page to 1, end page to 401, increment by 1. Adjust parameters if your API uses offset-based pagination (e.g., offset starts at 0, increment by 25 per page).
- Select the appropriate pagination type (e.g., "Page number" if the API uses a
- Ensure the source reads the full JSON structure, including the
columns(array of column names) androws(array of record arrays) fields.
Step 2: Flatten the Rows Array
- Add a Flatten transformation:
- Set Unroll root to the
rowsarray (this creates a separate row for each record in the rows array of every page). - Keep the
columnsarray as a retained column (it repeats for each flattened record).
- Set Unroll root to the
Step 3: Generate Unique Row IDs
- Add a Derived Column transformation to create a unique identifier for each original record:
This ensures we can group all key-value pairs belonging to the same record during pivoting.rowNumber() as rowId
Step 4: Map Values to Column Names
- Add another Derived Column to pair each record's values with their corresponding column names using the
zipfunction:
Replacezip(columns, <flattened_row_column>) as mappedColumns<flattened_row_column>with the name of the column containing the flattened record array (default name may berowor similar). This creates an array of objects withkey(column name) andvalue(record value).
Step 5: Flatten the Mapped Columns Array
- Add a second Flatten transformation:
- Set Unroll root to the
mappedColumnsarray. This splits each key-value pair into a separate row, retaining therowIdto track which original record it belongs to.
- Set Unroll root to the
Step 6: Pivot to Create Tabular Structure
- Add a Pivot transformation:
- Group by: Select
rowId(to group all key-value pairs from the same original record). - Pivot key: Select
mappedColumns.key(the column names from the API). - Pivot value: Select
mappedColumns.value(the corresponding record values). - Aggregation: Choose
First(since each record has exactly one value per column). - This converts the key-value pairs into a tabular format matching your target SQL table schema.
- Group by: Select
Step 7: Clean Up and Sink to SQL DB
- Add a Select transformation to remove unnecessary columns (e.g.,
rowId,columns,mappedColumns). - Add a Sink transformation connected to your SQL DB dataset:
- Enable Auto create table if the target table doesn't exist, or manually map columns if the table is pre-created.
- Set the write behavior (e.g.,
AppendorUpsert) based on your requirements.
Edge Case Handling
- If columns vary across pages, the pivot will include all unique column names from all pages. Ensure your SQL table can accommodate additional columns or add a filter to exclude unexpected columns.
- Validate that
length(columns) == length(<flattened_row_column>)for all rows using a Filter transformation to avoid mismatched key-value pairs.
内容的提问来源于stack exchange,提问作者Jeff
相关产品推荐
相关产品推荐

