Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Byron Ruth <b@devel.io>
  • Loading branch information
bruth committed Mar 29, 2017
0 parents commit 407d57a
Show file tree
Hide file tree
Showing 6 changed files with 648 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
*.sw?
vendor/
dist/
49 changes: 49 additions & 0 deletions Makefile
@@ -0,0 +1,49 @@
PROG_NAME := "diff-table"
IMAGE_NAME := "dbhi/diff-table"
CMD_PATH := "."

GIT_SHA := $(shell git log -1 --pretty=format:"%h" .)
GIT_TAG := $(shell git describe --tags --exact-match . 2>/dev/null)
GIT_BRANCH := $(shell git symbolic-ref -q --short HEAD)
GIT_VERSION := $(shell git log -1 --pretty=format:"%h (%ci)" .)

build:
go build -ldflags "-X \"main.buildVersion=$(GIT_VERSION)\"" \
-o $(GOPATH)/bin/$(PROG_NAME) $(CMD_PATH)

dist-build:
mkdir -p dist

gox -output="./dist/{{.OS}}-{{.Arch}}/$(PROG_NAME)" \
-ldflags "-X \"main.buildVersion=$(GIT_VERSION)\"" \
-os "windows linux darwin" \
-arch "amd64" $(CMD_PATH) > /dev/null

dist-zip:
cd dist && zip $(PROG_NAME)-darwin-amd64.zip darwin-amd64/*
cd dist && zip $(PROG_NAME)-linux-amd64.zip linux-amd64/*
cd dist && zip $(PROG_NAME)-windows-amd64.zip windows-amd64/*

dist: dist-build dist-zip

docker:
docker build -t ${IMAGE_NAME}:${GIT_SHA} .
docker tag ${IMAGE_NAME}:${GIT_SHA} ${IMAGE_NAME}:${GIT_BRANCH}
if [ -n "${GIT_TAG}" ] ; then \
docker tag ${IMAGE_NAME}:${GIT_SHA} ${IMAGE_NAME}:${GIT_TAG} ; \
fi;
if [ "${GIT_BRANCH}" == "master" ]; then \
docker tag ${IMAGE_NAME}:${GIT_SHA} ${IMAGE_NAME}:latest ; \
fi;

docker-push:
docker push ${IMAGE_NAME}:${GIT_SHA}
docker push ${IMAGE_NAME}:${GIT_BRANCH}
if [ -n "${GIT_TAG}" ]; then \
docker push ${IMAGE_NAME}:${GIT_TAG} ; \
fi;
if [ "${GIT_BRANCH}" == "master" ]; then \
docker push ${IMAGE_NAME}:latest ; \
fi;

.PHONY: build dist-build dist
88 changes: 88 additions & 0 deletions README.md
@@ -0,0 +1,88 @@
# diff-table

A tool to compare two tables of data. Currently the tool only supports executing queries against a Postgres database, but there are plans to add more SQL drivers and flat file support.

The primary use case is to compare the output of a query executed at different points in time. For example, in a batch ETL process that runs every night, you can compare the previous batch with the new batch.

## Install

Download a [release](https://github.com/chop-dbhi/diff-table/releases).

## Usage

This is a minimum example which shows the required options.

```
diff-table \
-db postgres://localhost:5432/postgres \
-table1 data_v1 \
-table2 data_v2 \
-key id
```

Here are the full set of options.

```
Usage of diff-table:
-db string
Database 1 connection URL.
-db2 string
Database 2 connection URL. Defaults to db option.
-diff
Diff row values and output new rows and changes.
-key string
Required comma-separate list of columns.
-schema string
Name of the first schema.
-schema2 string
Name of the second schema. Defaults to schema option.
-table1 string
Name of the first table.
-table2 string
Name of the second table.
```

## Exampl

```
diff-table \
-db postgres://localhost:5432/postgres \
-table1 data_v1 \
-table2 data_v2 \
-key id
```

The output is a JSON encoded value which various information about the table differences. If `-diff` is supplied, the `row_diffs` and `new_rows` are tracked and outputed as well. Note, this may significantly increase memory usage if the tables are vastly different.

```
{
"total_rows": 2055856,
"columns_added": [],
"columns_dropped": [],
"type_changes": {},
"rows_added": 1,
"rows_deleted": 0,
"rows_changed": 1,
"row_diffs": [
{
"key": {
"id": 2009
},
"changes": {
"val": {
"old": 0.7576323747634888,
"new": 1.323199987411499
}
}
}
],
"new_rows": [
{
"id": 2010,
"val": 1.53921932383223
}
]
}
```


13 changes: 13 additions & 0 deletions lock.json
@@ -0,0 +1,13 @@
{
"memo": "edf2341b8b06db87de490e562dc95fe9bd9466b2b5dadcf6ed1daf3c99a3f046",
"projects": [
{
"name": "github.com/lib/pq",
"revision": "0dad96c0b94f8dee039aa40467f767467392a0af",
"packages": [
".",
"oid"
]
}
]
}

0 comments on commit 407d57a

Please sign in to comment.