我有大约1亿条记录的数据库表的两个版本(旧/新)。它们在文件中:
trx-old
trx-new
结构为:
id date amount memo
1 5/1 100 slacks
2 5/1 50 wine
id是简单的主键,其他字段是非键。我想生成三个文件:
trx-removed (ids of records present in trx-old but not in trx-new)
trx-added (records from trx-new whose ids are not present in trx-old)
trx-changed (records from trx-new whose non-key values have changed since trx-old)
我需要每天在一个简短的批处理窗口中执行此操作。实际上,我需要针对多个表和多个模式(为每个模式生成三个文件)执行此操作,因此实际的应用程序会涉及更多的内容。但是我认为这个例子捕获了问题的症结所在。
感觉好像是mapreduce的明显应用。从未编写过mapreduce应用程序,我的问题是:
PS:我看到了diff between tables问题,但那边的解决方案似乎没有扩展性。
PPS这是一个演示算法的 ruby 小玩具:Ruby dbdiff
最佳答案
我认为仅编写自己的作业将是最容易的,主要是因为当典型的reducer仅写入一个文件时,您将希望使用MultipleOutputs从单个reduce步骤中写入三个单独的文件。您需要使用MultipleInputs为每个表指定一个映射器。
关于sql - Mapreduce表差异,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16377819/