我有一个简单的 Synapse 管道来查询 SQL 数据库。查询按预期工作,但是当我尝试添加“设置变量”活动来输出结果时,出现以下错误:
{ "code": "BadRequest",
"message": null,
"target": "pipeline//runid/<runID goes here>",
"details": null,
"error": null
}
我的突触管道只有两个活动:脚本和设置变量:
{
"name": "query_resource",
"properties": {
"activities": [
{
"name": "Test query",
"type": "Script",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"linkedServiceName": {
"referenceName": "***************",
"type": "LinkedServiceReference"
},
"typeProperties": {
"scripts": [
{
"type": "Query",
"text": {
"value": "@pipeline().parameters.query",
"type": "Expression"
}
}
],
"scriptBlockExecutionTimeout": "02:00:00"
}
},
{
"name": "Query Result",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Test query",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"variableName": "pipelineReturnValue",
"value": [
{
"key": "queryResult",
"value": {
"type": "Object",
"content": "@activity('Test query').output.resultSets"
}
}
],
"setSystemVariable": true
}
}
],
"parameters": {
"query": {
"type": "string",
"defaultValue": "SELECT * FROM OPENQUERY(*********, 'SELECT Some query that is successful')"
}
},
"annotations": [],
"lastPublishTime": "2024-10-25T22:05:38Z"
},
"type": "Microsoft.Synapse/workspaces/pipelines"
}
我希望管道成功运行并且查询结果存储在变量中。
当使用“设置变量类型”为
String
并将变量值设置为“@activity('Script1').output.resultSets
”时,我遇到了与您相同的错误:
这是正确的管道
JSON
,它使用创建为String
的变量对我有用:
{
"name": "Pipeline 1",
"properties": {
"activities": [
{
"name": "Script1",
"type": "Script",
"dependsOn": [],
"policy": {
"timeout": "12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"linkedServiceName": {
"referenceName": "AzureSqlDatabase1",
"type": "LinkedServiceReference"
},
"typeProperties": {
"scripts": [
{
"type": "Query",
"text": "SELECT TOP 1 FileName FROM filestatus\n"
}
],
"scriptBlockExecutionTimeout": "02:00:00"
}
},
{
"name": "Set variable1",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Script1",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"variableName": "QueryResult",
"value": {
"value": "@activity('Script1').output.resultSets[0].rows[0].FileName",
"type": "Expression"
}
}
}
],
"variables": {
"QueryResult": {
"type": "String"
}
},
"annotations": []
}
}
在上面的管道中,我使用了
String
的“设置变量”活动的值,如下所示:@activity('Script1').output.resultSets[0].rows[0].FileName
结果:
第二种方法:您可以将“设置变量类型”设置为
ARRAY
然后使用“设置变量”活动的值,如下所示:
@activity('Script1').output.resultSets
结果: