映射数据流中的有条件拆分转换Conditional split transformation in mapping data flow

适用于: Azure 数据工厂 Azure Synapse Analytics

有条件拆分转换根据匹配条件将数据行路由到不同的流。The conditional split transformation routes data rows to different streams based on matching conditions. 有条件拆分转换类似于编程语言中的 CASE 决策结构。The conditional split transformation is similar to a CASE decision structure in a programming language. 转换计算表达式,并根据结果将数据行定向到指定的流。The transformation evaluates expressions, and based on the results, directs the data row to the specified stream.

配置Configuration

“拆分依据”设置可确定数据行是流向第一个匹配流还是其匹配的每个流。The Split on setting determines whether the row of data flows to the first matching stream or every stream it matches to.

使用数据流表达式生成器为拆分条件输入表达式。Use the data flow expression builder to enter an expression for the split condition. 若要添加新条件,请单击现有行中的加号图标。To add a new condition, click on the plus icon in an existing row. 还可以为与任何条件都不匹配的行添加默认流。A default stream can be added as well for rows that don't match any condition.

有条件拆分conditional split

数据流脚本Data flow script

语法Syntax

<incomingStream>
    split(
        <conditionalExpression1>
        <conditionalExpression2>
        ...
        disjoint: {true | false}
    ) ~> <splitTx>@(stream1, stream2, ..., <defaultStream>)

示例Example

下面的示例是一个名为 SplitByYear 的有条件拆分转换,它采用传入流 CleanDataThe below example is a conditional split transformation named SplitByYear that takes in incoming stream CleanData. 此转换有两个拆分条件,即 year < 1960year > 1980This transformation has two split conditions year < 1960 and year > 1980. disjoint 为 false,因为数据转到了第一个匹配条件。disjoint is false because the data goes to the first matching condition. 每个匹配第一个条件的行都会转到输出流 moviesBefore1960Every row matching the first condition goes to output stream moviesBefore1960. 与第二个条件匹配的所有剩余行都会转到输出流 moviesAFter1980All remaining rows matching the second condition go to output stream moviesAFter1980. 所有其他行都转到默认流 AllOtherMoviesAll other rows flow through the default stream AllOtherMovies.

在数据工厂 UX 中,此转换如下图所示:In the Data Factory UX, this transformation looks like the below image:

有条件拆分conditional split

此转换的数据流脚本位于下面的代码片段中:The data flow script for this transformation is in the snippet below:

CleanData
    split(
        year < 1960,
        year > 1980,
        disjoint: false
    ) ~> SplitByYear@(moviesBefore1960, moviesAfter1980, AllOtherMovies)

后续步骤Next steps

与条件拆分一起使用的常见数据流转换有联接转换查找转换选择转换Common data flow transformations used with conditional split are the join transformation, lookup transformation, and the select transformation