ruby-spark 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/Gemfile +47 -0
  4. data/Guardfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +185 -0
  7. data/Rakefile +35 -0
  8. data/TODO.md +7 -0
  9. data/benchmark/aggregate.rb +33 -0
  10. data/benchmark/bisect.rb +88 -0
  11. data/benchmark/custom_marshal.rb +94 -0
  12. data/benchmark/digest.rb +150 -0
  13. data/benchmark/enumerator.rb +88 -0
  14. data/benchmark/performance/prepare.sh +18 -0
  15. data/benchmark/performance/python.py +156 -0
  16. data/benchmark/performance/r.r +69 -0
  17. data/benchmark/performance/ruby.rb +167 -0
  18. data/benchmark/performance/run-all.sh +160 -0
  19. data/benchmark/performance/scala.scala +181 -0
  20. data/benchmark/serializer.rb +82 -0
  21. data/benchmark/sort.rb +43 -0
  22. data/benchmark/sort2.rb +164 -0
  23. data/benchmark/take.rb +28 -0
  24. data/bin/ruby-spark +8 -0
  25. data/example/pi.rb +28 -0
  26. data/ext/ruby_c/extconf.rb +3 -0
  27. data/ext/ruby_c/murmur.c +158 -0
  28. data/ext/ruby_c/murmur.h +9 -0
  29. data/ext/ruby_c/ruby-spark.c +18 -0
  30. data/ext/ruby_java/Digest.java +36 -0
  31. data/ext/ruby_java/Murmur2.java +98 -0
  32. data/ext/ruby_java/RubySparkExtService.java +28 -0
  33. data/ext/ruby_java/extconf.rb +3 -0
  34. data/ext/spark/build.sbt +73 -0
  35. data/ext/spark/project/plugins.sbt +9 -0
  36. data/ext/spark/sbt/sbt +34 -0
  37. data/ext/spark/src/main/scala/Exec.scala +91 -0
  38. data/ext/spark/src/main/scala/MLLibAPI.scala +4 -0
  39. data/ext/spark/src/main/scala/Marshal.scala +52 -0
  40. data/ext/spark/src/main/scala/MarshalDump.scala +113 -0
  41. data/ext/spark/src/main/scala/MarshalLoad.scala +220 -0
  42. data/ext/spark/src/main/scala/RubyAccumulatorParam.scala +69 -0
  43. data/ext/spark/src/main/scala/RubyBroadcast.scala +13 -0
  44. data/ext/spark/src/main/scala/RubyConstant.scala +13 -0
  45. data/ext/spark/src/main/scala/RubyMLLibAPI.scala +55 -0
  46. data/ext/spark/src/main/scala/RubyMLLibUtilAPI.scala +21 -0
  47. data/ext/spark/src/main/scala/RubyPage.scala +34 -0
  48. data/ext/spark/src/main/scala/RubyRDD.scala +364 -0
  49. data/ext/spark/src/main/scala/RubySerializer.scala +14 -0
  50. data/ext/spark/src/main/scala/RubyTab.scala +11 -0
  51. data/ext/spark/src/main/scala/RubyUtils.scala +15 -0
  52. data/ext/spark/src/main/scala/RubyWorker.scala +257 -0
  53. data/ext/spark/src/test/scala/MarshalSpec.scala +84 -0
  54. data/lib/ruby-spark.rb +1 -0
  55. data/lib/spark.rb +198 -0
  56. data/lib/spark/accumulator.rb +260 -0
  57. data/lib/spark/broadcast.rb +98 -0
  58. data/lib/spark/build.rb +43 -0
  59. data/lib/spark/cli.rb +169 -0
  60. data/lib/spark/command.rb +86 -0
  61. data/lib/spark/command/base.rb +154 -0
  62. data/lib/spark/command/basic.rb +345 -0
  63. data/lib/spark/command/pair.rb +124 -0
  64. data/lib/spark/command/sort.rb +51 -0
  65. data/lib/spark/command/statistic.rb +144 -0
  66. data/lib/spark/command_builder.rb +141 -0
  67. data/lib/spark/command_validator.rb +34 -0
  68. data/lib/spark/config.rb +244 -0
  69. data/lib/spark/constant.rb +14 -0
  70. data/lib/spark/context.rb +304 -0
  71. data/lib/spark/error.rb +50 -0
  72. data/lib/spark/ext/hash.rb +41 -0
  73. data/lib/spark/ext/integer.rb +25 -0
  74. data/lib/spark/ext/io.rb +57 -0
  75. data/lib/spark/ext/ip_socket.rb +29 -0
  76. data/lib/spark/ext/module.rb +58 -0
  77. data/lib/spark/ext/object.rb +24 -0
  78. data/lib/spark/ext/string.rb +24 -0
  79. data/lib/spark/helper.rb +10 -0
  80. data/lib/spark/helper/logger.rb +40 -0
  81. data/lib/spark/helper/parser.rb +85 -0
  82. data/lib/spark/helper/serialize.rb +71 -0
  83. data/lib/spark/helper/statistic.rb +93 -0
  84. data/lib/spark/helper/system.rb +42 -0
  85. data/lib/spark/java_bridge.rb +19 -0
  86. data/lib/spark/java_bridge/base.rb +203 -0
  87. data/lib/spark/java_bridge/jruby.rb +23 -0
  88. data/lib/spark/java_bridge/rjb.rb +41 -0
  89. data/lib/spark/logger.rb +76 -0
  90. data/lib/spark/mllib.rb +100 -0
  91. data/lib/spark/mllib/classification/common.rb +31 -0
  92. data/lib/spark/mllib/classification/logistic_regression.rb +223 -0
  93. data/lib/spark/mllib/classification/naive_bayes.rb +97 -0
  94. data/lib/spark/mllib/classification/svm.rb +135 -0
  95. data/lib/spark/mllib/clustering/gaussian_mixture.rb +82 -0
  96. data/lib/spark/mllib/clustering/kmeans.rb +118 -0
  97. data/lib/spark/mllib/matrix.rb +120 -0
  98. data/lib/spark/mllib/regression/common.rb +73 -0
  99. data/lib/spark/mllib/regression/labeled_point.rb +41 -0
  100. data/lib/spark/mllib/regression/lasso.rb +100 -0
  101. data/lib/spark/mllib/regression/linear.rb +124 -0
  102. data/lib/spark/mllib/regression/ridge.rb +97 -0
  103. data/lib/spark/mllib/ruby_matrix/matrix_adapter.rb +53 -0
  104. data/lib/spark/mllib/ruby_matrix/vector_adapter.rb +57 -0
  105. data/lib/spark/mllib/stat/distribution.rb +12 -0
  106. data/lib/spark/mllib/vector.rb +185 -0
  107. data/lib/spark/rdd.rb +1328 -0
  108. data/lib/spark/sampler.rb +92 -0
  109. data/lib/spark/serializer.rb +24 -0
  110. data/lib/spark/serializer/base.rb +170 -0
  111. data/lib/spark/serializer/cartesian.rb +37 -0
  112. data/lib/spark/serializer/marshal.rb +19 -0
  113. data/lib/spark/serializer/message_pack.rb +25 -0
  114. data/lib/spark/serializer/oj.rb +25 -0
  115. data/lib/spark/serializer/pair.rb +27 -0
  116. data/lib/spark/serializer/utf8.rb +25 -0
  117. data/lib/spark/sort.rb +189 -0
  118. data/lib/spark/stat_counter.rb +125 -0
  119. data/lib/spark/storage_level.rb +39 -0
  120. data/lib/spark/version.rb +3 -0
  121. data/lib/spark/worker/master.rb +144 -0
  122. data/lib/spark/worker/spark_files.rb +15 -0
  123. data/lib/spark/worker/worker.rb +197 -0
  124. data/ruby-spark.gemspec +36 -0
  125. data/spec/generator.rb +37 -0
  126. data/spec/inputs/lorem_300.txt +316 -0
  127. data/spec/inputs/numbers/1.txt +50 -0
  128. data/spec/inputs/numbers/10.txt +50 -0
  129. data/spec/inputs/numbers/11.txt +50 -0
  130. data/spec/inputs/numbers/12.txt +50 -0
  131. data/spec/inputs/numbers/13.txt +50 -0
  132. data/spec/inputs/numbers/14.txt +50 -0
  133. data/spec/inputs/numbers/15.txt +50 -0
  134. data/spec/inputs/numbers/16.txt +50 -0
  135. data/spec/inputs/numbers/17.txt +50 -0
  136. data/spec/inputs/numbers/18.txt +50 -0
  137. data/spec/inputs/numbers/19.txt +50 -0
  138. data/spec/inputs/numbers/2.txt +50 -0
  139. data/spec/inputs/numbers/20.txt +50 -0
  140. data/spec/inputs/numbers/3.txt +50 -0
  141. data/spec/inputs/numbers/4.txt +50 -0
  142. data/spec/inputs/numbers/5.txt +50 -0
  143. data/spec/inputs/numbers/6.txt +50 -0
  144. data/spec/inputs/numbers/7.txt +50 -0
  145. data/spec/inputs/numbers/8.txt +50 -0
  146. data/spec/inputs/numbers/9.txt +50 -0
  147. data/spec/inputs/numbers_0_100.txt +101 -0
  148. data/spec/inputs/numbers_1_100.txt +100 -0
  149. data/spec/lib/collect_spec.rb +42 -0
  150. data/spec/lib/command_spec.rb +68 -0
  151. data/spec/lib/config_spec.rb +64 -0
  152. data/spec/lib/context_spec.rb +163 -0
  153. data/spec/lib/ext_spec.rb +72 -0
  154. data/spec/lib/external_apps_spec.rb +45 -0
  155. data/spec/lib/filter_spec.rb +80 -0
  156. data/spec/lib/flat_map_spec.rb +100 -0
  157. data/spec/lib/group_spec.rb +109 -0
  158. data/spec/lib/helper_spec.rb +19 -0
  159. data/spec/lib/key_spec.rb +41 -0
  160. data/spec/lib/manipulation_spec.rb +114 -0
  161. data/spec/lib/map_partitions_spec.rb +87 -0
  162. data/spec/lib/map_spec.rb +91 -0
  163. data/spec/lib/mllib/classification_spec.rb +54 -0
  164. data/spec/lib/mllib/clustering_spec.rb +35 -0
  165. data/spec/lib/mllib/matrix_spec.rb +32 -0
  166. data/spec/lib/mllib/regression_spec.rb +116 -0
  167. data/spec/lib/mllib/vector_spec.rb +77 -0
  168. data/spec/lib/reduce_by_key_spec.rb +118 -0
  169. data/spec/lib/reduce_spec.rb +131 -0
  170. data/spec/lib/sample_spec.rb +46 -0
  171. data/spec/lib/serializer_spec.rb +13 -0
  172. data/spec/lib/sort_spec.rb +58 -0
  173. data/spec/lib/statistic_spec.rb +168 -0
  174. data/spec/lib/whole_text_files_spec.rb +33 -0
  175. data/spec/spec_helper.rb +39 -0
  176. metadata +301 -0
@@ -0,0 +1,46 @@
1
+ require "spec_helper"
2
+
3
+ # Sample method can not be tested because of random generator
4
+ # Just test it for raising error
5
+
6
+ RSpec::shared_examples "a sampler" do |workers|
7
+ context "with #{workers || 'default'} worker" do
8
+
9
+ context ".sample" do
10
+ it "with replacement" do
11
+ rdd2 = rdd(workers).sample(true, rand)
12
+ expect { rdd2.collect }.to_not raise_error
13
+ end
14
+
15
+ it "without replacement" do
16
+ rdd2 = rdd(workers).sample(false, rand)
17
+ expect { rdd2.collect }.to_not raise_error
18
+ end
19
+ end
20
+
21
+ context ".take_sample" do
22
+ it "with replacement" do
23
+ size = rand(10..999)
24
+ expect(rdd(workers).take_sample(true, size).size).to eql(size)
25
+ end
26
+
27
+ it "without replacement" do
28
+ size = rand(10..999)
29
+ expect(rdd(workers).take_sample(false, size).size).to eql(size)
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+ RSpec::describe "Spark::RDD" do
37
+ let(:numbers) { Generator.numbers(1000) }
38
+
39
+ def rdd(workers)
40
+ $sc.parallelize(numbers, workers)
41
+ end
42
+
43
+ it_behaves_like "a sampler", nil
44
+ it_behaves_like "a sampler", 1
45
+ it_behaves_like "a sampler", rand(2..10)
46
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ RSpec::describe Spark::Serializer do
4
+
5
+ it ".get" do
6
+ expect(described_class.get(nil)).to eql(nil)
7
+ expect(described_class.get("MARSHAL")).to eql(nil)
8
+ expect(described_class.get("Marshal")).to eql(described_class::Marshal)
9
+ expect(described_class.get("marshal")).to eql(described_class::Marshal)
10
+ expect(described_class.get("message_pack")).to eql(described_class::MessagePack)
11
+ end
12
+
13
+ end
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+
3
+ RSpec::shared_examples "a sorting" do |workers|
4
+ it "with #{workers || 'default'} worker" do
5
+ rdd2 = rdd(workers)
6
+
7
+ rdd2 = rdd2.flat_map(split)
8
+ result = lines.flat_map(&split)
9
+
10
+ # Sort by self
11
+ rdd3 = rdd2.map(map).sort_by_key
12
+ result2 = result.map(&map).sort_by{|(key, _)| key}
13
+
14
+ expect(rdd3.collect).to eql(result2)
15
+
16
+ # Sort by len
17
+ rdd3 = rdd2.map(len_map).sort_by_key
18
+ result2 = result.map(&len_map).sort_by{|(key, _)| key}
19
+
20
+ expect(rdd3.collect).to eql(result2)
21
+ end
22
+ end
23
+
24
+
25
+ RSpec::describe "Spark::RDD" do
26
+ let(:split) { lambda{|x| x.split} }
27
+ let(:map) { lambda{|x| [x.to_s, 1]} }
28
+ let(:len_map) { lambda{|x| [x.size, x]} }
29
+
30
+ context "throught parallelize" do
31
+ context ".map" do
32
+ let(:lines) { Generator.lines }
33
+
34
+ def rdd(workers)
35
+ $sc.parallelize(lines, workers)
36
+ end
37
+
38
+ it_behaves_like "a sorting", nil
39
+ it_behaves_like "a sorting", 1
40
+ it_behaves_like "a sorting", rand(2..10)
41
+ end
42
+ end
43
+
44
+ context "throught text_file" do
45
+ context ".map" do
46
+ let(:file) { File.join("spec", "inputs", "lorem_300.txt") }
47
+ let(:lines) { File.readlines(file).map(&:strip) }
48
+
49
+ def rdd(workers)
50
+ $sc.text_file(file, workers)
51
+ end
52
+
53
+ it_behaves_like "a sorting", nil
54
+ it_behaves_like "a sorting", 1
55
+ it_behaves_like "a sorting", rand(2..10)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,168 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec::shared_examples 'a stats' do |workers|
4
+ let(:numbers) { [1.0, 1.0, 2.0, 3.0, 5.0, 8.0] }
5
+
6
+ context "with #{workers || 'default'} worker" do
7
+ it 'stats class' do
8
+ stats = $sc.parallelize(numbers, workers).stats
9
+
10
+ expect(stats.sum).to be_within(0.1).of(20)
11
+ expect(stats.mean).to be_within(0.1).of(20/6.0)
12
+ expect(stats.max).to be_within(0.1).of(8.0)
13
+ expect(stats.min).to be_within(0.1).of(1.0)
14
+ expect(stats.variance).to be_within(0.1).of(6.22222)
15
+ expect(stats.sample_variance).to be_within(0.1).of(7.46667)
16
+ expect(stats.stdev).to be_within(0.1).of(2.49444)
17
+ expect(stats.sample_stdev).to be_within(0.1).of(2.73252)
18
+ end
19
+
20
+ it 'rdd methods' do
21
+ rdd = $sc.parallelize([1, 2, 3], workers)
22
+
23
+ expect(rdd.mean).to be_within(0.1).of(2.0)
24
+ expect(rdd.variance).to be_within(0.1).of(0.666)
25
+ expect(rdd.stdev).to be_within(0.1).of(0.816)
26
+ expect(rdd.sample_stdev).to be_within(0.1).of(1.0)
27
+ expect(rdd.sample_variance).to be_within(0.1).of(1.0)
28
+ end
29
+ end
30
+ end
31
+
32
+ RSpec::shared_examples 'a histogram' do |workers|
33
+
34
+ context "with #{workers || 'default'} worker" do
35
+ it 'empty' do
36
+ rdd = $sc.parallelize([], workers, batch_size: 1)
37
+
38
+ expect( rdd.histogram([0, 10])[1] ).to eq([0])
39
+ expect( rdd.histogram([0, 4, 10])[1] ).to eq([0, 0])
40
+ end
41
+
42
+ it 'validation' do
43
+ rdd = $sc.parallelize([], workers, batch_size: 1)
44
+ expect { rdd.histogram(0) }.to raise_error(ArgumentError)
45
+ end
46
+
47
+ it 'double' do
48
+ rdd = $sc.parallelize([1.0, 2.0, 3.0, 4.0], workers, batch_size: 1)
49
+ buckets, counts = rdd.histogram(2)
50
+
51
+ expect(buckets).to eq([1.0, 2.5, 4.0])
52
+ expect(counts).to eq([2, 2])
53
+ end
54
+
55
+ it 'out of range' do
56
+ rdd = $sc.parallelize([10.01, -0.01], workers, batch_size: 1)
57
+
58
+ expect( rdd.histogram([0, 10])[1] ).to eq([0])
59
+ expect( rdd.histogram([0, 4, 10])[1] ).to eq([0, 0])
60
+ end
61
+
62
+ it 'in range with one bucket' do
63
+ rdd = $sc.parallelize([1, 2, 3, 4], workers, batch_size: 1)
64
+
65
+ expect( rdd.histogram([0, 10])[1] ).to eq([4])
66
+ expect( rdd.histogram([0, 4, 10])[1] ).to eq([3, 1])
67
+ end
68
+
69
+ it 'in range with one bucket exact match' do
70
+ rdd = $sc.parallelize([1, 2, 3, 4], workers, batch_size: 1)
71
+ expect( rdd.histogram([1, 4])[1] ).to eq([4])
72
+ end
73
+
74
+ it 'out of range with two buckets' do
75
+ rdd = $sc.parallelize([10.01, -0.01], workers, batch_size: 1)
76
+ expect( rdd.histogram([0, 5, 10])[1] ).to eq([0, 0])
77
+ end
78
+
79
+ it 'out of range with two uneven buckets' do
80
+ rdd = $sc.parallelize([10.01, -0.01], workers, batch_size: 1)
81
+ expect( rdd.histogram([0, 4, 10])[1] ).to eq([0, 0])
82
+ end
83
+
84
+ it 'in range with two buckets' do
85
+ rdd = $sc.parallelize([1, 2, 3, 5, 6], workers, batch_size: 1)
86
+ expect( rdd.histogram([0, 5, 10])[1] ).to eq([3, 2])
87
+ end
88
+
89
+ it 'in range with two bucket and nil' do
90
+ rdd = $sc.parallelize([1, 2, 3, 5, 6, nil, Float::NAN], workers, batch_size: 1)
91
+ expect( rdd.histogram([0, 5, 10])[1] ).to eq([3, 2])
92
+ end
93
+
94
+ it 'in range with two uneven buckets' do
95
+ rdd = $sc.parallelize([1, 2, 3, 5, 6], workers, batch_size: 1)
96
+ expect( rdd.histogram([0, 5, 11])[1] ).to eq([3, 2])
97
+ end
98
+
99
+ it 'mixed range with two uneven buckets' do
100
+ rdd = $sc.parallelize([-0.01, 0.0, 1, 2, 3, 5, 6, 11.0, 11.01], workers, batch_size: 1)
101
+ expect( rdd.histogram([0, 5, 11])[1] ).to eq([4, 3])
102
+ end
103
+
104
+ it 'mixed range with four uneven buckets' do
105
+ rdd = $sc.parallelize([-0.01, 0.0, 1, 2, 3, 5, 6, 11.01, 12.0, 199.0, 200.0, 200.1], workers, batch_size: 1)
106
+ expect( rdd.histogram([0.0, 5.0, 11.0, 12.0, 200.0])[1] ).to eq([4, 2, 1, 3])
107
+ end
108
+
109
+ it 'mixed range with uneven buckets and NaN' do
110
+ rdd = $sc.parallelize([-0.01, 0.0, 1, 2, 3, 5, 6, 11.01, 12.0, 199.0, 200.0, 200.1, nil, Float::NAN], workers, batch_size: 1)
111
+ expect( rdd.histogram([0.0, 5.0, 11.0, 12.0, 200.0])[1] ).to eq([4, 2, 1, 3])
112
+ end
113
+
114
+ it 'out of range with infinite buckets' do
115
+ rdd = $sc.parallelize([10.01, -0.01, Float::NAN, Float::INFINITY], workers, batch_size: 1)
116
+ expect( rdd.histogram([-Float::INFINITY, 0, Float::INFINITY])[1] ).to eq([1, 1])
117
+ end
118
+
119
+ it 'without buckets' do
120
+ rdd = $sc.parallelize([1, 2, 3, 4], workers, batch_size: 1)
121
+ expect( rdd.histogram(1) ).to eq([[1, 4], [4]])
122
+ end
123
+
124
+ it 'without buckets single element' do
125
+ rdd = $sc.parallelize([1], workers, batch_size: 1)
126
+ expect( rdd.histogram(1) ).to eq([[1, 1], [1]])
127
+ end
128
+
129
+ it 'without bucket no range' do
130
+ rdd = $sc.parallelize([1, 1, 1, 1], workers, batch_size: 1)
131
+ expect( rdd.histogram(1) ).to eq([[1, 1], [4]])
132
+ end
133
+
134
+ it 'without buckets basic two' do
135
+ rdd = $sc.parallelize([1, 2, 3, 4], workers, batch_size: 1)
136
+ expect( rdd.histogram(2) ).to eq([[1, 2.5, 4], [2, 2]])
137
+ end
138
+
139
+ it 'without buckets with more requested than elements' do
140
+ rdd = $sc.parallelize([1, 2], workers, batch_size: 1)
141
+ buckets = [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0]
142
+ hist = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1]
143
+
144
+ expect( rdd.histogram(10) ).to eq([buckets, hist])
145
+ end
146
+
147
+ it 'string' do
148
+ rdd = $sc.parallelize(['ab', 'ac', 'b', 'bd', 'ef'], workers, batch_size: 1)
149
+
150
+ expect( rdd.histogram(['a', 'b', 'c'])[1] ).to eq([2, 2])
151
+ expect( rdd.histogram(1) ).to eq([['ab', 'ef'], [5]])
152
+ expect { rdd.histogram(2) }.to raise_error(Spark::RDDError)
153
+ end
154
+
155
+ end
156
+ end
157
+
158
+ RSpec::describe Spark::RDD do
159
+ context '.stats' do
160
+ it_behaves_like 'a stats', 1
161
+ it_behaves_like 'a stats', rand(2..5)
162
+ end
163
+
164
+ context '.histogram' do
165
+ it_behaves_like 'a histogram', 1
166
+ it_behaves_like 'a histogram', rand(2..5)
167
+ end
168
+ end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ RSpec::shared_examples "a whole_text_files" do |workers|
4
+ it "with #{workers || 'default'} worker" do
5
+ rdd2 = rdd(workers).map(get_numbers)
6
+ result = files.size
7
+
8
+ expect(rdd2.collect.size).to eql(result)
9
+
10
+ rdd3 = rdd(workers)
11
+ rdd3 = rdd3.flat_map(get_numbers)
12
+
13
+ result = 0
14
+ files.each{|f| result += File.read(f).split.map(&:to_i).reduce(:+)}
15
+
16
+ expect(rdd3.sum).to eql(result)
17
+ end
18
+ end
19
+
20
+ RSpec::describe "Spark::Context" do
21
+ let(:get_numbers) { lambda{|file, content| content.split.map(&:to_i)} }
22
+
23
+ let(:dir) { File.join("spec", "inputs", "numbers") }
24
+ let(:files) { Dir.glob(File.join(dir, "*")) }
25
+
26
+ def rdd(workers)
27
+ $sc.whole_text_files(dir, workers)
28
+ end
29
+
30
+ it_behaves_like "a whole_text_files", nil
31
+ it_behaves_like "a whole_text_files", 1
32
+ it_behaves_like "a whole_text_files", rand(2..10)
33
+ end
@@ -0,0 +1,39 @@
1
+ # require 'simplecov'
2
+ # SimpleCov.start
3
+
4
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
+ require 'ruby-spark'
6
+ require 'generator'
7
+
8
+ # Loading
9
+ Spark.load_lib
10
+ Spark.jb.load_test
11
+ Spark::Mllib.import
12
+
13
+ # Keep it on method because its called from config test
14
+ def spark_start
15
+ Spark.logger.disable
16
+ Spark.config do
17
+ set 'spark.ruby.parallelize_strategy', 'deep_copy'
18
+ set 'spark.ruby.batch_size', 100
19
+ end
20
+ Spark.start
21
+ $sc = Spark.context
22
+ end
23
+
24
+ def windows?
25
+ RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
26
+ end
27
+
28
+ RSpec.configure do |config|
29
+ config.default_formatter = 'doc'
30
+ config.color = true
31
+ config.tty = true
32
+
33
+ config.before(:suite) do
34
+ spark_start
35
+ end
36
+ config.after(:suite) do
37
+ Spark.stop
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,301 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-spark
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ondřej Moravčík
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-04 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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
+ description: ''
42
+ email:
43
+ - moravcik.ondrej@gmail.com
44
+ executables:
45
+ - ruby-spark
46
+ extensions:
47
+ - ext/ruby_c/extconf.rb
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - Guardfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - TODO.md
57
+ - benchmark/aggregate.rb
58
+ - benchmark/bisect.rb
59
+ - benchmark/custom_marshal.rb
60
+ - benchmark/digest.rb
61
+ - benchmark/enumerator.rb
62
+ - benchmark/performance/prepare.sh
63
+ - benchmark/performance/python.py
64
+ - benchmark/performance/r.r
65
+ - benchmark/performance/ruby.rb
66
+ - benchmark/performance/run-all.sh
67
+ - benchmark/performance/scala.scala
68
+ - benchmark/serializer.rb
69
+ - benchmark/sort.rb
70
+ - benchmark/sort2.rb
71
+ - benchmark/take.rb
72
+ - bin/ruby-spark
73
+ - example/pi.rb
74
+ - ext/ruby_c/extconf.rb
75
+ - ext/ruby_c/murmur.c
76
+ - ext/ruby_c/murmur.h
77
+ - ext/ruby_c/ruby-spark.c
78
+ - ext/ruby_java/Digest.java
79
+ - ext/ruby_java/Murmur2.java
80
+ - ext/ruby_java/RubySparkExtService.java
81
+ - ext/ruby_java/extconf.rb
82
+ - ext/spark/build.sbt
83
+ - ext/spark/project/plugins.sbt
84
+ - ext/spark/sbt/sbt
85
+ - ext/spark/src/main/scala/Exec.scala
86
+ - ext/spark/src/main/scala/MLLibAPI.scala
87
+ - ext/spark/src/main/scala/Marshal.scala
88
+ - ext/spark/src/main/scala/MarshalDump.scala
89
+ - ext/spark/src/main/scala/MarshalLoad.scala
90
+ - ext/spark/src/main/scala/RubyAccumulatorParam.scala
91
+ - ext/spark/src/main/scala/RubyBroadcast.scala
92
+ - ext/spark/src/main/scala/RubyConstant.scala
93
+ - ext/spark/src/main/scala/RubyMLLibAPI.scala
94
+ - ext/spark/src/main/scala/RubyMLLibUtilAPI.scala
95
+ - ext/spark/src/main/scala/RubyPage.scala
96
+ - ext/spark/src/main/scala/RubyRDD.scala
97
+ - ext/spark/src/main/scala/RubySerializer.scala
98
+ - ext/spark/src/main/scala/RubyTab.scala
99
+ - ext/spark/src/main/scala/RubyUtils.scala
100
+ - ext/spark/src/main/scala/RubyWorker.scala
101
+ - ext/spark/src/test/scala/MarshalSpec.scala
102
+ - lib/ruby-spark.rb
103
+ - lib/spark.rb
104
+ - lib/spark/accumulator.rb
105
+ - lib/spark/broadcast.rb
106
+ - lib/spark/build.rb
107
+ - lib/spark/cli.rb
108
+ - lib/spark/command.rb
109
+ - lib/spark/command/base.rb
110
+ - lib/spark/command/basic.rb
111
+ - lib/spark/command/pair.rb
112
+ - lib/spark/command/sort.rb
113
+ - lib/spark/command/statistic.rb
114
+ - lib/spark/command_builder.rb
115
+ - lib/spark/command_validator.rb
116
+ - lib/spark/config.rb
117
+ - lib/spark/constant.rb
118
+ - lib/spark/context.rb
119
+ - lib/spark/error.rb
120
+ - lib/spark/ext/hash.rb
121
+ - lib/spark/ext/integer.rb
122
+ - lib/spark/ext/io.rb
123
+ - lib/spark/ext/ip_socket.rb
124
+ - lib/spark/ext/module.rb
125
+ - lib/spark/ext/object.rb
126
+ - lib/spark/ext/string.rb
127
+ - lib/spark/helper.rb
128
+ - lib/spark/helper/logger.rb
129
+ - lib/spark/helper/parser.rb
130
+ - lib/spark/helper/serialize.rb
131
+ - lib/spark/helper/statistic.rb
132
+ - lib/spark/helper/system.rb
133
+ - lib/spark/java_bridge.rb
134
+ - lib/spark/java_bridge/base.rb
135
+ - lib/spark/java_bridge/jruby.rb
136
+ - lib/spark/java_bridge/rjb.rb
137
+ - lib/spark/logger.rb
138
+ - lib/spark/mllib.rb
139
+ - lib/spark/mllib/classification/common.rb
140
+ - lib/spark/mllib/classification/logistic_regression.rb
141
+ - lib/spark/mllib/classification/naive_bayes.rb
142
+ - lib/spark/mllib/classification/svm.rb
143
+ - lib/spark/mllib/clustering/gaussian_mixture.rb
144
+ - lib/spark/mllib/clustering/kmeans.rb
145
+ - lib/spark/mllib/matrix.rb
146
+ - lib/spark/mllib/regression/common.rb
147
+ - lib/spark/mllib/regression/labeled_point.rb
148
+ - lib/spark/mllib/regression/lasso.rb
149
+ - lib/spark/mllib/regression/linear.rb
150
+ - lib/spark/mllib/regression/ridge.rb
151
+ - lib/spark/mllib/ruby_matrix/matrix_adapter.rb
152
+ - lib/spark/mllib/ruby_matrix/vector_adapter.rb
153
+ - lib/spark/mllib/stat/distribution.rb
154
+ - lib/spark/mllib/vector.rb
155
+ - lib/spark/rdd.rb
156
+ - lib/spark/sampler.rb
157
+ - lib/spark/serializer.rb
158
+ - lib/spark/serializer/base.rb
159
+ - lib/spark/serializer/cartesian.rb
160
+ - lib/spark/serializer/marshal.rb
161
+ - lib/spark/serializer/message_pack.rb
162
+ - lib/spark/serializer/oj.rb
163
+ - lib/spark/serializer/pair.rb
164
+ - lib/spark/serializer/utf8.rb
165
+ - lib/spark/sort.rb
166
+ - lib/spark/stat_counter.rb
167
+ - lib/spark/storage_level.rb
168
+ - lib/spark/version.rb
169
+ - lib/spark/worker/master.rb
170
+ - lib/spark/worker/spark_files.rb
171
+ - lib/spark/worker/worker.rb
172
+ - ruby-spark.gemspec
173
+ - spec/generator.rb
174
+ - spec/inputs/lorem_300.txt
175
+ - spec/inputs/numbers/1.txt
176
+ - spec/inputs/numbers/10.txt
177
+ - spec/inputs/numbers/11.txt
178
+ - spec/inputs/numbers/12.txt
179
+ - spec/inputs/numbers/13.txt
180
+ - spec/inputs/numbers/14.txt
181
+ - spec/inputs/numbers/15.txt
182
+ - spec/inputs/numbers/16.txt
183
+ - spec/inputs/numbers/17.txt
184
+ - spec/inputs/numbers/18.txt
185
+ - spec/inputs/numbers/19.txt
186
+ - spec/inputs/numbers/2.txt
187
+ - spec/inputs/numbers/20.txt
188
+ - spec/inputs/numbers/3.txt
189
+ - spec/inputs/numbers/4.txt
190
+ - spec/inputs/numbers/5.txt
191
+ - spec/inputs/numbers/6.txt
192
+ - spec/inputs/numbers/7.txt
193
+ - spec/inputs/numbers/8.txt
194
+ - spec/inputs/numbers/9.txt
195
+ - spec/inputs/numbers_0_100.txt
196
+ - spec/inputs/numbers_1_100.txt
197
+ - spec/lib/collect_spec.rb
198
+ - spec/lib/command_spec.rb
199
+ - spec/lib/config_spec.rb
200
+ - spec/lib/context_spec.rb
201
+ - spec/lib/ext_spec.rb
202
+ - spec/lib/external_apps_spec.rb
203
+ - spec/lib/filter_spec.rb
204
+ - spec/lib/flat_map_spec.rb
205
+ - spec/lib/group_spec.rb
206
+ - spec/lib/helper_spec.rb
207
+ - spec/lib/key_spec.rb
208
+ - spec/lib/manipulation_spec.rb
209
+ - spec/lib/map_partitions_spec.rb
210
+ - spec/lib/map_spec.rb
211
+ - spec/lib/mllib/classification_spec.rb
212
+ - spec/lib/mllib/clustering_spec.rb
213
+ - spec/lib/mllib/matrix_spec.rb
214
+ - spec/lib/mllib/regression_spec.rb
215
+ - spec/lib/mllib/vector_spec.rb
216
+ - spec/lib/reduce_by_key_spec.rb
217
+ - spec/lib/reduce_spec.rb
218
+ - spec/lib/sample_spec.rb
219
+ - spec/lib/serializer_spec.rb
220
+ - spec/lib/sort_spec.rb
221
+ - spec/lib/statistic_spec.rb
222
+ - spec/lib/whole_text_files_spec.rb
223
+ - spec/spec_helper.rb
224
+ homepage: ''
225
+ licenses:
226
+ - MIT
227
+ metadata: {}
228
+ post_install_message:
229
+ rdoc_options: []
230
+ require_paths:
231
+ - lib
232
+ required_ruby_version: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '2.0'
237
+ required_rubygems_version: !ruby/object:Gem::Requirement
238
+ requirements:
239
+ - - ">="
240
+ - !ruby/object:Gem::Version
241
+ version: '0'
242
+ requirements:
243
+ - java, scala
244
+ rubyforge_project:
245
+ rubygems_version: 2.2.2
246
+ signing_key:
247
+ specification_version: 4
248
+ summary: Ruby wrapper for Spark
249
+ test_files:
250
+ - spec/generator.rb
251
+ - spec/inputs/lorem_300.txt
252
+ - spec/inputs/numbers/1.txt
253
+ - spec/inputs/numbers/10.txt
254
+ - spec/inputs/numbers/11.txt
255
+ - spec/inputs/numbers/12.txt
256
+ - spec/inputs/numbers/13.txt
257
+ - spec/inputs/numbers/14.txt
258
+ - spec/inputs/numbers/15.txt
259
+ - spec/inputs/numbers/16.txt
260
+ - spec/inputs/numbers/17.txt
261
+ - spec/inputs/numbers/18.txt
262
+ - spec/inputs/numbers/19.txt
263
+ - spec/inputs/numbers/2.txt
264
+ - spec/inputs/numbers/20.txt
265
+ - spec/inputs/numbers/3.txt
266
+ - spec/inputs/numbers/4.txt
267
+ - spec/inputs/numbers/5.txt
268
+ - spec/inputs/numbers/6.txt
269
+ - spec/inputs/numbers/7.txt
270
+ - spec/inputs/numbers/8.txt
271
+ - spec/inputs/numbers/9.txt
272
+ - spec/inputs/numbers_0_100.txt
273
+ - spec/inputs/numbers_1_100.txt
274
+ - spec/lib/collect_spec.rb
275
+ - spec/lib/command_spec.rb
276
+ - spec/lib/config_spec.rb
277
+ - spec/lib/context_spec.rb
278
+ - spec/lib/ext_spec.rb
279
+ - spec/lib/external_apps_spec.rb
280
+ - spec/lib/filter_spec.rb
281
+ - spec/lib/flat_map_spec.rb
282
+ - spec/lib/group_spec.rb
283
+ - spec/lib/helper_spec.rb
284
+ - spec/lib/key_spec.rb
285
+ - spec/lib/manipulation_spec.rb
286
+ - spec/lib/map_partitions_spec.rb
287
+ - spec/lib/map_spec.rb
288
+ - spec/lib/mllib/classification_spec.rb
289
+ - spec/lib/mllib/clustering_spec.rb
290
+ - spec/lib/mllib/matrix_spec.rb
291
+ - spec/lib/mllib/regression_spec.rb
292
+ - spec/lib/mllib/vector_spec.rb
293
+ - spec/lib/reduce_by_key_spec.rb
294
+ - spec/lib/reduce_spec.rb
295
+ - spec/lib/sample_spec.rb
296
+ - spec/lib/serializer_spec.rb
297
+ - spec/lib/sort_spec.rb
298
+ - spec/lib/statistic_spec.rb
299
+ - spec/lib/whole_text_files_spec.rb
300
+ - spec/spec_helper.rb
301
+ has_rdoc: