Ask HN: Data diff tool for tabular data?
Is there a tool you'd recommend to diff tabular data / TSV files?
Every day I have a snapshot of a database stored as TSV. Given two days of snapshots and that every item in the TSV has a unique ID, I'd like to get a list of which lines are new, changed, unchanged, and deleted between the two days. These lists will then be used to update an external service with an awkward database-like API.
I can kind of do this with normal diff but perhaps there's something better suited for the task? It reminds me of data joins in d3 but I'm not working with a UI or Javascript.
32 comments
[ 4.3 ms ] story [ 79.1 ms ] threadExample script:
[1]https://lnav.org
https://github.com/paulfitz/daff
The easiest way to do this is to use an ETL tool as hand coding this can be a bit hairy. You can use an open source etl tool like Talend for this as it has inbuilt Postgres or MySQL scd modules.
You can totally join two 'sheets' by primary key and save and replay that workflow, I think you may have to write a python function to iterate over the sets of columns to look for differences. Not sure if there's a cleaner way
[0] https://github.com/saulpw/visidata
http://augeas.net/docs/references/lenses/files/csv-aug.html
But will require a bit of coding
Another option that might fit would be a sort(1) pass on your TSV files (unless you already ORDER BY on the primary key), then using Awk to detect differences, and immediately print out a list of API commands to update your external DB. Awk conveniently handles tabular data, just set the field-separator (FS) to \t in this case (default it splits on all whitespace).
I made Quick to solve your exact problem! we use it to test our batch processes that either generate flat files or write data into database tables.
please contact me if you need help with the tool, i know that the docs are not as complete as i would like them to be.
here is the wiki: https://github.com/MouslihAbdelhakim/Quick/wiki
here is a repo of some examples: https://github.com/MouslihAbdelhakim/Quick-examples
It is not free but I find it much better than the usual visual diff free tools like kdiff3 or meld.
Supports delimited files and Postgres tables. Outputs a large JSON-based summary of record diffs or it emits an event stream as changes are found (and thus does not hold the summary in memory).
Prebuilt binaries: https://github.com/chop-dbhi/diff-table/releases
Edit: add link to releases and description
For example:
So, keep a table of the latest "data" you have. Then import into a separate table. After that, your requirements are solvable with a few SQL joins. The upside is that you also have a local copy of the data in a table, which is always a plus when diagnosing/supporting your deployed product.
The data sets you then need:
And each update to the external API also updates your local version of the data. I.e. Orig_table.I know it sounds a bit verbose and maybe not an "all in one" solution that you're looking for. But sometimes, you just need to solve the problem.
https://www.xlcompare.com
Import two snapshots of data like this:
Show difference between the two snapshots like so: See also the `noms diff` subcommand.https://github.com/capitalone/datacomparer