篩選 Azure Data Factory 和 Synapse Analytics 管線中的活動

您可以在管線中使用篩選活動,將篩選運算式套用至輸入陣列。

適用於:Azure Data Factory Azure Synapse Analytics

提示

試用 Microsoft Fabric 中的 Data Factory,這是適用於企業的全方位分析解決方案。 Microsoft Fabric 涵蓋從資料移動到資料科學、即時分析、商業智慧和報告的所有項目。 了解如何免費啟動新的試用版

語法

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

使用 UI 建立 Filter 活動

若要在管線中使用 Filter (篩選) 活動,請完成下列步驟:

  1. 您可以使用任何陣列類型變數或來自其他活動的輸出作為篩選條件的輸入。 若要建立陣列變數,請選取管線畫布的背景,然後選取 [變數] 索引標籤,以新增陣列類型變數,如下所示。

    Shows an empty pipeline canvas with an array type variable added to the pipeline.

  2. 在管線 [活動] 窗格中搜尋 Filter,然後將 Filter 活動拖曳至管線畫布。

  3. 在畫布上選取新的 Filter 活動 (如未選取) 和其 [設定] 索引標籤以編輯詳細資料。

    Shows the UI for a Filter activity.

  4. 選取 [項目] 欄位,然後選取 [新增動態內容] 連結以開啟動態內容編輯器窗格。

    Shows the  Add dynamic content  link for the Items property.

  5. 選取您要在動態內容編輯器中篩選的輸入陣列。 在此範例中,我們會選取在第一個步驟中建立的變數。

    Shows the dynamic content editor with the variable created in the first step selected

  6. 再次使用動態內容編輯器來指定 Condition (條件) 屬性的篩選準則,如上所示。

  7. 您可以使用 Filter 活動的輸出作為 ForEach 活動等其他活動的輸入。

類型屬性

屬性 說明 允許的值 必要
NAME Filter 活動的名稱。 String Yes
type 必須設定為篩選 String Yes
條件 要用來篩選輸入的條件。 運算式 Yes
項目 應套用篩選條件的輸入陣列。 運算式 Yes

範例

在此範例中,管線有兩個活動:篩選ForEach。 篩選活動設定為會對值大於 3 之項目的輸入陣列進行篩選。 接著,ForEach 活動會逐一查看篩選值,然後將變數 test 設為目前值。

{
    "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": []
    }
}

查看其他支援的控制流程活動: