All Projects → paulfitz → Daff

paulfitz / Daff

Licence: mit
align and compare tables

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Daff

Indonesia Postal And Area
Indonesia Postal Code & Area (BPS)
Stars: ✭ 64 (-89.3%)
Mutual labels:  csv, sqlite
Winmerge
WinMerge is an Open Source differencing and merging tool for Windows. WinMerge can compare both folders and files, presenting differences in a visual text format that is easy to understand and handle.
Stars: ✭ 2,358 (+294.31%)
Mutual labels:  csv, diff
Csvpack
csvpack library / gem - tools 'n' scripts for working with tabular data packages using comma-separated values (CSV) datafiles in text with meta info (that is, schema, datatypes, ..) in datapackage.json; download, read into and query CSV datafiles with your SQL database (e.g. SQLite, PostgreSQL, ...) of choice and much more
Stars: ✭ 71 (-88.13%)
Mutual labels:  csv, sqlite
Csvs To Sqlite
Convert CSV files into a SQLite database
Stars: ✭ 568 (-5.02%)
Mutual labels:  csv, sqlite
Pgloader
Migrate to PostgreSQL in a single command!
Stars: ✭ 3,754 (+527.76%)
Mutual labels:  csv, sqlite
Diff Table
Stars: ✭ 21 (-96.49%)
Mutual labels:  csv, diff
Rbql
🦜RBQL - Rainbow Query Language: SQL-like language for (not only) CSV file processing. Supports SQL queries with Python and JavaScript expressions
Stars: ✭ 118 (-80.27%)
Mutual labels:  csv, sqlite
Csv Diff
Python CLI tool and library for diffing CSV and JSON files
Stars: ✭ 118 (-80.27%)
Mutual labels:  csv, diff
csv-to-sqlite
A desktop app to convert CSV files to SQLite databases!
Stars: ✭ 68 (-88.63%)
Mutual labels:  csv, sqlite
dbd
dbd is a database prototyping tool that enables data analysts and engineers to quickly load and transform data in SQL databases.
Stars: ✭ 30 (-94.98%)
Mutual labels:  csv, sqlite
Nano Sql
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Stars: ✭ 717 (+19.9%)
Mutual labels:  csv, sqlite
Pytablewriter
pytablewriter is a Python library to write a table in various formats: CSV / Elasticsearch / HTML / JavaScript / JSON / LaTeX / LDJSON / LTSV / Markdown / MediaWiki / NumPy / Excel / Pandas / Python / reStructuredText / SQLite / TOML / TSV.
Stars: ✭ 422 (-29.43%)
Mutual labels:  csv, sqlite
Sqlitebiter
A CLI tool to convert CSV / Excel / HTML / JSON / Jupyter Notebook / LDJSON / LTSV / Markdown / SQLite / SSV / TSV / Google-Sheets to a SQLite database file.
Stars: ✭ 601 (+0.5%)
Mutual labels:  csv, sqlite
Datasette
An open source multi-tool for exploring and publishing data
Stars: ✭ 5,640 (+843.14%)
Mutual labels:  csv, sqlite
winmerge2011
Fork of WinMerge which has a different set of features
Stars: ✭ 36 (-93.98%)
Mutual labels:  diff, sqlite
Visidata
A terminal spreadsheet multitool for discovering and arranging data
Stars: ✭ 4,606 (+670.23%)
Mutual labels:  csv, sqlite
Excelmerge
GUI Diff Tool for Excel
Stars: ✭ 425 (-28.93%)
Mutual labels:  csv, diff
Go Sqlbuilder
A flexible and powerful SQL string builder library plus a zero-config ORM.
Stars: ✭ 539 (-9.87%)
Mutual labels:  sqlite
Sqlitedb
Basic SQLite wrapper for Swift 4.x and lightweight ORM for accessing underlying tables in an SQLite database
Stars: ✭ 538 (-10.03%)
Mutual labels:  sqlite
Laracsv
A Laravel package to easily generate CSV files from Eloquent model
Stars: ✭ 583 (-2.51%)
Mutual labels:  csv

Build Status NPM version Gem Version PyPI version PHP version Bower version Badge count

daff: data diff

This is a library for comparing tables, producing a summary of their differences, and using such a summary as a patch file. It is optimized for comparing tables that share a common origin, in other words multiple versions of the "same" table.

For a live demo, see:

http://paulfitz.github.com/daff/

Install the library for your favorite language:

npm install daff -g  # node/javascript
pip install daff     # python
gem install daff     # ruby
composer require paulfitz/daff-php  # php
install.packages('daff') # R wrapper by Edwin de Jonge
bower install daff   # web/javascript

Other translations are available here:

https://github.com/paulfitz/daff/releases

Or use the library to view csv diffs on github via a chrome extension:

https://github.com/theodi/csvhub

The diff format used by daff is specified here:

http://paulfitz.github.io/daff-doc/spec.html

This library is a stripped down version of the coopy toolbox (see http://share.find.coop). To compare tables from different origins, or with automatically generated IDs, or other complications, check out the coopy toolbox.

The program

You can run daff/daff.py/daff.rb as a utility program:

$ daff
daff can produce and apply tabular diffs.
Call as:
  daff a.csv b.csv
  daff [--color] [--no-color] [--output OUTPUT.csv] a.csv b.csv
  daff [--output OUTPUT.html] a.csv b.csv
  daff [--www] a.csv b.csv
  daff parent.csv a.csv b.csv
  daff --input-format sqlite a.db b.db
  daff patch [--inplace] a.csv patch.csv
  daff merge [--inplace] parent.csv a.csv b.csv
  daff trim [--output OUTPUT.csv] source.csv
  daff render [--output OUTPUT.html] diff.csv
  daff copy in.csv out.tsv
  daff in.csv
  daff git
  daff version

The --inplace option to patch and merge will result in modification of a.csv.

If you need more control, here is the full list of flags:
  daff diff [--output OUTPUT.csv] [--context NUM] [--all] [--act ACT] a.csv b.csv
     --act ACT:     show only a certain kind of change (update, insert, delete, column)
     --all:         do not prune unchanged rows or columns
     --all-rows:    do not prune unchanged rows
     --all-columns: do not prune unchanged columns
     --color:       highlight changes with terminal colors (default in terminals)
     --context NUM: show NUM rows of context (0=none)
     --context-columns NUM: show NUM columns of context (0=none)
     --fail-if-diff: return status is 0 if equal, 1 if different, 2 if problem
     --id:          specify column to use as primary key (repeat for multi-column key)
     --ignore:      specify column to ignore completely (can repeat)
     --index:       include row/columns numbers from original tables
     --input-format [csv|tsv|ssv|psv|json|sqlite]: set format to expect for input
     --eol [crlf|lf|cr|auto]: separator between rows of csv output.
     --no-color:    make sure terminal colors are not used
     --ordered:     assume row order is meaningful (default for CSV)
     --output-format [csv|tsv|ssv|psv|json|copy|html]: set format for output
     --padding [dense|sparse|smart]: set padding method for aligning columns
     --table NAME:  compare the named table, used with SQL sources. If name changes, use 'n1:n2'
     --unordered:   assume row order is meaningless (default for json formats)
     -w / --ignore-whitespace: ignore changes in leading/trailing whitespace
     -i / --ignore-case: ignore differences in case

  daff render [--output OUTPUT.html] [--css CSS.css] [--fragment] [--plain] diff.csv
     --css CSS.css: generate a suitable css file to go with the html
     --fragment:    generate just a html fragment rather than a page
     --plain:       do not use fancy utf8 characters to make arrows prettier
     --unquote:     do not quote html characters in html diffs
     --www:         send output to a browser

Formats supported are CSV, TSV, Sqlite (with --input-format sqlite or the .sqlite extension), and ndjson.

Using with git

Run daff git csv to install daff as a diff and merge handler for *.csv files in your repository. Run daff git for instructions on doing this manually. Your CSV diffs and merges will get smarter, since git will suddenly understand about rows and columns, not just lines:

Example CSV diff

The library

You can use daff as a library from any supported language. We take here the example of Javascript. To use daff on a webpage, first include daff.js:

<script src="daff.js"></script>

Or if using node outside the browser:

var daff = require('daff');

For concreteness, assume we have two versions of a table, data1 and data2:

var data1 = [
    ['Country','Capital'],
    ['Ireland','Dublin'],
    ['France','Paris'],
    ['Spain','Barcelona']
];
var data2 = [
    ['Country','Code','Capital'],
    ['Ireland','ie','Dublin'],
    ['France','fr','Paris'],
    ['Spain','es','Madrid'],
    ['Germany','de','Berlin']
];

To make those tables accessible to the library, we wrap them in daff.TableView:

var table1 = new daff.TableView(data1);
var table2 = new daff.TableView(data2);

We can now compute the alignment between the rows and columns in the two tables:

var alignment = daff.compareTables(table1,table2).align();

To produce a diff from the alignment, we first need a table for the output:

var data_diff = [];
var table_diff = new daff.TableView(data_diff);

Using default options for the diff:

var flags = new daff.CompareFlags();
var highlighter = new daff.TableDiff(alignment,flags);
highlighter.hilite(table_diff);

The diff is now in data_diff in highlighter format, see specification here:

http://paulfitz.github.io/daff-doc/spec.html

[ [ '!', '', '+++', '' ],
  [ '@@', 'Country', 'Code', 'Capital' ],
  [ '+', 'Ireland', 'ie', 'Dublin' ],
  [ '+', 'France', 'fr', 'Paris' ],
  [ '->', 'Spain', 'es', 'Barcelona->Madrid' ],
  [ '+++', 'Germany', 'de', 'Berlin' ] ]

For visualization, you may want to convert this to a HTML table with appropriate classes on cells so you can color-code inserts, deletes, updates, etc. You can do this with:

var diff2html = new daff.DiffRender();
diff2html.render(table_diff);
var table_diff_html = diff2html.html();

For 3-way differences (that is, comparing two tables given knowledge of a common ancestor) use daff.compareTables3 (give ancestor table as the first argument).

Here is how to apply that difference as a patch:

var patcher = new daff.HighlightPatch(table1,table_diff);
patcher.apply();
// table1 should now equal table2

For other languages, you should find sample code in the packages on the Releases page.

Supported languages

The daff library is written in Haxe, which can be translated reasonably well into at least the following languages:

Some translations are done for you on the Releases page. To make another translation, or to compile from source first follow the Haxe language introduction for the language you care about. At the time of writing, if you are on OSX, you should install haxe using brew install haxe. Then do one of:

make js
make php
make py
make java
make cs
make cpp

For each language, the daff library expects to be handed an interface to tables you create, rather than creating them itself. This is to avoid inefficient copies from one format to another. You'll find a SimpleTable class you can use if you find this awkward.

Other possibilities:

API documentation

Sponsors

the zen of venn The Data Commons Co-op, "perhaps the geekiest of all cooperative organizations on the planet," has given great moral support during the development of `daff`. Donate a multiple of `42.42` in your currency to let them know you care: https://datacommons.coop/donate/.

Reading material

License

daff is distributed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].