Azure Data Factory数组参数拼接查询报错求助
Azure Data Factory多表增量复制参数化查询解决方案
问题场景
当管道参数从单表字符串改为数组["table1","table2"]后,出现两类错误:
- 直接用
concat拼接数组时:concat does not have an overload that supports the arguments given:(StringLiteral,Array.........) - 用
string()转换数组后拼接,出现类型转换错误:ErrorCode=UserErrorInvalidValueInPayload,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=Failed to convert the value in 'table' property to 'System.String' type. Please make sure the payload structure and value are correct.,Source=Microsoft.DataTransfer.DataContracts,''Type=System.InvalidCastException,Message=Object must implement IConvertible.,Source=mscorlib,'
原因分析
concat函数仅支持字符串类型参数,无法直接拼接数组string()转换数组会生成带方括号的字符串(如["table1","table2"]),无法作为合法表名传入查询,同时触发ADF类型校验错误
解决方案:用ForEach遍历数组处理单表逻辑
- 保持管道参数
p_param_input_table为数组类型,传入多表名数组 - 添加ForEach活动,将
Items设置为@pipeline().parameters.p_param_input_table(如需顺序执行可勾选Sequential) - 在ForEach内部实现单表增量复制逻辑(包含Lookup水印表、复制活动),复制活动的源查询修改为:
用@concat('select * from DW_GL.',item(),' where updated_on > ''',activity('Old_Lookup1').output.firstRow.date_value,''' and updated_on <= ''',activity('Old_Lookup1').output.firstRow.date_value_new,'''')item()获取当前循环的表名字符串,直接参与拼接,无需额外类型转换
说明
ForEach活动会遍历数组中的每个表名,对每个表单独执行增量复制逻辑,既适配数组参数输入,又保证每个查询的表名合法有效。
内容的提问来源于stack exchange,提问作者TA01
相关产品推荐
相关产品推荐

