zillabyte 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/ruby/README.md +2 -0
- data/ruby/lib/zillabyte.rb +20 -0
- data/ruby/lib/zillabyte/common/progress.rb +17 -0
- data/ruby/lib/zillabyte/harness.rb +16 -0
- data/ruby/lib/zillabyte/harness/aggregate.rb +29 -0
- data/ruby/lib/zillabyte/harness/counter.rb +11 -0
- data/ruby/lib/zillabyte/harness/each.rb +29 -0
- data/ruby/lib/zillabyte/harness/groupby.rb +9 -0
- data/ruby/lib/zillabyte/harness/helper.rb +326 -0
- data/ruby/lib/zillabyte/harness/live_delegator.rb +369 -0
- data/ruby/lib/zillabyte/harness/simple_function.rb +131 -0
- data/ruby/lib/zillabyte/harness/simple_spout.rb +90 -0
- data/ruby/lib/zillabyte/harness/sink.rb +23 -0
- data/ruby/lib/zillabyte/harness/spout.rb +48 -0
- data/ruby/lib/zillabyte/harness/topology.rb +132 -0
- data/ruby/lib/zillabyte/harness/tuple.rb +32 -0
- data/ruby/lib/zillabyte/version.rb +3 -0
- metadata +103 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
class Zillabyte::Harness::SimpleSpout
|
4
|
+
attr_accessor :_nodes, :_sink, :_name
|
5
|
+
|
6
|
+
|
7
|
+
def self.build()
|
8
|
+
|
9
|
+
# Parse the options...
|
10
|
+
options = Zillabyte::Harness::Helper.opt_parser()
|
11
|
+
flow = Zillabyte::Harness::SimpleSpout.new()
|
12
|
+
flow._nodes = []
|
13
|
+
flow._name = options[:name]
|
14
|
+
|
15
|
+
# Get the user logic...
|
16
|
+
yield(flow)
|
17
|
+
if(options[:command] == :info)
|
18
|
+
_info_file = File.open(options[:file], "w+")
|
19
|
+
info_hash = {"language" => "ruby", "name" => flow._name}
|
20
|
+
Zillabyte::Harness::Helper.write_hash_to_file(info_hash, _info_file)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get the spout-specific logic...
|
24
|
+
spout = Zillabyte::Harness::Spout.new(false)
|
25
|
+
yield(spout)
|
26
|
+
spout._name = "spout"
|
27
|
+
flow._nodes << spout
|
28
|
+
if(options[:command] == :info)
|
29
|
+
info_hash = {"name" => spout._name, "type" => spout._type}
|
30
|
+
if(spout._emits)
|
31
|
+
info_hash["emits"] = spout._emits
|
32
|
+
elsif(spout._relation)
|
33
|
+
info_hash["relation"] = spout._relation
|
34
|
+
elsif(spout._matches)
|
35
|
+
info_hash["matches"] = spout._matches
|
36
|
+
end
|
37
|
+
Zillabyte::Harness::Helper.write_hash_to_file(info_hash, _info_file)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Add the sink...
|
41
|
+
flow._nodes << flow._sink
|
42
|
+
if(options[:command] == :info)
|
43
|
+
info_hash = {"name" => flow._sink._name, "type" => flow._sink._type, "columns" => flow._sink._columns}
|
44
|
+
Zillabyte::Harness::Helper.write_hash_to_file(info_hash, _info_file)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Execute...
|
48
|
+
if(options[:command] == :execute and options[:name] == "spout")
|
49
|
+
pipe_name = options[:pipe]
|
50
|
+
c = Zillabyte::Harness::SpoutController.new(spout, progress = Zillabyte::Common::Progress.new)
|
51
|
+
c.run(pipe_name)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Done
|
55
|
+
flow
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
def name(v)
|
61
|
+
Zillabyte::Harness::Helper.check_name("simple_spout", v, {})
|
62
|
+
@_name = v
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def emits(v)
|
67
|
+
# Construct the sink...
|
68
|
+
Zillabyte::Harness::Helper.check_emits("simple_spout", v, {})
|
69
|
+
@_sink = Zillabyte::Harness::Sink.new()
|
70
|
+
@_sink.name(v[0][0])
|
71
|
+
columns = v[0][1]
|
72
|
+
columns.each do |col|
|
73
|
+
col.each do |cname, ctype|
|
74
|
+
@_sink.column(cname, ctype)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def prepare(&block)
|
81
|
+
# Dummy function, prepare is picked up by Each above
|
82
|
+
end
|
83
|
+
|
84
|
+
def next_batch(&block)
|
85
|
+
# Dummy function, execute is picked up by Each above
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
end
|
90
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Zillabyte::Harness::Sink
|
2
|
+
attr_accessor :_name, :_type, :_columns, :_consumes
|
3
|
+
|
4
|
+
def initialize()
|
5
|
+
@_type = 'sink'
|
6
|
+
@_columns = []
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def consumes(v)
|
11
|
+
@_consumes = v
|
12
|
+
end
|
13
|
+
|
14
|
+
def name(v)
|
15
|
+
@_name = v
|
16
|
+
end
|
17
|
+
|
18
|
+
def column(cname, ctype)
|
19
|
+
col = {cname => ctype}
|
20
|
+
@_columns << col
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Zillabyte::Harness::Spout
|
2
|
+
attr_accessor :_name, :_type, :_matches, :_relation, :_emits, :_prepare, :_next_batch, :_flow_flag
|
3
|
+
|
4
|
+
def initialize(flow_flag)
|
5
|
+
@_name = "spout_"+Zillabyte::Harness::Counter.get()
|
6
|
+
@_type = 'spout'
|
7
|
+
@_flow_flag = flow_flag
|
8
|
+
end
|
9
|
+
|
10
|
+
def matches(v, options = {})
|
11
|
+
case v
|
12
|
+
when String
|
13
|
+
@_relation = { :query => v, :options => options.is_a?(Hash) ? options : {} }
|
14
|
+
when Array
|
15
|
+
@_matches = v
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def name(v)
|
20
|
+
@_name = v
|
21
|
+
end
|
22
|
+
|
23
|
+
def emits(v)
|
24
|
+
if(@_flow_flag)
|
25
|
+
@_emits = v
|
26
|
+
else
|
27
|
+
@_emits = []
|
28
|
+
v.each do |relation|
|
29
|
+
temit = []
|
30
|
+
relation[1].each do |column|
|
31
|
+
column.each do |col, type|
|
32
|
+
temit << col
|
33
|
+
end
|
34
|
+
end
|
35
|
+
@_emits << [relation[0], temit]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def prepare(&block)
|
41
|
+
@_prepare = block
|
42
|
+
end
|
43
|
+
|
44
|
+
def next_batch(&block)
|
45
|
+
@_next_batch = block
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
class Zillabyte::Harness::Topology
|
4
|
+
attr_accessor :_name, :_options, :_nodes, :_streams, :_names, :_branched, :_info_file #instance variables?
|
5
|
+
|
6
|
+
def self.build(name)
|
7
|
+
h = Zillabyte::Harness::Topology.new()
|
8
|
+
h._nodes = []
|
9
|
+
h._streams = {}
|
10
|
+
h._names = {}
|
11
|
+
h._branched = false
|
12
|
+
h._name = name || Dir.pwd.split("/")[-1]
|
13
|
+
Zillabyte::Harness::Helper.check_name("new", h._name, {})
|
14
|
+
h._options = Zillabyte::Harness::Helper.opt_parser()
|
15
|
+
if(h._options[:command] == :info)
|
16
|
+
h._info_file = File.open(h._options[:file],"w+")
|
17
|
+
info_hash = {"language" => "ruby", "name" => h._name}
|
18
|
+
Zillabyte::Harness::Helper.write_hash_to_file(info_hash, h._info_file)
|
19
|
+
end
|
20
|
+
h
|
21
|
+
end
|
22
|
+
|
23
|
+
def spout_from_relation()
|
24
|
+
h = Zillabyte::Harness::Spout.new(true)
|
25
|
+
yield(h)
|
26
|
+
Zillabyte::Harness::Helper.check_name("spout", h._name, @_names)
|
27
|
+
@_nodes << h
|
28
|
+
if(@_options[:command] == :info)
|
29
|
+
info_hash = {"name" => h._name, "type" => h._type}
|
30
|
+
if(h._relation)
|
31
|
+
info_hash["relation"] = h._relation
|
32
|
+
elsif(h._matches)
|
33
|
+
info_hash["matches"] = h._matches
|
34
|
+
end
|
35
|
+
Zillabyte::Harness::Helper.write_hash_to_file(info_hash, @_info_file)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def spout
|
40
|
+
h = Zillabyte::Harness::Spout.new(true)
|
41
|
+
yield(h)
|
42
|
+
Zillabyte::Harness::Helper.check_name("spout", h._name, @_names)
|
43
|
+
@_branched = Zillabyte::Harness::Helper.check_emits("spout", h._emits, @_streams) || @_branched
|
44
|
+
@_nodes << h
|
45
|
+
if(@_options[:command] == :info)
|
46
|
+
info_hash = {"name" => h._name, "type" => h._type, "emits" => h._emits}
|
47
|
+
Zillabyte::Harness::Helper.write_hash_to_file(info_hash, @_info_file)
|
48
|
+
elsif(@_options[:command] == :execute and @_options[:name] == h._name)
|
49
|
+
pipe_name = @_options[:pipe]
|
50
|
+
c = Zillabyte::Harness::SpoutController.new(h, progress = Zillabyte::Common::Progress.new)
|
51
|
+
c.run(pipe_name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def each
|
56
|
+
h = Zillabyte::Harness::Each.new()
|
57
|
+
yield(h)
|
58
|
+
Zillabyte::Harness::Helper.check_name("each", h._name, @_names)
|
59
|
+
if(@_branched)
|
60
|
+
Zillabyte::Harness::Helper.check_consumes(h, @_streams)
|
61
|
+
else
|
62
|
+
if(h._consumes)
|
63
|
+
h._consumes = nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
@_branched = Zillabyte::Harness::Helper.check_emits("each", h._emits, @_streams) || @_branched
|
67
|
+
@_nodes << h
|
68
|
+
if(@_options[:command] == :info)
|
69
|
+
info_hash = {"name" => h._name, "type" => h._type, "emits" => h._emits}
|
70
|
+
if(h._consumes)
|
71
|
+
info_hash["consumes"] = h._consumes
|
72
|
+
end
|
73
|
+
Zillabyte::Harness::Helper.write_hash_to_file(info_hash, @_info_file)
|
74
|
+
elsif(@_options[:command] == :execute and @_options[:name] == h._name)
|
75
|
+
pipe_name = @_options[:pipe]
|
76
|
+
c = Zillabyte::Harness::EachController.new(h, progress = Zillabyte::Common::Progress.new)
|
77
|
+
c.run(pipe_name)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def group_by(fields)
|
82
|
+
h = Zillabyte::Harness::GroupBy.new(fields)
|
83
|
+
@_nodes << h
|
84
|
+
end
|
85
|
+
|
86
|
+
def aggregate
|
87
|
+
h = Zillabyte::Harness::Aggregate.new()
|
88
|
+
yield(h)
|
89
|
+
Zillabyte::Harness::Helper.check_name("aggregate", h._name, @_names)
|
90
|
+
@_branched = Zillabyte::Harness::Helper.check_emits("aggregate", h._emits, @_streams) || @_branched
|
91
|
+
@_nodes << h
|
92
|
+
if(@_options[:command] == :info)
|
93
|
+
info_hash = {"name" => h._name, "type" => h._type, "emits" => h._emits}
|
94
|
+
if(h._consumes)
|
95
|
+
info_hash["consumes"] = h._consumes
|
96
|
+
end
|
97
|
+
Zillabyte::Harness::Helper.write_hash_to_file(info_hash, @_info_file)
|
98
|
+
elsif(@_options[:command] == :execute)
|
99
|
+
pipe_name = @_options[:pipe]
|
100
|
+
if(@_options[:name] == h._name+"_start")
|
101
|
+
c = Zillabyte::Harness::AggregateStartController.new(h, Zillabyte::Common::Progress.new)
|
102
|
+
elsif(@_options[:name] == h._name+"_aggregate")
|
103
|
+
c = Zillabyte::Harness::AggregateAggregateController.new(h, Zillabyte::Common::Progress.new)
|
104
|
+
elsif(@_options[:name] == h._name+"_complete")
|
105
|
+
c = Zillabyte::Harness::AggregateCompleteController.new(h, Zillabyte::Common::Progress.new)
|
106
|
+
end
|
107
|
+
c.run(pipe_name)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def sink
|
112
|
+
h = Zillabyte::Harness::Sink.new()
|
113
|
+
yield(h)
|
114
|
+
Zillabyte::Harness::Helper.check_sink(h, @_nodes)
|
115
|
+
if(@_branched)
|
116
|
+
Zillabyte::Harness::Helper.check_consumes(h, @_streams)
|
117
|
+
else
|
118
|
+
if(h._consumes)
|
119
|
+
h._consumes = nil
|
120
|
+
end
|
121
|
+
end
|
122
|
+
@_nodes << h
|
123
|
+
if(@_options[:command] == :info)
|
124
|
+
info_hash = {"name" => h._name, "type" => h._type, "columns" => h._columns}
|
125
|
+
if(h._consumes)
|
126
|
+
info_hash["consumes"] = h._consumes
|
127
|
+
end
|
128
|
+
Zillabyte::Harness::Helper.write_hash_to_file(info_hash, @_info_file)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Tuple
|
2
|
+
attr_accessor :id, :component, :stream, :task, :values, :fields
|
3
|
+
|
4
|
+
def initialize(hash)
|
5
|
+
@hash = hash
|
6
|
+
end
|
7
|
+
|
8
|
+
def [](k)
|
9
|
+
values[k]
|
10
|
+
end
|
11
|
+
|
12
|
+
def values
|
13
|
+
@hash["tuple"]
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def self.from_hash(hash)
|
18
|
+
begin
|
19
|
+
t = hash.fetch("tuple")
|
20
|
+
rescue Exception => e
|
21
|
+
fail 'Missing tuple field in emitted JSON object' + e.backtrace.join('\n')
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
begin
|
25
|
+
m = hash.fetch("meta")
|
26
|
+
rescue Exception => e
|
27
|
+
fail 'Missing meta field in emitted JSON object' + e.backtrace.join('\n')
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
Tuple.new(hash)
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zillabyte
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- zillabyte
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: zillabyte-cli
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: The Official Zillabyte Gem
|
56
|
+
email:
|
57
|
+
- gem@zillabyte.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ruby/lib/zillabyte/common/progress.rb
|
63
|
+
- ruby/lib/zillabyte/harness/aggregate.rb
|
64
|
+
- ruby/lib/zillabyte/harness/counter.rb
|
65
|
+
- ruby/lib/zillabyte/harness/each.rb
|
66
|
+
- ruby/lib/zillabyte/harness/groupby.rb
|
67
|
+
- ruby/lib/zillabyte/harness/helper.rb
|
68
|
+
- ruby/lib/zillabyte/harness/live_delegator.rb
|
69
|
+
- ruby/lib/zillabyte/harness/simple_function.rb
|
70
|
+
- ruby/lib/zillabyte/harness/simple_spout.rb
|
71
|
+
- ruby/lib/zillabyte/harness/sink.rb
|
72
|
+
- ruby/lib/zillabyte/harness/spout.rb
|
73
|
+
- ruby/lib/zillabyte/harness/topology.rb
|
74
|
+
- ruby/lib/zillabyte/harness/tuple.rb
|
75
|
+
- ruby/lib/zillabyte/harness.rb
|
76
|
+
- ruby/lib/zillabyte/version.rb
|
77
|
+
- ruby/lib/zillabyte.rb
|
78
|
+
- ruby/README.md
|
79
|
+
homepage: http://www.zillabyte.com
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- ruby/lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.0.7
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: The Official Zillabyte Gem
|
103
|
+
test_files: []
|