Azure ForEach activity failing with: The function 'length' expects its parameter to be an array or a string. The provided value is of type 'Integer'

huangapple go评论63阅读模式
英文:

Azure ForEach activity failing with: The function 'length' expects its parameter to be an array or a string. The provided value is of type 'Integer'

问题

如何将我的值转换为整数?

以下是附加的上下文信息,如果有帮助的话:
我的流水线应该获取一个Blob CSV文件的列数,然后将该列数传递给ForEach活动。一个Switch活动嵌套在ForEach中,但是流水线在ForEach处出现错误,错误信息为:“函数'length'期望其参数是数组或字符串。提供的值的类型为'Integer'。”

元数据输出:

{
	"columnCount": 52,
	"effectiveIntegrationRuntime": "AutoResolveIntegrationRuntime (Central US)",
	"executionDuration": 1,
	"durationInQueue": {
		"integrationRuntimeQueue": 0
	},
	"billingReference": {
		"activityType": "PipelineActivity",
		"billableDuration": [
			{
				"meterType": "AzureIR",
				"duration": 0.016666666666666666,
				"unit": "Hours"
			}
		]
	}
}

ForEach输入:

{
"items": "@activity('Get Metadata1').output.columnCount",
"activities": [
{
"name": "Switch1",
"type": "Switch",
"dependsOn": [],
"userProperties": [],
"typeProperties": {
"on": "@item()",
"cases": [
{
"value": "44",
"activities": [
{
"name": "Copy data1_copy1",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "DelimitedTextSource",
"storeSettings": {
"type": "AzureBlobStorageReadSettings",
"recursive": false,
"enablePartitionDiscovery": false
},
"formatSettings": {
"type": "DelimitedTextReadSettings"
}
},
"sink": {
"type": "AzureSqlSink",
"writeBehavior": "insert",
"sqlWriterUseTableLock": false
},
"enableStaging": false,
"translator": {
"type": "TabularTranslator",
"typeConversion": true,
"typeConversionSettings": {
"allowDataTruncation": true,
"treatBooleanAsNumber": false
}
}
},
"inputs": [
{
"referenceName": "ten_eighty_split_CSV",
"type": "DatasetReference",
"parameters": {
"FileName": "@pipeline().parameters.SourceFile"
}
}
],
"outputs": [
{
"referenceName": "ten_eighty_split_10_15_SQL",
"type": "DatasetReference",
"parameters": {}
}
]
}
]
},
{
"value": "52",
"activities": [
{
"name": "Copy data2_copy1",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "DelimitedTextSource",
"storeSettings": {
"type": "AzureBlobStorageReadSettings",
"recursive": false,
"enablePartitionDiscovery": false
},
"formatSettings": {
"type": "DelimitedTextReadSettings"
}
},
"sink": {
"type": "AzureSqlSink",
"writeBehavior": "insert",
"sqlWriterUseTableLock": false
},
"enableStaging": false,
"translator": {
"type": "TabularTranslator",
"typeConversion": true,
"typeConversionSettings": {
"allowDataTruncation": true,
"treatBooleanAsNumber": false
}
}
},
"inputs": [
{
"referenceName": "ten_eighty_split_CSV",
"type": "DatasetReference",
"parameters": {
"FileName": "@pipeline().parameters.SourceFile"
}
}
],
"outputs": [
{
"referenceName": "ten_eighty_split_15_20_SQL",
"type": "DatasetReference",
"parameters": {}
}
]
}
]
},
{
"value": "60",
"activities": [
{
"name": "Copy data3_copy1",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "DelimitedTextSource",
"storeSettings": {
"type": "AzureBlobStorageReadSettings",
"recursive": false,
"enablePartitionDiscovery": false
},
"formatSettings": {
"type": "DelimitedTextReadSettings"
}
},
"sink": {
"type": "AzureSqlSink",
"writeBehavior": "insert",
"sqlWriterUseTableLock": false
},
"enableStaging": false,
"translator": {
"type": "TabularTranslator",
"typeConversion": true,
"typeConversionSettings": {
"allowDataTruncation": true,
"treatBooleanAsNumber": false
}
}
},
"inputs": [
{
"referenceName": "ten_eighty_split_CSV",
"type": "DatasetReference",
"parameters": {
"FileName": "@pipeline().parameters.SourceFile"
}
}
],
"outputs": [
{
"referenceName": "ten_eighty_split_25_30_SQL",
"type": "DatasetReference",
"parameters": {}
}
]
}
]
},
{
"value": "68",
"activities": [
{
"name": "Copy data4_copy1",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "DelimitedTextSource",
"storeSettings": {
"type": "
<details>
<summary>英文:</summary>
How do I convert my value to an integer?
Here&#39;s added context if helpful:
My pipeline should get the column count of a blob CSV and pass that count to a ForEach activity. A switch activity is embedded in ForEach, but the pipeline is failing at ForEach with this error: &#39;The function &#39;length&#39; expects its parameter to be an array or a string. The provided value is of type &#39;Integer&#39;.
Metadata output: 

{
"columnCount": 52,
"effectiveIntegrationRuntime": "AutoResolveIntegrationRuntime (Central US)",
"executionDuration": 1,
"durationInQueue": {
"integrationRuntimeQueue": 0
},
"billingReference": {
"activityType": "PipelineActivity",
"billableDuration": [
{
"meterType": "AzureIR",
"duration": 0.016666666666666666,
"unit": "Hours"
}
]
}
}

ForEach input:

{
"items": "@activity('Get Metadata1').output.columnCount",
"activities": [
{
"name": "Switch1",
"type": "Switch",
"dependsOn": [],
"userProperties": [],
"typeProperties": {
"on": "@item()",
"cases": [
{
"value": "44",
"activities": [
{
"name": "Copy data1_copy1",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "DelimitedTextSource",
"storeSettings": {
"type": "AzureBlobStorageReadSettings",
"recursive": false,
"enablePartitionDiscovery": false
},
"formatSettings": {
"type": "DelimitedTextReadSettings"
}
},
"sink": {
"type": "AzureSqlSink",
"writeBehavior": "insert",
"sqlWriterUseTableLock": false
},
"enableStaging": false,
"translator": {
"type": "TabularTranslator",
"typeConversion": true,
"typeConversionSettings": {
"allowDataTruncation": true,
"treatBooleanAsNumber": false
}
}
},
"inputs": [
{
"referenceName": "ten_eighty_split_CSV",
"type": "DatasetReference",
"parameters": {
"FileName": "@pipeline().parameters.SourceFile"
}
}
],
"outputs": [
{
"referenceName": "ten_eighty_split_10_15_SQL",
"type": "DatasetReference",
"parameters": {}
}
]
}
]
},
{
"value": "52",
"activities": [
{
"name": "Copy data2_copy1",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "DelimitedTextSource",
"storeSettings": {
"type": "AzureBlobStorageReadSettings",
"recursive": false,
"enablePartitionDiscovery": false
},
"formatSettings": {
"type": "DelimitedTextReadSettings"
}
},
"sink": {
"type": "AzureSqlSink",
"writeBehavior": "insert",
"sqlWriterUseTableLock": false
},
"enableStaging": false,
"translator": {
"type": "TabularTranslator",
"typeConversion": true,
"typeConversionSettings": {
"allowDataTruncation": true,
"treatBooleanAsNumber": false
}
}
},
"inputs": [
{
"referenceName": "ten_eighty_split_CSV",
"type": "DatasetReference",
"parameters": {
"FileName": "@pipeline().parameters.SourceFile"
}
}
],
"outputs": [
{
"referenceName": "ten_eighty_split_15_20_SQL",
"type": "DatasetReference",
"parameters": {}
}
]
}
]
},
{
"value": "60",
"activities": [
{
"name": "Copy data3_copy1",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "DelimitedTextSource",
"storeSettings": {
"type": "AzureBlobStorageReadSettings",
"recursive": false,
"enablePartitionDiscovery": false
},
"formatSettings": {
"type": "DelimitedTextReadSettings"
}
},
"sink": {
"type": "AzureSqlSink",
"writeBehavior": "insert",
"sqlWriterUseTableLock": false
},
"enableStaging": false,
"translator": {
"type": "TabularTranslator",
"typeConversion": true,
"typeConversionSettings": {
"allowDataTruncation": true,
"treatBooleanAsNumber": false
}
}
},
"inputs": [
{
"referenceName": "ten_eighty_split_CSV",
"type": "DatasetReference",
"parameters": {
"FileName": "@pipeline().parameters.SourceFile"
}
}
],
"outputs": [
{
"referenceName": "ten_eighty_split_25_30_SQL",
"type": "DatasetReference",
"parameters": {}
}
]
}
]
},
{
"value": "68",
"activities": [
{
"name": "Copy data4_copy1",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "DelimitedTextSource",
"storeSettings": {
"type": "AzureBlobStorageReadSettings",
"recursive": false,
"enablePartitionDiscovery": false
},
"formatSettings": {
"type": "DelimitedTextReadSettings"
}
},
"sink": {
"type": "AzureSqlSink",
"writeBehavior": "insert",
"sqlWriterUseTableLock": false
},
"enableStaging": false,
"translator": {
"type": "TabularTranslator",
"typeConversion": true,
"typeConversionSettings": {
"allowDataTruncation": true,
"treatBooleanAsNumber": false
}
}
},
"inputs": [
{
"referenceName": "ten_eighty_split_CSV",
"type": "DatasetReference",
"parameters": {
"FileName": "@pipeline().parameters.SourceFile"
}
}
],
"outputs": [
{
"referenceName": "ten_eighty_split_30_35_SQL",
"type": "DatasetReference",
"parameters": {}
}
]
}
]
}
]
}
}
]
}


ForEach output:
`{}`
Not sure how to satisfy this error. Thanks!
</details>
# 答案1
**得分**: 0
>Failure type: 用户配置问题
>详情: 函数 'length' 期望其参数是数组或字符串。提供的值是 'Integer' 类型。
由于您将整数值 (**columnCount**) 用作 for-each 活动的输入,因此出现此错误。如果您有值数组,并希望根据数组的每个值进行迭代活动,您可以使用 for-each 活动。在这种情况下,您可以在 **获取元数据活动** 之后直接使用 **切换活动**。在切换活动中,表达式在大括号内 `{...}` 中给出。
**表达式:**
`@{activity('获取元数据1').output.columnCount}` 
我在我的环境中尝试了这个操作,当我给出表达式 **不带大括号 {...}** 时,也出现了相同的错误。添加大括号后,它正常运行。以下是步骤。
- 获取元数据活动被执行,**列计数** 作为参数被提取。
**元数据活动的输出**:

{
"columnCount": 2,
"effectiveIntegrationRuntime": "AutoResolveIntegrationRuntime (West US)",
"executionDuration": 1,
"durationInQueue": {
"integrationRuntimeQueue": 0
},
"billingReference": {
"activityType": "PipelineActivity",
"billableDuration": [
{
"meterType": "AzureIR",
"duration": 0.016666666666666666,
"unit": "Hours"
}
]
}
}


- 然后,切换活动被执行,给出了表达式和情况。
表达式:  `@{activity('获取元数据1').output.columnCount}` 
![在此输入图片描述](https://i.stack.imgur.com/TbT2m.png)
- 当管道调试时,它被成功执行,没有错误发生。
<details>
<summary>英文:</summary>
&gt;Failure type: User configuration issue
&gt;Details: The function &#39;length&#39; expects its parameter to be an array or a string. The provided value is of type &#39;Integer&#39;.
Since you use an integer value (**columnCount**) as an input to for-each activity, you are getting this error. If you have array of values and you want to iterate the activity based on each value of array, you can use for-each activity. In this case, you can use the **switch case activity** directly after **get metadata activity**.  In Switch activity, expression is given within braces `{...}` .
**Expression:**
`@{activity(&#39;Get Metadata1&#39;).output.columnCount}` 
I tried this in my environment and got the same error when I give the expression **without braces {..}**. When {} are added, it worked. Below are the steps.
- **Get MetaData activity** is taken and **column count** is taken as an argument. 
**Output of MetaData activity**:

{
"columnCount": 2,
"effectiveIntegrationRuntime": "AutoResolveIntegrationRuntime (West US)",
"executionDuration": 1,
"durationInQueue": {
"integrationRuntimeQueue": 0
},
"billingReference": {
"activityType": "PipelineActivity",
"billableDuration": [
{
"meterType": "AzureIR",
"duration": 0.016666666666666666,
"unit": "Hours"
}
]
}
}


- Then Switch activity is taken and expression and case are given.
Expression:  `@{activity(&#39;Get Metadata1&#39;).output.columnCount}` 
![enter image description here](https://i.stack.imgur.com/TbT2m.png)
- When pipeline is debugged, it got executed successfully without error.
</details>

huangapple
  • 本文由 发表于 2023年2月16日 04:34:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465188.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定