|
1 | 1 | ---
|
2 |
| -title: Mapping data flow Alter Row Transformation |
3 |
| -description: How to update database target using Azure Data Factory mapping data flow Alter Row Transformation |
| 2 | +title: Alter row transformation in mapping data flow |
| 3 | +description: How to update database target using the alter row transformation in mapping data flow |
4 | 4 | author: kromerm
|
5 | 5 | ms.author: makromer
|
| 6 | +ms.reviewer: daperlov |
6 | 7 | ms.service: data-factory
|
7 | 8 | ms.topic: conceptual
|
8 | 9 | ms.custom: seo-lt-2019
|
9 |
| -ms.date: 03/12/2019 |
| 10 | +ms.date: 01/08/2020 |
10 | 11 | ---
|
11 | 12 |
|
12 |
| -# Azure Data Factory Alter Row Transformation |
| 13 | +# Alter row transformation in mapping data flow |
13 | 14 |
|
14 | 15 | Use the Alter Row transformation to set insert, delete, update, and upsert policies on rows. You can add one-to-many conditions as expressions. These conditions should be specified in order of priority, as each row will be marked with the policy corresponding to the first-matching expression. Each of those conditions can result in a row (or rows) being inserted, updated, deleted, or upserted. Alter Row can produce both DDL & DML actions against your database.
|
15 | 16 |
|
16 |
| - |
17 |
| - |
18 | 17 | 
|
19 | 18 |
|
20 |
| -> [!NOTE] |
21 |
| -> Alter Row transformations will only operate on database or CosmosDB sinks in your data flow. The actions that you assign to rows (insert, update, delete, upsert) will not occur during debug sessions. You must add an Execute Data Flow task to a pipeline and use pipeline debug or triggers to enact the alter row policies on your database tables. |
| 19 | +Alter Row transformations will only operate on database or CosmosDB sinks in your data flow. The actions that you assign to rows (insert, update, delete, upsert) won't occur during debug sessions. Run an Execute Data Flow activity in a pipeline to enact the alter row policies on your database tables. |
22 | 20 |
|
23 |
| -## Indicate a default row policy |
| 21 | +## Specify a default row policy |
24 | 22 |
|
25 |
| -Create an Alter Row transformation and specify a row policy with a condition of `true()`. Each row that does not meet any of the previously defined expressions will be marked for the specified row policy. By default, each row that does not meet any conditional expression will be marked for `Insert`. |
| 23 | +Create an Alter Row transformation and specify a row policy with a condition of `true()`. Each row that doesn't match any of the previously defined expressions will be marked for the specified row policy. By default, each row that doesn't match any conditional expression will be marked for `Insert`. |
26 | 24 |
|
27 |
| - |
| 25 | + |
28 | 26 |
|
29 | 27 | > [!NOTE]
|
30 | 28 | > To mark all rows with one policy, you can create a condition for that policy and specify the condition as `true()`.
|
31 | 29 |
|
32 |
| -## View policies |
| 30 | +## View policies in data preview |
33 | 31 |
|
34 |
| -Turn on Data Flow Debug mode to view the results of your alter row policies in the Data Preview pane. Executing an alter row in Data Flow Debug mode will not produce DDL or DML actions against your target. In order to have those actions occur, execute the data flow inside an Execute Data Flow activity within a pipeline. |
| 32 | +Use [debug mode](concepts-data-flow-debug-mode.md) to view the results of your alter row policies in the data preview pane. A data preview of an alter row transformation won't produce DDL or DML actions against your target. |
35 | 33 |
|
36 | 34 | 
|
37 | 35 |
|
38 |
| -This will allow you to verify and view the state of each row based on your conditions. There are icon represents for each insert, update, delete, and upsert action that will occur in your data flow, indicating which action will take place when you execute the data flow inside a pipeline. |
| 36 | +Each alter row policy is represented by an icon that indicates whether an insert, update, upsert, or deleted action will occur. The top header shows how many rows are affected by each policy in the preview. |
39 | 37 |
|
40 |
| -## Sink settings |
| 38 | +## Allow alter row policies in sink |
41 | 39 |
|
42 |
| -You must have a database sink type for Alter Row to work. In the sink Settings, you should set each action corresponding to your Alter Row conditions to be allowed. |
| 40 | +For the alter row policies to work, the data stream must write to a database or Cosmos sink. In the **Settings** tab in your sink, enable which alter row policies are allowed for that sink. |
43 | 41 |
|
44 | 42 | 
|
45 | 43 |
|
46 |
| -The default behavior in ADF Data Flow with database sinks is to insert rows. If you want to allow updates, upserts, and deletes as well, you must also check these boxes in the sink to allow the actions. |
| 44 | + The default behavior is to only allow inserts. To allow updates, upserts, or deletes, check the box in the sink corresponding to that condition. If updates, upserts, or, deletes are enabled, you must specify which key columns in the sink to match on. |
47 | 45 |
|
48 | 46 | > [!NOTE]
|
49 |
| -> If your inserts, updates, or upserts modify the schema of the target table in the sink, your data flow will fail. In order to modify the target schema in your database, you must choose the "Recreate table" option in the sink. This will drop and recreate your table with the new schema definition. |
| 47 | +> If your inserts, updates, or upserts modify the schema of the target table in the sink, the data flow will fail. To modify the target schema in your database, choose **Recreate table** as the table action. This will drop and recreate your table with the new schema definition. |
| 48 | +
|
| 49 | +## Data flow script |
| 50 | + |
| 51 | +### Syntax |
| 52 | + |
| 53 | +``` |
| 54 | +<incomingStream> |
| 55 | + alterRow( |
| 56 | + insertIf(<condition>?), |
| 57 | + updateIf(<condition>?), |
| 58 | + deleteIf(<condition>?), |
| 59 | + upsertIf(<condition>?), |
| 60 | + ) ~> <alterRowTransformationName> |
| 61 | +``` |
| 62 | + |
| 63 | +### Example |
| 64 | + |
| 65 | +The below example is an alter row transformation named `CleanData` that takes an incoming stream `SpecifyUpsertConditions` and creates three alter row conditions. In the previous transformation, a column named `alterRowCondition` is calculated that determines whether or not a row is inserted, updated, or deleted in the database. If the value of the column has a string value that matches the alter row rule, it is assigned that policy. |
| 66 | + |
| 67 | +In the Data Factory UX, this transformation looks like the below image: |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +The data flow script for this transformation is in the snippet below: |
| 72 | + |
| 73 | +``` |
| 74 | +SpecifyUpsertConditions alterRow(insertIf(alterRowCondition == 'insert'), |
| 75 | + updateIf(alterRowCondition == 'update'), |
| 76 | + deleteIf(alterRowCondition == 'delete')) ~> AlterRow |
| 77 | +``` |
50 | 78 |
|
51 | 79 | ## Next steps
|
52 | 80 |
|
|
0 commit comments