sql-server - Datafactory - dynamically copy subsection of columns from one database table to another
问题描述
I have a database on SQL Server on premises and need to regularly copy the data from 80 different tables to an Azure SQL Database. For each table the columns I need to select from and map are different - example, TableA - I need columns 1,2 and 5. For TableB I need just column 1. The tables are named the same in the source and target, but the column names are different.
I could create multiple Copy data pipelines and select the source and target data sets and map to the target table structures, but that seems like a lot of work for what is ultimately the same process repeated.
I've so far created a meta table, which lists all the tables and the column mapping information. This table holds the following data: SourceSchema, SourceTableName, SourceColumnName, TargetSchema, TargetTableName, TargetColumnName.
For each table, data is held in this table to map the source tables to the target tables.
I have then created a lookup which selects each table from the mapping table. It then does a for each loop and does another lookup to get the source and target column data for the table in the foreach iteration.
From this information, I'm able to map the Source table and the Sink table in a Copy Data activity created within the foreach loop, but I'm not sure how I can dynamically map the columns, or dynamically select only the columns I require from each source table. I have the "activity('LookupColumns').output" from the column lookup, but would be grateful if someone could suggest how I can use this to then map the source columns to the target columns for the copy activity. Thanks.
解决方案
In your case, you can use the expression in the mapping setting.
It needs your provide an expression and it's data should like this:{"type":"TabularTranslator","mappings":[{"source":{"name":"Id"},"sink":{"name":"CustomerID"}},{"source":{"name":"Name"},"sink":{"name":"LastName"}},{"source":{"name":"LastModifiedDate"},"sink":{"name":"ModifiedDate"}}]}
So you need to add a column named as Translator in your meta table, and it's value should be like the above JSON data. Then use this expression to do mapping:@item().Translator
推荐阅读
- pandas - 日期时间重新格式化每周列
- architecture - 最佳实践(GRPC 通信)架构微服务(List vs Loop)
- spring-boot - 一个项目中的 Spring Data JDBC 和 Hibernate JPA
- consul - 需要通过 API 或 Consul 等工具动态更改 linux conf/yaml 文件的建议
- java - Javax 验证不包括字段名称
- php - 如何在 PHP 中回显 SQL 行的位置编号?
- spring-boot - Spring Data JPA 分页 HHH000104
- c# - NLog - 如果消息以某些单词开头,则写入另一个目标
- javascript - javascript 切换单击在 addEventListener 中不起作用
- python - Python:读取目录中的所有文件以在while循环中观看