0
votes

I have created a pipeline in ADF V2 that is copying data from an Odata connector source to a Azure SQL DB sink, the dataset source and sink are dynamic so it iterates through the multiple entities (tables) from the Odata source and copies them over to the corresponding tables in SQL. I've tested the copy activity independently and that works when iterating through the dynamic datasets but when I incorporate an until activity as a parent to the copy activity which is to used to iterate through multiple pages of data per entity(table) from the Odata source it gives me this error; "code":"BadRequest","message":null,"target":"pipeline//runid/XXXX","details":null,"error":null}

The only advice I can find from from similar threads on here is that there is an issue in the underlying JSON payload with a special character like a { or space corrupting the code and specific examples have been related to when the linked service has been made dynamic but I can not see any such issues in my case, I've pasted the code below;

Note: My linked service is not parameterised, just the datasets and I am able to preview the data within the datasets.

{
"name": "pl_AllEntities",
"properties": {
    "activities": [
        {
            "name": "Lookup OdataMetadata",
            "type": "Lookup",
            "dependsOn": [],
            "policy": {
                "timeout": "7.00:00:00",
                "retry": 0,
                "retryIntervalInSeconds": 30,
                "secureOutput": false,
                "secureInput": false
            },
            "userProperties": [],
            "typeProperties": {
                "source": {
                    "type": "AzureSqlSource",
                    "sqlReaderQuery": {
                        "value": "SELECT OdataEntityName\nFROM [dbo].[Config_OdataEntitySync]",
                        "type": "Expression"
                    },
                    "queryTimeout": "02:00:00",
                    "isolationLevel": "ReadCommitted",
                    "partitionOption": "None"
                },
                "dataset": {
                    "referenceName": "ds_Config_OdataEntitySync",
                    "type": "DatasetReference"
                },
                "firstRowOnly": false
            }
        },
        {
            "name": "ForEach OdataEntity",
            "type": "ForEach",
            "dependsOn": [
                {
                    "activity": "Lookup OdataMetadata",
                    "dependencyConditions": [
                        "Succeeded"
                    ]
                }
            ],
            "userProperties": [],
            "typeProperties": {
                "items": {
                    "value": "@activity('Lookup OdataMetadata').output.value",
                    "type": "Expression"
                },
                "activities": [
                    {
                        "name": "Lookup LastRowChangedDatetime",
                        "type": "Lookup",
                        "dependsOn": [],
                        "policy": {
                            "timeout": "7.00:00:00",
                            "retry": 0,
                            "retryIntervalInSeconds": 30,
                            "secureOutput": false,
                            "secureInput": false
                        },
                        "userProperties": [],
                        "typeProperties": {
                            "source": {
                                "type": "AzureSqlSource",
                                "sqlReaderStoredProcedureName": "[dbo].[usp_Config_GetHighWaterMark]",
                                "storedProcedureParameters": {
                                    "inOdataEntityName": {
                                        "type": "String",
                                        "value": {
                                            "value": "@item().OdataEntityName",
                                            "type": "Expression"
                                        }
                                    }
                                },
                                "queryTimeout": "02:00:00",
                                "partitionOption": "None"
                            },
                            "dataset": {
                                "referenceName": "ds_GeenGBDBxxxxx",
                                "type": "DatasetReference"
                            }
                        }
                    },
                    {
                        "name": "Set LastRowChangeDatetime",
                        "type": "SetVariable",
                        "dependsOn": [
                            {
                                "activity": "Lookup LastRowChangedDatetime",
                                "dependencyConditions": [
                                    "Succeeded"
                                ]
                            }
                        ],
                        "userProperties": [],
                        "typeProperties": {
                            "variableName": "LastRowChangedDatetime",
                            "value": {
                                "value": "@string(activity('Lookup LastRowChangedDatetime').output.firstRow['LastRowChangedDatetime'])",
                                "type": "Expression"
                            }
                        }
                    },
                    {
                        "name": "Until AllRowsCopied",
                        "type": "Until",
                        "dependsOn": [
                            {
                                "activity": "Set LastRowChangeDatetime",
                                "dependencyConditions": [
                                    "Succeeded"
                                ]
                            }
                        ],
                        "userProperties": [],
                        "typeProperties": {
                            "expression": {
                                "value": "@equals(variables('RowRead'),true)",
                                "type": "Expression"
                            },
                            "activities": [
                                {
                                    "name": "Copy Data",
                                    "type": "Copy",
                                    "dependsOn": [],
                                    "policy": {
                                        "timeout": "7.00:00:00",
                                        "retry": 0,
                                        "retryIntervalInSeconds": 30,
                                        "secureOutput": false,
                                        "secureInput": false
                                    },
                                    "userProperties": [],
                                    "typeProperties": {
                                        "source": {
                                            "type": "ODataSource",
                                            "query": {
                                                "value": "@concat('$filter=RowChangedDatetime gt ',convertTimeZone(variables('LastRowChangedDatetime'),'UTC', 'UTC'),'&$top=',variables('RowCount'),'&$skip=',variables('RowCountAdder'))",
                                                "type": "Expression"
                                            },
                                            "httpRequestTimeout": "00:05:00"
                                        },
                                        "sink": {
                                            "type": "AzureSqlSink",
                                            "writeBehavior": "insert",
                                            "disableMetricsCollection": false
                                        },
                                        "enableStaging": false
                                    },
                                    "inputs": [
                                        {
                                            "referenceName": "ds_OData_DynamicSource",
                                            "type": "DatasetReference",
                                            "parameters": {
                                                "EntityName": {
                                                    "value": "@item().OdataEntityName",
                                                    "type": "Expression"
                                                }
                                            }
                                        }
                                    ],
                                    "outputs": [
                                        {
                                            "referenceName": "ds_GeenSQL_DynamicSink",
                                            "type": "DatasetReference",
                                            "parameters": {
                                                "SchemaName": "dbo",
                                                "TableNamePrefix": "Staging_",
                                                "TableEntityName": {
                                                    "value": "@item().OdataEntityName",
                                                    "type": "Expression"
                                                }
                                            }
                                        }
                                    ]
                                },
                                {
                                    "name": "Set RowCountAdderTemp",
                                    "type": "SetVariable",
                                    "dependsOn": [
                                        {
                                            "activity": "Copy Data",
                                            "dependencyConditions": [
                                                "Succeeded"
                                            ]
                                        }
                                    ],
                                    "userProperties": [],
                                    "typeProperties": {
                                        "variableName": "RowCountAdderTemp",
                                        "value": {
                                            "value": "@string(add(int(variables('RowCountAdder')),10000))",
                                            "type": "Expression"
                                        }
                                    }
                                },
                                {
                                    "name": "Set RowCountAdder",
                                    "type": "SetVariable",
                                    "dependsOn": [
                                        {
                                            "activity": "Set RowCountAdderTemp",
                                            "dependencyConditions": [
                                                "Succeeded"
                                            ]
                                        }
                                    ],
                                    "userProperties": [],
                                    "typeProperties": {
                                        "variableName": "RowCountAdder",
                                        "value": {
                                            "value": "@variables('RowCountAdderTemp')",
                                            "type": "Expression"
                                        }
                                    }
                                },
                                {
                                    "name": "If Condition1",
                                    "type": "IfCondition",
                                    "dependsOn": [
                                        {
                                            "activity": "Set RowCountAdder",
                                            "dependencyConditions": [
                                                "Succeeded"
                                            ]
                                        }
                                    ],
                                    "userProperties": [],
                                    "typeProperties": {
                                        "expression": {
                                            "value": "@equals(activity('Copy Data').output.rowsRead,0)",
                                            "type": "Expression"
                                        },
                                        "ifFalseActivities": [
                                            {
                                                "name": "Set variable1",
                                                "type": "SetVariable",
                                                "dependsOn": [],
                                                "userProperties": [],
                                                "typeProperties": {
                                                    "variableName": "RowRead",
                                                    "value": false
                                                }
                                            }
                                        ],
                                        "ifTrueActivities": [
                                            {
                                                "name": "Set variable2",
                                                "description": "",
                                                "type": "SetVariable",
                                                "dependsOn": [],
                                                "userProperties": [],
                                                "typeProperties": {
                                                    "variableName": "RowRead",
                                                    "value": true
                                                }
                                            }
                                        ]
                                    }
                                }
                            ],
                            "timeout": "7.00:00:00"
                        }
                    },
                    {
                        "name": "usp_Config_GetHighWaterMark",
                        "type": "SqlServerStoredProcedure",
                        "dependsOn": [
                            {
                                "activity": "Until AllRowsCopied",
                                "dependencyConditions": [
                                    "Succeeded"
                                ]
                            }
                        ],
                        "policy": {
                            "timeout": "7.00:00:00",
                            "retry": 0,
                            "retryIntervalInSeconds": 30,
                            "secureOutput": false,
                            "secureInput": false
                        },
                        "userProperties": [],
                        "typeProperties": {
                            "storedProcedureName": "[dbo].[usp_Config_GetHighWaterMark]",
                            "storedProcedureParameters": {
                                "inOdataEntityName": {
                                    "value": {
                                        "value": "@item().OdataEntityName",
                                        "type": "Expression"
                                    },
                                    "type": "String"
                                },
                                "inSyncEnabled": {
                                    "value": {
                                        "value": "@pipeline().parameters.inSyncEnabled",
                                        "type": "Expression"
                                    },
                                    "type": "Boolean"
                                }
                            }
                        },
                        "linkedServiceName": {
                            "referenceName": "ls_AzureSqldb",
                            "type": "LinkedServiceReference"
                        }
                    }
                ]
            }
        }
    ],
    "parameters": {
        "OdataEntityName": {
            "type": "string"
        },
        "inSyncEnabled": {
            "type": "bool",
            "defaultValue": true
        }
    },
    "variables": {
        "LastRowChangedDatetime": {
            "type": "String"
        },
        "RowCount": {
            "type": "String",
            "defaultValue": "10000"
        },
        "RowCountAdder": {
            "type": "String",
            "defaultValue": "0"
        },
        "RowCountTemp": {
            "type": "String"
        },
        "RowCountAdderTemp": {
            "type": "String"
        },
        "RowRead": {
            "type": "Boolean"
        }
    },
    "folder": {
        "name": "Odata"
    },
    "annotations": []
}

}

1

1 Answers

0
votes

Note: When fetching a data preview in debug mode, no data will be written to your sink. A snapshot of what the data looks like will be returned, but nothing will be written to your destination. To test writing data into your sink, run a pipeline debug from the pipeline canvas

Checkout the below listed possibilities:

1. If you had changed the destination table to be in another schema. Revisit and select "Auto-generate" to update the value with the correct schema.

Import Schema

From you JSON, I can see no mappings.

Example: from my repro

"mappings": [
                                        {
                                            "source": {
                                                "name": "ID",
                                                "type": "Int32"
                                            },
                                            "sink": {
                                                "name": "IS_sink",
                                                "type": "Int64"
                                            }
                                        },
                                        {
                                            "source": {
                                                "name": "Name",
                                                "type": "String"
                                            },
                                            "sink": {
                                                "name": "Name_sink",
                                                "type": "String"
                                            }
                                        }
                                    ]
                                    

2. In the Sink part, if the dataset filename is hard coded to that field replace it with @dataset parameter i.e. Change @{item().Table_Name} to @{dataset().table_name}

In your case, as below

From: Line 173: "value": "@item().OdataEntityName"

To: Line 173: "value": "@dataset().OdataEntityName"

3. This can also happen if a pipeline parameter has a dash ("-") in the name

4. Can be due to missing single quotation marks in a dataset parameter.

5. If Copy Data activity has generated automatically, User properties, try deleting these properties.

6. Re-check if all user properties are configured correctly and there are no additional ones created.

enter image description here

7. If you are copying data from Project Online, you can use the OData connector and an access token obtained from tools like Postman. But these access token expires in 1 hour by default, you need to get a new access token when it expires.