我想创建一个数组类型的变量在管道中使用,但不知道如何做到这一点。我想把这个月到12月存储在一个数组类型的变量中。例如,我想在本月要执行的管道中创建以下变量;
["07","08","09","10","11","12"]
字符串还有,下个月是这样的;
["08","09","10","11","12"]
型有没有办法使用Synapse的管道函数来创建这个变量?任何答案都会有所帮助。- 谢谢你-谢谢
r8xiu3jd1#
您可以在其中使用for-each activity和append variable activity来创建一个数组变量,其中包含Synapse管道中从当前月份到12月的值。
for-each activity
append variable activity
x1c 0d1x的数据1.起始值:此变量存储当前月份。1.TotalIterationValue:此变量存储一年中剩余的月数。1.Array_variable:此变量是一个数组,用于存储从当前月份到12月的月份。
1.设置变量-起始值:的此活动将StartValue变量的值设置为当前月份。它使用子字符串函数从UTC时间中提取月份,并将其设置为变量的值。表达式:@substring(utcnow(),5,2)的值。1.设置变量- TotalIterationValue:
StartValue
@substring(utcnow(),5,2)
此活动将TotalIterationValue变量的值设置为一年中剩余的月数。它使用sub函数从13(一年中的总月数)中减去当前月份,并将其设置为变量的值。表达式:@string(sub(13,int(variables('StartValue'))))个
@string(sub(13,int(variables('StartValue'))))
的项目中的表达式:@range(0, int(variables('TotalIterationValue')))个x1c4d 1x的Array_variable的表达式:@add(int(variables('StartValue')),item())个此活动循环遍历从0到TotalIterationValue值的数字范围,并将相应的月份追加到Array_variable变量。它使用add函数将当前迭代次数添加到StartValue变量中,并将其设置为Array_variable变量的值。
@range(0, int(variables('TotalIterationValue')))
Array_variable
@add(int(variables('StartValue')),item())
TotalIterationValue
{ "name": "PipelineX", "properties": { "activities": [ { "name": "Set variable- Start Value", "type": "SetVariable", "dependsOn": [], "policy": { "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "variableName": "StartValue", "value": { "value": "@substring(utcnow(),5,2)", "type": "Expression" } } }, { "name": "Set variable - TotalIterationValue", "type": "SetVariable", "dependsOn": [ { "activity": "Set variable- Start Value", "dependencyConditions": [ "Succeeded" ] } ], "policy": { "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "variableName": "TotalIterationValue", "value": { "value": "@string(sub(13,int(variables('StartValue'))))", "type": "Expression" } } }, { "name": "ForEach1", "type": "ForEach", "dependsOn": [ { "activity": "Set variable - TotalIterationValue", "dependencyConditions": [ "Succeeded" ] } ], "userProperties": [], "typeProperties": { "items": { "value": "@range(0, int(variables('TotalIterationValue')))", "type": "Expression" }, "isSequential": true, "activities": [ { "name": "Append variable1", "type": "AppendVariable", "dependsOn": [], "userProperties": [], "typeProperties": { "variableName": "Array_variable", "value": { "value": "@add(int(variables('StartValue')),item())", "type": "Expression" } } } ] } } ], "variables": { "StartValue": { "type": "String" }, "TotalIterationValue": { "type": "String" }, "Array_variable": { "type": "Array" } }, "annotations": [] } }
字符串Array_variable将具有从当前月份到12月的值。
csbfibhn2#
除了Aswin的方法之外,作为替代方案,您也可以尝试以下方法:
{ "name": "pipeline38", "properties": { "activities": [ { "name": "FindCurrentMonth", "type": "SetVariable", "dependsOn": [], "policy": { "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "variableName": "FindCurrentMonth", "value": { "value": "@substring(formatDateTime(utcnow(),'yyyy-MM-dd'),5,2)", "type": "Expression" } } }, { "name": "Until1", "type": "Until", "dependsOn": [ { "activity": "FindCurrentMonth", "dependencyConditions": [ "Succeeded" ] } ], "userProperties": [], "typeProperties": { "expression": { "value": "@equals(variables('TempVar'),'12')", "type": "Expression" }, "activities": [ { "name": "Append variable1", "type": "AppendVariable", "dependsOn": [ { "activity": "TempVar", "dependencyConditions": [ "Succeeded" ] } ], "userProperties": [], "typeProperties": { "variableName": "appendvariable", "value": { "value": "@variables('TempVar')", "type": "Expression" } } }, { "name": "TempVar", "type": "SetVariable", "dependsOn": [], "policy": { "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "variableName": "TempVar", "value": { "value": "@variables('FindCurrentMonth')", "type": "Expression" } } }, { "name": "Update month value", "type": "SetVariable", "dependsOn": [ { "activity": "Append variable1", "dependencyConditions": [ "Succeeded" ] } ], "policy": { "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "variableName": "FindCurrentMonth", "value": { "value": "@{add(int(variables('TempVar')),1)}", "type": "Expression" } } } ], "timeout": "0.12:00:00" } }, { "name": "Final Output", "type": "SetVariable", "dependsOn": [ { "activity": "Until1", "dependencyConditions": [ "Succeeded" ] } ], "policy": { "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "variableName": "finaloutput", "value": { "value": "@variables('appendvariable')", "type": "Expression" } } } ], "variables": { "FindCurrentMonth": { "type": "String" }, "month": { "type": "String" }, "appendvariable": { "type": "Array" }, "TempVar": { "type": "String" }, "finaloutput": { "type": "Array" } }, "annotations": [] } }
字符串创建以下字符串变量:FindCurrentMonthmonthTempVar创建以下Array变量:appendvariablefinaloutput
FindCurrentMonth
month
TempVar
appendvariable
finaloutput
@substring(formatDateTime(utcnow(),'yyyy-MM-dd'),5,2)
@equals(variables('TempVar'),'12')
@variables('FindCurrentMonth')
@variables('TempVar')
@{add(int(variables('TempVar')),1)}
@variables('appendvariable')
的数据
up9lanfz3#
我们可以在until循环中使用set变量和append变量。
的数据不需要设置变量4。我创建它只是为了打印值,因为在调试模式下无法看到附加值,您可以忽略month2变量并设置变量4活动。
的
{ "name": "Pipeline 1", "properties": { "activities": [ { "name": "Set variable1", "type": "SetVariable", "dependsOn": [], "policy": { "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "variableName": "start", "value": { "value": "@substring(formatDateTime(utcNow(),'yyyy-MM-dd'),5,2)", "type": "Expression" } } }, { "name": "Until1", "type": "Until", "dependsOn": [ { "activity": "Set variable1", "dependencyConditions": [ "Succeeded" ] } ], "userProperties": [], "typeProperties": { "expression": { "value": "@equals(variables('start'),'13')", "type": "Expression" }, "activities": [ { "name": "Append variable1", "type": "AppendVariable", "dependsOn": [], "userProperties": [], "typeProperties": { "variableName": "months", "value": { "value": "@variables('start')", "type": "Expression" } } }, { "name": "Set variable2", "type": "SetVariable", "dependsOn": [ { "activity": "Append variable1", "dependencyConditions": [ "Succeeded" ] } ], "policy": { "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "variableName": "start2", "value": { "value": "@string(add(int(variables('start')),1))", "type": "Expression" } } }, { "name": "Set variable3", "type": "SetVariable", "dependsOn": [ { "activity": "Set variable2", "dependencyConditions": [ "Succeeded" ] } ], "policy": { "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "variableName": "start", "value": { "value": "@variables('start2')", "type": "Expression" } } }, { "name": "Set variable4", "type": "SetVariable", "dependsOn": [ { "activity": "Append variable1", "dependencyConditions": [ "Succeeded" ] } ], "policy": { "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "variableName": "months2", "value": { "value": "@variables('months')", "type": "Expression" } } } ], "timeout": "0.12:00:00" } } ], "variables": { "start": { "type": "String" }, "months": { "type": "Array" }, "start2": { "type": "String" }, "months2": { "type": "Array" } }, "annotations": [] }
字符串}
3条答案
按热度按时间r8xiu3jd1#
您可以在其中使用
for-each activity
和append variable activity
来创建一个数组变量,其中包含Synapse管道中从当前月份到12月的值。x1c 0d1x的数据
1.起始值:此变量存储当前月份。
1.TotalIterationValue:此变量存储一年中剩余的月数。
1.Array_variable:此变量是一个数组,用于存储从当前月份到12月的月份。
1.设置变量-起始值:
的
此活动将
StartValue
变量的值设置为当前月份。它使用子字符串函数从UTC时间中提取月份,并将其设置为变量的值。表达式:@substring(utcnow(),5,2)
的值。1.设置变量- TotalIterationValue:
此活动将TotalIterationValue变量的值设置为一年中剩余的月数。它使用sub函数从13(一年中的总月数)中减去当前月份,并将其设置为变量的值。表达式:
@string(sub(13,int(variables('StartValue'))))
个的
项目中的表达式:
@range(0, int(variables('TotalIterationValue')))
个x1c4d 1x的
Array_variable
的表达式:@add(int(variables('StartValue')),item())
个此活动循环遍历从0到
TotalIterationValue
值的数字范围,并将相应的月份追加到Array_variable变量。它使用add函数将当前迭代次数添加到StartValue变量中,并将其设置为Array_variable变量的值。字符串
Array_variable
将具有从当前月份到12月的值。csbfibhn2#
除了Aswin的方法之外,作为替代方案,您也可以尝试以下方法:
字符串
创建以下字符串变量:
FindCurrentMonth
month
TempVar
创建以下Array变量:appendvariable
finaloutput
@substring(formatDateTime(utcnow(),'yyyy-MM-dd'),5,2)
个@equals(variables('TempVar'),'12')
个@variables('FindCurrentMonth')
个@variables('TempVar')
@{add(int(variables('TempVar')),1)}
@variables('appendvariable')
个的数据
up9lanfz3#
我们可以在until循环中使用set变量和append变量。
的数据
不需要设置变量4。我创建它只是为了打印值,因为在调试模式下无法看到附加值,您可以忽略month2变量并设置变量4活动。
的
字符串
}