SSIS查找相关数据,如果缺失则添加
假设我有这样的输入数据:
firstName |姓氏 |国家
鲍勃 |史密斯|英国
简|美国能源部 |法国
汉克|天蝎座| UK
和目标表是:
People
身份证 |名字 |姓氏 | CountryId
国家/地区
身份证 |国家/地区名称
0 |法国
现在在SSIS数据流任务中我读取输入,使用查找在Country表中搜索匹配的CountryName,如果存在没有问题,则返回ID并继续,但如果不存在我想使用OLEDBCommand要在 Country 表中创建记录,获取 ID 并继续。
然而,正在发生的情况是 UK 两次被传递给 OLEDBCommand。
我应该如何处理这种情况?是否有某种方法可以强制查找一次检查一条记录,因为它似乎在添加丢失的记录之前检查一批记录。我尝试在完全和无影响之间更改缓存选项。
say I have input data like so:
firstName | lastName | Country
Bob | Smith | UK
Jane | Doe | France
Hank | Scorpio | UK
and the target tables are:
People
ID | firstName | lastName | CountryId
Country
ID | CountryName
0 | France
Now in SSIS data flow task I read the input, use a lookup to search the Country table for a matching CountryName, if it exists no problem, return the ID and carry on, but if it does not exists I want to use an OLEDBCommand to create the record in the Country table, get the ID and carry on.
However, what is happening is that UK is getting passed to the OLEDBCommand twice.
How should I be handling this scenario? is there some way of forcing the lookup to check one record at a time as it seem to be checking a batch before adding the missing records. I have tried changing the cache options between full and none to no affect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将缓冲区大小设置为 1(每个缓冲区一行),并且在查找时不使用缓存,但即使如此,您也可能会冒着“同时”处理两行的风险(由于 ssis 的并行化) 。
然而,你能做的就是以不同的方式思考它。也许您不需要一步完成这一切。
首先,加载所有用户并检查国家/地区。对于那些没有的,请汇总(基于国家/地区),并将其插入您的国家/地区表中。
然后,您可以使用正常查找加载所有用户 - 因为国家/地区表已预先填充。
You could go around to set buffer size to 1 (one row per buffer), and no cache on the lookup, but even so you risk (because of the parallelisation of ssis) to have two rows going at it at the "same time".
What you can do however is to think of it differently. Perhaps you don't need to do it all in one step.
First, load all users and check against country. For those that doesn't have, gather up in an aggregate (based on country), and insert those into your Country table.
Then, you can load all your users using a normal lookup - because the Country table has been prefilled.