avro2json 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/avro2json.gemspec +1 -1
- data/bin/avro2json +32 -5
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df05647076cef6b928dc3123f326fd04239ead17
|
4
|
+
data.tar.gz: f7a4d9c0da6101f7f220069562722aff245b06f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a152f2b0844ba3a4800a0834ba3d41b806f065c439e3d6a07077780bfb3a49145b463bd3e9a03fccbafde87ff24ac751a828d4c8284c6f0bccab71a377140df
|
7
|
+
data.tar.gz: f341ff83748fb27a54ee89a1ab7bb6490ea21c254bd75cb1fae5e156c6e9efb73459f97c56efb8815425bf44fe3637c07eb2534406415764d2f2eb6910dac82f
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# avro2json
|
2
|
+
|
3
|
+
Converts Avro-encoded data to JSON.
|
4
|
+
|
5
|
+
```
|
6
|
+
curl http://example.com/data.avro | avro2json
|
7
|
+
cat somefile.avro | avro2json
|
8
|
+
avro2json < somefile.avro
|
9
|
+
```
|
10
|
+
|
11
|
+
It's possible to use a custom schema when reading the Avro data:
|
12
|
+
|
13
|
+
```
|
14
|
+
avro2json --schema=some-schema.avsc < data.avro
|
15
|
+
```
|
16
|
+
|
17
|
+
Run `avro2json -h` for more information.
|
data/avro2json.gemspec
CHANGED
data/bin/avro2json
CHANGED
@@ -3,12 +3,39 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'avro'
|
5
5
|
require 'json'
|
6
|
+
require 'optparse'
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
def load_records(input, options)
|
9
|
+
schema_path = options[:schema_path]
|
10
|
+
schema = schema_path && Avro::Schema.parse(File.read(schema_path))
|
11
|
+
Avro::DataFile::Reader.new(input, Avro::IO::DatumReader.new(nil, schema))
|
12
|
+
end
|
13
|
+
|
14
|
+
def main
|
15
|
+
options = {}
|
16
|
+
|
17
|
+
option_parser = OptionParser.new do |opts|
|
18
|
+
opts.banner = "Usage: avro2json [options]"
|
19
|
+
|
20
|
+
opts.on("-sSCHEMA", "--schema=SCHEMA", "Use the specified schema file when decoding") do |schema|
|
21
|
+
options[:schema_path] = schema
|
22
|
+
end
|
9
23
|
|
10
|
-
|
24
|
+
opts.on("-h", "--help", "Prints this help") do
|
25
|
+
puts opts
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
end
|
11
29
|
|
12
|
-
|
13
|
-
|
30
|
+
option_parser.parse!
|
31
|
+
|
32
|
+
# Buffer the input in order to allow seeking -- otherwise Avro blows up.
|
33
|
+
input = StringIO.new($stdin.read)
|
34
|
+
records = load_records(input, options)
|
35
|
+
|
36
|
+
records.each do |record|
|
37
|
+
puts JSON.pretty_generate(record)
|
38
|
+
end
|
14
39
|
end
|
40
|
+
|
41
|
+
main
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avro2json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- ".gitignore"
|
64
64
|
- Gemfile
|
65
65
|
- LICENSE.txt
|
66
|
+
- README.md
|
66
67
|
- Rakefile
|
67
68
|
- avro2json.gemspec
|
68
69
|
- bin/avro2json
|