GEO 位置数据库更新模糊度
我有一个临时数据库,它将 GEO 位置存储为以下结构:
国家
地区
城市
邮政编码
经度
Latitude
我正在从供应商处获取数据。该名称不相关。数据位于 CSV 文件中,列是
启动IP
结束IP
国家
地区
城市
邮政编码
经度
纬度
事实上,CSV 文件中的数据往往会发生变化,例如邮政编码、城市名称、地区名称或 IP 范围。
应用程序处理数据导入工作的部分方式如下: 删除国家、地区、城市、邮政编码等。 并将数据重新填充到数据库中。
我需要一个更好的方法来做到这一点。因为当应用程序运行时,我将丢失数据库中该条目的密钥。然而此导入需要大约 2 分钟,这意味着应用程序将无法使用 GEO Location 数据库。所以我不能真正使用删除和插入。
我需要以这样的方式实现这一点:我将所有数据加载到内存中,并将其与我从列表中读取数据时的结构完全匹配。即:来自 DB 和 CSV 文件的国家/地区词典、地区词典。并在一个事务中检测更改并更新数据库。
问题是:如何映射它们,以便我可以检测到变化。换句话说,例如:如果国家/地区名称发生更改:),我需要使用 CSV 文件中的国家/地区名称更改为的内容进行更新。好的。但是超过 1 个国家/地区名称更改又如何呢?对于地区、城市、邮政编码也是如此。
是的,我将此广告存储为树结构。国家是根节点,地区是第一级子节点,城市是第二级,邮政编码是樱桃。
有什么想法吗?
对不起。解释起来有点长。感谢您花时间阅读本文。
I have a staging database which stores the GEO location as the following structure :
Countries
Regions
Cities
Postal Code
Longtitude
Latitude
I am getting the data from a vendor. The name is not relevant. The data comes in a CSV file, the columns are
Start IP
End IP
Country
Region
City
Postal Code
Longtitude
Latitude
The fact that the data comes in the CSV file tends to change, such as the Postal Code, City Name, Region Name, or the IP Range.
The way part of the application that handles the data import work as follows:
Delete Countries, Regions, Cities, Postal Code etc.
And Re populate the data into the Database.
I need a better way to this. Because when the application is live I will be losing the keys of this entries which are in the database. and yet this importing takes about 2 minutes, which means the application wont be able to do use GEO Location db. So i cant really use delete and insert.
I need to implement this such a way that, I will load all the data into memory and match it exactly as the structure of when I read the data from the list. i.e: Country Dictionary, Region Dictionary from DB and CSV file. and the detect the changes and update the database in one transaction.
The problem is: How to map them, so that I can detect changes. In other words, for example : If the Country name changes :), I need to update that with whatever the country name changed to in the CSV file. Ok. But how about more than 1 country name changes ? Same idea for regions, cities, postal codes.
Yes, I store this ad a Tree Structure. Country is the root node, Regions are first level childs, Cities are seconds level and Postal codes are the cherries.
Any ideas?
I m sorry. This was kinda long to explain. Appreciate the time you took to read through this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对 CSV 文件执行比较,并使用它来编写将更新数据库的 SQL。
Perform a diff on CSV files and use that to craft SQL that will update the database.
如果您想进行更新,可以使用 RedGate SQL Comparer (MS SQL)。非常好,会给你脚本。还有其他工具可以进行此类比较。这些步骤将
替代方案:
将其上传到新表名中,删除旧表并将此新表重命名为原始表名。当然,您还必须处理任何主键外键关系
if you want to do an update, you can use RedGate SQL Comparer (MS SQL). It is very good, will give you the scripts. There are also other tools which can do this sort of comparison. The steps would be
Alternative:
upload this into a new table name, drop the old table and rename this new table to the original table name. Ofcourse you would have to handle any primany key foreign key relationships as well