Azure 数据工厂中的 Filter 活动Filter activity in Azure Data Factory

可以在管道中使用 Filter 活动将筛选器表达式应用到输入数组。You can use a Filter activity in a pipeline to apply a filter expression to an input array.

适用于:是 Azure 数据工厂是 Azure Synapse Analytics(预览版)APPLIES TO: yesAzure Data Factory yesAzure Synapse Analytics (Preview)

语法Syntax

{
    "name": "MyFilterActivity",
    "type": "filter",
    "typeProperties": {
        "condition": "<condition>",
        "items": "<input array>"
    }
}

Type 属性Type properties

属性Property 说明Description 允许的值Allowed values 必须Required
namename Filter 活动的名称。Name of the Filter activity. StringString Yes
typetype 必须设置为 “filter”。Must be set to filter. StringString Yes
conditioncondition 要用于筛选输入的条件。Condition to be used for filtering the input. 表达式Expression Yes
itemsitems 应该应用筛选器的输入数组。Input array on which filter should be applied. 表达式Expression Yes

示例Example

在此示例中,管道包含两个活动:FilterForEachIn this example, the pipeline has two activities: Filter and ForEach. Filter 活动配置为筛选输入数组中值大于 3 的项。The Filter activity is configured to filter the input array for items with a value greater than 3. 然后,ForEach 活动会循环访问筛选的值,并将变量 test 设置为当前值。The ForEach activity then iterates over the filtered values and sets the variable test to the current value.

{
    "name": "PipelineName",
    "properties": {
        "activities": [{
                "name": "MyFilterActivity",
                "type": "filter",
                "typeProperties": {
                    "condition": "@greater(item(),3)",
                    "items": "@pipeline().parameters.inputs"
                }
            },
            {
            "name": "MyForEach",
            "type": "ForEach",
            "dependsOn": [
                {
                    "activity": "MyFilterActivity",
                    "dependencyConditions": [
                        "Succeeded"
                    ]
                }
            ],
            "userProperties": [],
            "typeProperties": {
                "items": {
                    "value": "@activity('MyFilterActivity').output.value",
                    "type": "Expression"
                },
                "isSequential": "false",
                "batchCount": 1,
                "activities": [
                    {
                        "name": "Set Variable1",
                        "type": "SetVariable",
                        "dependsOn": [],
                        "userProperties": [],
                        "typeProperties": {
                            "variableName": "test",
                            "value": {
                                "value": "@string(item())",
                                "type": "Expression"
                            }
                        }
                    }
                ]
            }
        }],
        "parameters": {
            "inputs": {
                "type": "Array",
                "defaultValue": [1, 2, 3, 4, 5, 6]
            }
        },
        "variables": {
            "test": {
                "type": "String"
            }
        },
        "annotations": []
    }
}

后续步骤Next steps

查看数据工厂支持的其他控制流活动:See other control flow activities supported by Data Factory: