Azure Synapse Studio Orchestrate(ADF V2) Delta

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
USE [JSSUG_DEV] GO --Create Table CREATE TABLE [Employee] (EmpID INT NOT NULL, EmpName VARCHAR(50) NOT NULL, EmpDesignation VARCHAR(50) NULL, EmpDepartment VARCHAR(50) NULL, EmpJoining DATETIME NULL, RecordModifiedDate DATETIME NULL CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED(EmpID) ) GO CREATE TABLE [Item] (ItemID INT NOT NULL, ItemName VARCHAR(50) NULL, ItemCategory VARCHAR(50) NULL, ItemPrice numeric(18,2) NULL, RecordModifiedDate DATETIME NULL PRIMARY KEY CLUSTERED(ItemID ASC) ) ON [PRIMARY] GO CREATE TABLE Config (Table_Schema VARCHAR(200) NULL, Table_Name VARCHAR(200) NULL, DateMark DATETIME NULL ) ON [PRIMARY] GO --Insert Data INSERT INTO Employee(EmpID,EmpName,EmpDesignation,EmpDepartment,EmpJoining,RecordModifiedDate) VALUES (1,'Tanaka','Project Manager','PM',GETDATE(),GETDATE()), (2,'Sato','Senior Software Enginner','SSE',GETDATE(),GETDATE()), (3,'Nakamura','Software Enginner Manager','SEM',GETDATE(),GETDATE()), (4,'Arai','Software Enginner Manager','SEM',GETDATE(),GETDATE()), (5,'Matsubara','Senior Software Enginner','SSE',GETDATE(),GETDATE()) GO INSERT INTO Item (ItemID,ItemName,ItemCategory,ItemPrice,RecordModifiedDate) VALUES (1,'Microsoft SQL Server','Software',12.6,GETDATE()), (2,'Microsoft Azure','Cloud',17.26,GETDATE()), (3,'Xbox Series X','Game',9881.32,GETDATE()), (4,'Synapse Analytics','DW',324.9,GETDATE()) GO INSERT INTO Config (Table_Schema,Table_Name,DateMark) VALUES('dbo','Employee','1900-01-01'), ('dbo','Item','1900-01-01') GO SELECT * FROM Employee SELECT * FROM Item SELECT * FROM Config --Create Procedure CREATE PROCEDURE usp_UpdateDateMark @RecordModifiedDate DATETIME, @TableSchemaName VARCHAR(200), @TableName VARCHAR(200) AS BEGIN UPDATE Config SET DateMark = @RecordModifiedDate WHERE Table_Name = @TableName END --Azure Synapse Studio Orchestrate Parameter /* [ { "TABLE_NAME": "Employee", "DateMark_Column":"RecordModifiedDate" }, { "TABLE_NAME": "Item", "DateMark_Column":"RecordModifiedDate" } ] */ select max(RecordModifiedDate) AS [DateMark] from Employee select max(RecordModifiedDate) AS [DateMark] from Item select Table_Name,DateMark from Config where Table_Name = 'Item' select Table_Name,DateMark from Config where Table_Name = 'Employee' select * from Item --OldMarkDate where RecordModifiedDate > '1900-01-01' --MaxMarkDate and RecordModifiedDate <= '2020-07-25 17:27:01.660' /* { "orchestrate_name":"@{pipeline().DataFactory}", "pipeline_run_time":"@{convertTimeZone(pipeline().TriggerTime,'UTC','Tokyo Standard Time')}", "pipeline_name":"@{pipeline().Pipeline}", } https://support.microsoft.com/en-us/help/973627/microsoft-time-zone-index-values */ /* { "orchestrate_name":"", "pipeline_run_time":"", "pipeline_name":"", } */ --Run at SynaPool CREATE TABLE [Employee] (EmpID INT NOT NULL, EmpName VARCHAR(50) NOT NULL, EmpDesignation VARCHAR(50) NULL, EmpDepartment VARCHAR(50) NULL, EmpJoining DATETIME NULL, RecordModifiedDate DATETIME NULL ) WITH ( CLUSTERED COLUMNSTORE INDEX ) GO CREATE TABLE [Item] (ItemID INT NOT NULL, ItemName VARCHAR(50) NULL, ItemCategory VARCHAR(50) NULL, ItemPrice numeric(18,2) NULL, RecordModifiedDate DATETIME NULL ) WITH ( CLUSTERED COLUMNSTORE INDEX ) GO --Insert new recode INSERT INTO Employee(EmpID,EmpName,EmpDesignation,EmpDepartment,EmpJoining,RecordModifiedDate) VALUES (6,'Tanaka(new)','Project Manager','PM',GETDATE(),GETDATE()), (7,'Sato(new)','Senior Software Enginner','SSE',GETDATE(),GETDATE()), (8,'Nakamura(new)','Software Enginner Manager','SEM',GETDATE(),GETDATE()) GO INSERT INTO Item (ItemID,ItemName,ItemCategory,ItemPrice,RecordModifiedDate) VALUES (5,'Microsoft SQL Server(new)','Software',125.6,GETDATE()), (6,'Microsoft Azure(new)','Cloud',172.26,GETDATE()), (7,'Xbox Series X(new)','Game',988.32,GETDATE()), (8,'Synapse Analytics(new)','DW',34.9,GETDATE()) GO --初期化 DELETE Employee DELETE Item UPDATE Config set DateMark = '1900-01-01' |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
{ "name": "Demo20200725", "properties": { "activities": [ { "name": "ForEachSoureTable", "type": "ForEach", "dependsOn": [], "userProperties": [], "typeProperties": { "items": { "value": "@pipeline().parameters.arrayTableName", "type": "Expression" }, "activities": [ { "name": "LookupNewMarkDate", "type": "Lookup", "dependsOn": [], "policy": { "timeout": "7.00:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "source": { "type": "SqlServerSource", "sqlReaderQuery": { "value": "select max(@{item().DateMark_Column}) AS [DateMark]\nfrom @{item().TABLE_NAME}", "type": "Expression" }, "queryTimeout": "02:00:00" }, "dataset": { "referenceName": "SqlServerTable_Dataset", "type": "DatasetReference" } } }, { "name": "LookupOldMarkDate", "type": "Lookup", "dependsOn": [], "policy": { "timeout": "7.00:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "source": { "type": "SqlServerSource", "sqlReaderQuery": { "value": "select Table_Name,DateMark\nfrom Config\nwhere Table_Name = '@{item().TABLE_NAME}'", "type": "Expression" }, "queryTimeout": "02:00:00" }, "dataset": { "referenceName": "SqlServerTable_Dataset", "type": "DatasetReference" } } }, { "name": "getData", "type": "Copy", "dependsOn": [ { "activity": "LookupNewMarkDate", "dependencyConditions": [ "Succeeded" ] }, { "activity": "LookupOldMarkDate", "dependencyConditions": [ "Succeeded" ] } ], "policy": { "timeout": "7.00:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "source": { "type": "SqlServerSource", "sqlReaderQuery": { "value": "select *\nfrom @{item().TABLE_NAME}\n\n--OldMarkDate\nwhere @{item().DateMark_Column} > '@{activity('LookupOldMarkDate').output.firstRow.DateMark}'\n\n--MaxMarkDate\nand @{item().DateMark_Column} <= '@{activity('LookupNewMarkDate').output.firstRow.DateMark}'", "type": "Expression" }, "queryTimeout": "02:00:00" }, "sink": { "type": "DelimitedTextSink", "storeSettings": { "type": "AzureBlobStorageWriteSettings" }, "formatSettings": { "type": "DelimitedTextWriteSettings", "quoteAllText": true, "fileExtension": ".txt" } }, "enableStaging": false, "translator": { "type": "TabularTranslator", "typeConversion": true, "typeConversionSettings": { "allowDataTruncation": true, "treatBooleanAsNumber": false } } }, "inputs": [ { "referenceName": "SqlServerTable_Dataset", "type": "DatasetReference" } ], "outputs": [ { "referenceName": "DelimitedText_Dataset", "type": "DatasetReference", "parameters": { "FileName": { "value": "@concat(item().TABLE_NAME,'_',pipeline().RunId,'.csv')", "type": "Expression" } } } ] }, { "name": "usp_UpdateDateMark", "type": "SqlServerStoredProcedure", "dependsOn": [ { "activity": "getData", "dependencyConditions": [ "Succeeded" ] } ], "policy": { "timeout": "7.00:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "storedProcedureName": "[dbo].[usp_UpdateDateMark]", "storedProcedureParameters": { "RecordModifiedDate": { "value": { "value": "@activity('LookupNewMarkDate').output.firstRow.DateMark", "type": "Expression" }, "type": "DateTime" }, "TableName": { "value": { "value": "@activity('LookupOldMarkDate').output.firstRow.Table_Name", "type": "Expression" }, "type": "String" } } }, "linkedServiceName": { "referenceName": "SqlServer2019", "type": "LinkedServiceReference", "parameters": { "DBName": "JSSUG_DEV" } } }, { "name": "SendMail", "type": "WebActivity", "dependsOn": [ { "activity": "usp_UpdateDateMark", "dependencyConditions": [ "Succeeded" ] } ], "policy": { "timeout": "7.00:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "url": "https://prod-02.southeastasia.logic.azure.com:443/workflows/8461dce2c926470c980dd0b64fb71f90/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=fruEdONWTVO5hJgXmMvb_nrTXykLVaC5UNTzRIl6ASU", "connectVia": { "referenceName": "AutoResolveIntegrationRuntime", "type": "IntegrationRuntimeReference" }, "method": "POST", "body": { "value": "{\n\"orchestrate_name\":\"@{pipeline().DataFactory}\",\n\"pipeline_run_time\":\"@{convertTimeZone(getFutureTime(0,'Day'),'UTC','Tokyo Standard Time')}\",\n\"pipeline_name\":\"@{pipeline().Pipeline}\",\n}", "type": "Expression" } } } ] } } ], "parameters": { "arrayTableName": { "type": "array", "defaultValue": [ { "TABLE_NAME": "Employee", "DateMark_Column": "RecordModifiedDate" }, { "TABLE_NAME": "Item", "DateMark_Column": "RecordModifiedDate" } ] } }, "annotations": [] }, "type": "Microsoft.Synapse/workspaces/pipelines" } |