Skip to content

Commit 7de6335

Browse files
committed
0.0.1 release
1 parent eed9bde commit 7de6335

12 files changed

Lines changed: 496 additions & 190 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
bin
2+
vendor
3+
Gopkg.lock
24
*.so
35
*.h

.travis.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,31 @@ go:
88

99
os:
1010
- linux
11-
- osx
11+
#- osx
1212

1313
matrix:
1414
allow_failures:
1515
- go: tip
1616
fast_finish: true
1717

18+
before_install:
19+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o $GOPATH/bin/dep; fi
20+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then wget https://github.com/golang/dep/releases/download/v0.5.0/dep-darwin-amd64 -O $GOPATH/bin/dep; fi
21+
- chmod +x $GOPATH/bin/dep
22+
23+
install:
24+
- dep ensure
25+
- go get -u github.com/alecthomas/gometalinter
26+
- gometalinter --install
27+
1828
script:
19-
- cd railgun
29+
- gometalinter --misspell-locale=US --disable-all --enable=misspell --enable=vet ./railgun/
30+
#- gometalinter --misspell-locale=US --disable-all --enable=misspell --enable=vet ./plugins/railgun/
31+
- gometalinter --misspell-locale=US --disable-all --enable=misspell --enable=vet ./cmd/railgun/
32+
- gometalinter --misspell-locale=US --disable-all --enable=misspell --enable=vet ./cmd/railgun.js/
33+
- cd gss
2034
- go fmt
2135
- cd ./../cmd/railgun
2236
- go fmt
37+
- cd ./../../cmd/railgun.js
38+
- go fmt

Gopkg.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[constraint]]
2+
name = "github.com/colinmarc/hdfs"
3+
revision = "279cc88949e23da3364c94a9ee440f5beee3ca65"

README.md

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,101 @@
1-
[![Build Status](https://travis-ci.org/spatialcurrent/railgun.svg)](https://travis-ci.org/spatialcurrent/railgun) [![GoDoc](https://godoc.org/github.com/spatialcurrent/railgun?status.svg)](https://godoc.org/github.com/spatialcurrent/railgun)
1+
[![Build Status](https://travis-ci.org/spatialcurrent/railgun.svg)](https://travis-ci.org/spatialcurrent/railgun) [![Go Report Card](https://goreportcard.com/badge/spatialcurrent/railgun)](https://goreportcard.com/report/spatialcurrent/railgun) [![GoDoc](https://godoc.org/github.com/spatialcurrent/railgun?status.svg)](https://godoc.org/github.com/spatialcurrent/railgun) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://github.com/spatialcurrent/railgun/blob/master/LICENSE)
22

33
# Railgun
44

55
# Description
66

7-
**Railgun** is a simple and fast data processing tool. **Railgun** uses [go-simple-serializer](https://github.com/spatialcurrent/go-simple-serializer) (GSS) for reading/writing objects to standard formats. **Railgun** uses [go-dfl](https://github.com/spatialcurrent/go-dfl) for filtering.
7+
**Railgun** is a simple and fast data processing tool. **Railgun** uses:
8+
- [go-reader](https://github.com/spatialcurrent/go-reader) for opening and reading from URIs,
9+
- [go-simple-serializer](https://github.com/spatialcurrent/go-simple-serializer) (GSS) for reading/writing objects to standard formats, and
10+
- [go-dfl](https://github.com/spatialcurrent/go-dfl) for filtering and transforming data.
811

9-
GSS supports `bson`, `csv`, `tsv`, `hcl`, `hcl2`, `json`, `jsonl`, `properties`, `toml`, `yaml`. `hcl` and `hcl2` implementation is fragile and very much in `alpha`.
12+
go-reader can read from `stdin`, `http/https`, the local filesystem, [AWS S3](https://aws.amazon.com/s3/), and [HDFS](https://hortonworks.com/apache/hdfs/).
13+
14+
go-simple-serializer (GSS) supports `bson`, `csv`, `tsv`, `hcl`, `hcl2`, `json`, `jsonl`, `properties`, `toml`, `yaml`. `hcl` and `hcl2` implementation is fragile and very much in `alpha`.
1015

1116
# Usage
1217

1318
**CLI**
1419

15-
You can use the command line tool to convert between formats.
20+
You can use the command line tool to process data.
1621

1722
```
18-
Usage: railgun -input_format INPUT_FORMAT -o OUTPUT_FORMAT [-input_uri INPUT_URI] [-input_compression [bzip2|gzip|snappy]] [-h HEADER] [-c COMMENT] [-object_path PATH] [-f FILTER] [-output_path OUTPUT_PATH] [-max MAX_COUNT]
23+
Usage: railgun -input_format INPUT_FORMAT -o OUTPUT_FORMAT [-input_uri INPUT_URI] [-input_compression [bzip2|gzip|snappy]] [-h HEADER] [-c COMMENT] [-object_path PATH] [-dfl_exp DFL_EXPRESSION] [-dfl_file DFL_FILE] [-output_path OUTPUT_PATH] [-max MAX_COUNT]
1924
Options:
25+
-aws_access_key_id string
26+
Defaults to value of environment variable AWS_ACCESS_KEY_ID
27+
-aws_default_region string
28+
Defaults to value of environment variable AWS_DEFAULT_REGION.
29+
-aws_secret_access_key string
30+
Defaults to value of environment variable AWS_SECRET_ACCESS_KEY.
31+
-aws_session_token string
32+
Defaults to value of environment variable AWS_SESSION_TOKEN.
2033
-c string
2134
The input comment character, e.g., #. Commented lines are not sent to output.
22-
-f string
23-
The output filter
35+
-dfl_exp string
36+
Process using dfl expression
37+
-dfl_file string
38+
Process using dfl file.
2439
-h string
2540
The input header if the stdin input has no header.
41+
-hdfs_name_node string
42+
Defaults to value of environment variable HDFS_DEFAULT_NAME_NODE.
2643
-help
2744
Print help.
2845
-input_compression string
29-
The input compression: none, gzip, snappy (default "none")
46+
The input compression: none, bzip2, gzip, snappy (default "none")
3047
-input_format string
31-
The input format: csv, tsv, hcl, hcl2, json, jsonl, properties, toml, yaml
48+
The input format: bson, csv, tsv, hcl, hcl2, json, jsonl, properties, toml, yaml
49+
-input_reader_buffer_size int
50+
The input reader buffer size (default 4096)
3251
-input_uri string
3352
The input uri (default "stdin")
3453
-max int
3554
The maximum number of objects to output (default -1)
36-
-o string
37-
The output format: csv, tsv, hcl, hcl2, json, jsonl, properties, toml, yaml
38-
-object_path string
39-
The output path
40-
-output_path string
41-
The output path
55+
-output_format string
56+
The output format: bson, csv, tsv, hcl, hcl2, json, jsonl, properties, toml, yaml
57+
-output_uri string
58+
The output uri (default "stdout")
4259
-version
4360
Prints version to stdout.
4461
```
4562

46-
**Go**
63+
# Releases
4764

48-
You can import **railgun** as a library with:
65+
**Railgun** is currently in **alpha**. See releases at https://github.com/spatialcurrent/railgun/releases.
4966

50-
```go
51-
import (
52-
"github.com/spatialcurrent/go-railgun/railgun"
53-
)
54-
```
67+
# Examples
5568

56-
The `Process` function is the core functions to use.
69+
**Search for Cuisine**
5770

58-
```go
59-
...
60-
output_object, err := railgun.Process(input_object, object_path, filter, funcs, max_count, output_path)
61-
...
62-
output_string, err := gss.Serialize(output_object, output_format)
63-
...
71+
```
72+
~/go/src/github.com/spatialcurrent/go-osm/bin/osm_linux_amd64 -input_uri 'http://download.geofabrik.de/north-america/us/district-of-columbia-latest.osm.bz2' -ways_to_nodes -output_format geojsonl -filter_keys_keep amenity -output_uri stdout | railgun -input_format jsonl -output_format json -dfl_file ~/go/src/github.com/spatialcurrent/railgun/examples/mexican.dfl -output_uri mexican.json
6473
```
6574

66-
# Releases
67-
68-
**Railgun** is currently in **alpha**. See releases at https://github.com/spatialcurrent/railgun/releases.
69-
70-
# Examples
75+
**Tsunami Feed**
7176

72-
TBD
77+
```
78+
const pipeline = ["filter(@features, '(@properties?.tsunami != null) and (@properties.tsunami == 1)')", "sort(@, '@properties?.mag', true)", "map(@, '@properties?.place ?: \"\"')", "limit(@, 10)"];
79+
(await fetch("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_month.geojson")).json().then(earthquakes => {
80+
result = railgun.process(earthquakes, {"dfl": pipeline, "output_format": "yaml"});
81+
console.log(result);
82+
})
83+
```
7384

7485
# Building
7586

7687
**CLI**
7788

7889
The `build_cli.sh` script is used to build executables for Linux and Windows.
7990

91+
**JavaScript**
92+
93+
You can compile GSS to pure JavaScript with the `scripts/build_javascript.sh` script.
94+
95+
**Changing Destination**
96+
97+
The default destination for build artifacts is `railgun/bin`, but you can change the destination with a CLI argument. For building on a Chromebook consider saving the artifacts in `/usr/local/go/bin`, e.g., `bash scripts/build_cli.sh /usr/local/go/bin`
98+
8099
# Contributing
81100

82101
[Spatial Current, Inc.](https://spatialcurrent.io) is currently accepting pull requests for this repository. We'd love to have your contributions! Please see [Contributing.md](https://github.com/spatialcurrent/railgun/blob/master/CONTRIBUTING.md) for how to get started.

cmd/railgun.js/main.go

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
// =================================================================
2+
//
3+
// Copyright (C) 2018 Spatial Current, Inc. - All Rights Reserved
4+
// Released as open source under the MIT License. See LICENSE file.
5+
//
6+
// =================================================================
7+
8+
// railgun.js is the Javascript version of Railgun.
9+
//
10+
package main
11+
12+
import (
13+
"fmt"
14+
"reflect"
15+
"strings"
16+
)
17+
18+
import (
19+
"github.com/pkg/errors"
20+
)
21+
22+
import (
23+
"github.com/spatialcurrent/go-dfl/dfl"
24+
"github.com/spatialcurrent/go-simple-serializer/gss"
25+
"github.com/spatialcurrent/railgun/railgun"
26+
)
27+
28+
import (
29+
"github.com/gopherjs/gopherjs/js"
30+
"honnef.co/go/js/console"
31+
)
32+
33+
var GO_RAILGUN_COMPRESSION_ALGORITHMS = []string{"none", "gzip", "snappy"}
34+
var GO_RAILGUN_FORMATS = []string{"csv", "tsv", "hcl", "hcl2", "json", "jsonl", "properties", "toml", "yaml"}
35+
36+
func main() {
37+
js.Global.Set("railgun", map[string]interface{}{
38+
"version": railgun.VERSION,
39+
"process": Process,
40+
})
41+
}
42+
43+
func Process(in interface{}, options *js.Object) interface{} {
44+
45+
// Convert Javascript options object into Golang map
46+
m := map[string]interface{}{}
47+
for _, key := range js.Keys(options) {
48+
m[key] = options.Get(key).Interface()
49+
}
50+
51+
input_header := []string{}
52+
input_comment := ""
53+
input_format := ""
54+
output_format := ""
55+
dfl_exp := ""
56+
57+
if v, ok := m["header"]; ok {
58+
switch v.(type) {
59+
case []string:
60+
input_header = v.([]string)
61+
case []interface{}:
62+
input_header = make([]string, 0, len(v.([]interface{})))
63+
for _, h := range v.([]interface{}) {
64+
input_header = append(input_header, fmt.Sprint(h))
65+
}
66+
}
67+
}
68+
69+
if v, ok := m["input_comment"]; ok {
70+
switch v.(type) {
71+
case string:
72+
input_comment = v.(string)
73+
}
74+
}
75+
76+
if v, ok := m["input_format"]; ok {
77+
switch v.(type) {
78+
case string:
79+
input_format = v.(string)
80+
}
81+
}
82+
83+
if v, ok := m["output_format"]; ok {
84+
switch v.(type) {
85+
case string:
86+
output_format = v.(string)
87+
}
88+
}
89+
90+
var ctx interface{}
91+
92+
switch in.(type) {
93+
case string:
94+
input_object, err := gss.NewObject(in.(string), input_format)
95+
if err != nil {
96+
console.Log(errors.Wrap(err, "error creating new object for format "+input_format))
97+
return ""
98+
}
99+
switch input_object_typed := input_object.(type) {
100+
case []map[string]interface{}:
101+
err = gss.Deserialize(in.(string), input_format, input_header, input_comment, &input_object_typed)
102+
if err != nil {
103+
console.Log(errors.Wrap(err, "error deserializing input using format "+input_format).Error())
104+
return ""
105+
}
106+
ctx = input_object_typed // This is a critical line, otherwise the type information is lost.
107+
default:
108+
err = gss.Deserialize(in.(string), input_format, input_header, input_comment, &input_object)
109+
if err != nil {
110+
console.Log(errors.Wrap(err, "error deserializing input using format "+input_format).Error())
111+
return ""
112+
}
113+
ctx = input_object
114+
}
115+
case *js.Object:
116+
ctx = in.(*js.Object).Interface()
117+
case map[string]interface{}:
118+
ctx = in.(map[string]interface{})
119+
default:
120+
console.Log("Unknown input type", fmt.Sprint(reflect.TypeOf(in)))
121+
}
122+
123+
if v, ok := m["dfl"]; ok {
124+
switch v.(type) {
125+
case string:
126+
dfl_exp = v.(string)
127+
case []interface{}:
128+
arr := dfl.TryConvertArray(v.([]interface{}))
129+
switch arr.(type) {
130+
case []string:
131+
dfl_exp = strings.Join(arr.([]string), " | ")
132+
}
133+
}
134+
}
135+
136+
var dfl_node dfl.Node
137+
if len(dfl_exp) > 0 {
138+
n, err := dfl.Parse(dfl_exp)
139+
if err != nil {
140+
console.Log(errors.Wrap(err, "Error parsing dfl node.").Error())
141+
return ""
142+
}
143+
dfl_node = n.Compile()
144+
}
145+
146+
var output interface{}
147+
if dfl_node != nil {
148+
o, err := dfl_node.Evaluate(ctx, dfl.NewFuntionMapWithDefaults())
149+
if err != nil {
150+
console.Log(errors.Wrap(err, "error processing").Error())
151+
return ""
152+
}
153+
output = o
154+
} else {
155+
output = ctx
156+
}
157+
158+
output = gss.StringifyMapKeys(output)
159+
160+
if len(output_format) > 0 {
161+
output_string, err := gss.Serialize(output, output_format)
162+
if err != nil {
163+
console.Log(errors.Wrap(err, "Error converting to output format "+output_format).Error())
164+
return ""
165+
}
166+
return output_string
167+
}
168+
169+
return output
170+
}

0 commit comments

Comments
 (0)