cascading.jruby 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +12 -0
- data/HACKING.md +12 -4
- data/History.txt +8 -0
- data/README.md +2 -2
- data/Rakefile +3 -2
- data/TODO +2 -2
- data/ivy.xml +25 -0
- data/ivysettings.xml +7 -0
- data/lib/cascading.rb +1 -1
- data/lib/cascading/aggregations.rb +190 -0
- data/lib/cascading/assembly.rb +138 -194
- data/lib/cascading/cascading.rb +8 -3
- data/lib/cascading/cascading_exception.rb +12 -10
- data/lib/cascading/flow.rb +3 -2
- data/lib/cascading/operations.rb +1 -23
- data/lib/cascading/scope.rb +27 -24
- data/lib/cascading/sub_assembly.rb +93 -0
- data/samples/copy.rb +3 -1
- data/samples/data/data_group_by.txt +7 -0
- data/samples/data/genealogy/names/dist.all.last +88799 -0
- data/samples/data/gutenberg/the_outline_of_science_vol_1 +12761 -0
- data/samples/group_by.rb +61 -0
- data/samples/logwordcount.rb +3 -1
- data/samples/scorenames.rb +2 -1
- data/samples/sub_assembly.rb +30 -0
- data/samples/union.rb +3 -1
- data/spec/scope_spec.rb +47 -66
- data/spec/spec_util.rb +4 -4
- data/tags +69 -44
- data/tasks/ant.rake +9 -5
- data/tasks/samples.rake +6 -0
- data/tasks/test.rake +1 -1
- data/test/mock_assemblies.rb +55 -0
- data/test/test_aggregations.rb +443 -0
- data/test/test_assembly.rb +437 -196
- data/test/test_exceptions.rb +3 -3
- data/test/test_local_execution.rb +168 -0
- data/test/test_operations.rb +0 -7
- metadata +23 -2
data/tasks/ant.rake
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
namespace :ant do
|
2
|
+
desc 'Retrieves Cascading and Hadoop jars and sets environment variables to point to them'
|
3
|
+
task :retrieve do
|
4
|
+
raise 'Ant retrieve failed' unless system('ant retrieve')
|
5
|
+
ENV['CASCADING_HOME'] = 'build/lib'
|
6
|
+
ENV['HADOOP_HOME'] = 'build/lib'
|
7
|
+
end
|
8
|
+
|
2
9
|
desc 'Builds Java source for inclusion in gem'
|
3
10
|
task :build do
|
4
|
-
|
5
|
-
raise "Ant build failed: #{stdout}" unless $? == 0
|
6
|
-
puts stdout
|
11
|
+
raise 'Ant build failed' unless system('ant build')
|
7
12
|
end
|
8
13
|
|
9
14
|
desc 'Cleans Java build files'
|
10
15
|
task :clean do
|
11
|
-
|
12
|
-
puts stdout
|
16
|
+
system('ant clean')
|
13
17
|
end
|
14
18
|
end
|
data/tasks/samples.rake
CHANGED
@@ -7,6 +7,12 @@ namespace :samples do
|
|
7
7
|
raise "#{sample} sample app failed" unless success
|
8
8
|
end
|
9
9
|
end
|
10
|
+
|
11
|
+
desc 'Remove sample outputs and build artifacts (also cleans specs)'
|
12
|
+
task :clean do
|
13
|
+
`rm -rf output`
|
14
|
+
`rm -rf build`
|
15
|
+
end
|
10
16
|
end
|
11
17
|
|
12
18
|
desc 'Alias to samples:run'
|
data/tasks/test.rake
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'cascading'
|
2
|
+
|
3
|
+
module MockAssemblies
|
4
|
+
def mock_assembly(&block)
|
5
|
+
assembly = nil
|
6
|
+
flow 'test' do
|
7
|
+
source 'test', tap('test/data/data1.txt')
|
8
|
+
assembly = assembly 'test', &block
|
9
|
+
sink 'test', tap('output/test_mock_assembly')
|
10
|
+
end
|
11
|
+
assembly
|
12
|
+
end
|
13
|
+
|
14
|
+
def mock_branched_assembly(&block)
|
15
|
+
assembly = nil
|
16
|
+
flow 'mock_branched_assembly' do
|
17
|
+
source 'data1', tap('test/data/data1.txt')
|
18
|
+
|
19
|
+
assembly 'data1' do
|
20
|
+
branch 'test1' do
|
21
|
+
pass
|
22
|
+
end
|
23
|
+
branch 'test2' do
|
24
|
+
pass
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
assembly = assembly 'test', &block
|
29
|
+
|
30
|
+
sink 'test', tap('output/test_mock_branched_assembly')
|
31
|
+
end
|
32
|
+
assembly
|
33
|
+
end
|
34
|
+
|
35
|
+
def mock_two_input_assembly(&block)
|
36
|
+
assembly = nil
|
37
|
+
flow 'mock_two_input_assembly' do
|
38
|
+
source 'test1', tap('test/data/data1.txt')
|
39
|
+
source 'test2', tap('test/data/data2.txt')
|
40
|
+
|
41
|
+
assembly 'test1' do
|
42
|
+
split 'line', :pattern => /[.,]*\s+/, :into => ['name', 'score1', 'score2', 'id'], :output => ['name', 'score1', 'score2', 'id']
|
43
|
+
end
|
44
|
+
|
45
|
+
assembly 'test2' do
|
46
|
+
split 'line', :pattern => /[.,]*\s+/, :into => ['name', 'id', 'town'], :output => ['name', 'id', 'town']
|
47
|
+
end
|
48
|
+
|
49
|
+
assembly = assembly 'test', &block
|
50
|
+
|
51
|
+
sink 'test', tap('output/test_mock_two_input_assembly')
|
52
|
+
end
|
53
|
+
assembly
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,443 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'cascading'
|
3
|
+
require 'cascading/sub_assembly'
|
4
|
+
|
5
|
+
require 'test/mock_assemblies'
|
6
|
+
|
7
|
+
class TC_Aggregations < Test::Unit::TestCase
|
8
|
+
include MockAssemblies
|
9
|
+
|
10
|
+
# first chosen because it does not have a corresponding AggregateBy
|
11
|
+
def test_create_group_by
|
12
|
+
group = nil
|
13
|
+
assembly = mock_assembly do
|
14
|
+
group = group_by 'line' do
|
15
|
+
first 'offset'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
20
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
21
|
+
assert assembly.tail_pipe.aggregator?
|
22
|
+
assert_equal Java::CascadingOperationAggregator::First, assembly.tail_pipe.aggregator.class
|
23
|
+
|
24
|
+
grouping_fields = group.key_selectors['test']
|
25
|
+
assert_equal ['line'], grouping_fields.to_a
|
26
|
+
|
27
|
+
assert_equal ['line', 'offset'], assembly.scope.values_fields.to_a
|
28
|
+
assert_equal ['line', 'offset'], assembly.scope.grouping_fields.to_a
|
29
|
+
|
30
|
+
assembly = mock_assembly do
|
31
|
+
group = group_by 'offset' do
|
32
|
+
first 'line'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
37
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
38
|
+
assert assembly.tail_pipe.aggregator?
|
39
|
+
assert_equal Java::CascadingOperationAggregator::First, assembly.tail_pipe.aggregator.class
|
40
|
+
|
41
|
+
grouping_fields = group.key_selectors['test']
|
42
|
+
assert_equal ['offset'], grouping_fields.to_a
|
43
|
+
|
44
|
+
assert_equal ['offset', 'line'], assembly.scope.values_fields.to_a
|
45
|
+
assert_equal ['offset', 'line'], assembly.scope.grouping_fields.to_a
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_create_group_by_aggregate_by
|
49
|
+
group = nil
|
50
|
+
assembly = mock_assembly do
|
51
|
+
group = group_by 'line' do
|
52
|
+
count
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# GroupBy replaced by SubAssembly, the tail of which is a Sum, not a Count
|
57
|
+
assert_equal SubAssembly, group.class
|
58
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
59
|
+
assert assembly.tail_pipe.aggregator?
|
60
|
+
assert_equal Java::CascadingOperationAggregator::Sum, assembly.tail_pipe.aggregator.class
|
61
|
+
|
62
|
+
assert_equal ['line', 'count'], assembly.scope.values_fields.to_a
|
63
|
+
assert_equal ['line', 'count'], assembly.scope.grouping_fields.to_a
|
64
|
+
|
65
|
+
assembly = mock_assembly do
|
66
|
+
group = group_by 'offset' do
|
67
|
+
count
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# GroupBy replaced by SubAssembly, the tail of which is a Sum, not a Count
|
72
|
+
assert_equal SubAssembly, group.class
|
73
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
74
|
+
assert assembly.tail_pipe.aggregator?
|
75
|
+
assert_equal Java::CascadingOperationAggregator::Sum, assembly.tail_pipe.aggregator.class
|
76
|
+
|
77
|
+
assert_equal ['offset', 'count'], assembly.scope.values_fields.to_a
|
78
|
+
assert_equal ['offset', 'count'], assembly.scope.grouping_fields.to_a
|
79
|
+
end
|
80
|
+
|
81
|
+
# min chosen because it does not have a corresponding AggregateBy
|
82
|
+
def test_create_group_by_many_fields
|
83
|
+
group = nil
|
84
|
+
assembly = mock_assembly do
|
85
|
+
group = group_by 'offset', 'line' do
|
86
|
+
min 'offset' => 'min_offset'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
91
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
92
|
+
assert assembly.tail_pipe.aggregator?
|
93
|
+
assert_equal Java::CascadingOperationAggregator::Min, assembly.tail_pipe.aggregator.class
|
94
|
+
|
95
|
+
grouping_fields = group.key_selectors['test']
|
96
|
+
assert_equal ['offset', 'line'], grouping_fields.to_a
|
97
|
+
|
98
|
+
assert_equal ['offset', 'line', 'min_offset'], assembly.scope.values_fields.to_a
|
99
|
+
assert_equal ['offset', 'line', 'min_offset'], assembly.scope.grouping_fields.to_a
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_create_group_by_aggregate_by_many_fields
|
103
|
+
group = nil
|
104
|
+
assembly = mock_assembly do
|
105
|
+
group = group_by 'offset', 'line' do
|
106
|
+
average 'offset' => 'avg_offset'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# GroupBy replaced by SubAssembly, the tail of which is an AverageFinal, not an Average
|
111
|
+
assert_equal SubAssembly, group.class
|
112
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
113
|
+
assert assembly.tail_pipe.aggregator?
|
114
|
+
assert_equal Java::CascadingPipeAssembly::AverageBy::AverageFinal, assembly.tail_pipe.aggregator.class
|
115
|
+
|
116
|
+
assert_equal ['offset', 'line', 'avg_offset'], assembly.scope.values_fields.to_a
|
117
|
+
assert_equal ['offset', 'line', 'avg_offset'], assembly.scope.grouping_fields.to_a
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_create_group_by_with_sort
|
121
|
+
group = nil
|
122
|
+
assembly = mock_assembly do
|
123
|
+
group = group_by 'offset', 'line', :sort_by => 'line' do
|
124
|
+
count
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# :sort_by invalidates AggregateBy optimization
|
129
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
130
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
131
|
+
assert assembly.tail_pipe.aggregator?
|
132
|
+
assert_equal Java::CascadingOperationAggregator::Count, assembly.tail_pipe.aggregator.class
|
133
|
+
|
134
|
+
assert group.is_sorted
|
135
|
+
assert !group.is_sort_reversed
|
136
|
+
|
137
|
+
grouping_fields = group.key_selectors['test']
|
138
|
+
sorting_fields = group.sorting_selectors['test']
|
139
|
+
assert_equal ['offset', 'line'], grouping_fields.to_a
|
140
|
+
assert_equal ['line'], sorting_fields.to_a
|
141
|
+
|
142
|
+
assert_equal ['offset', 'line', 'count'], assembly.scope.values_fields.to_a
|
143
|
+
assert_equal ['offset', 'line', 'count'], assembly.scope.grouping_fields.to_a
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_create_group_by_with_sort_reverse
|
147
|
+
group = nil
|
148
|
+
assembly = mock_assembly do
|
149
|
+
group = group_by 'offset', 'line', :sort_by => 'line', :reverse => true do
|
150
|
+
count
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# :sort_by invalidates AggregateBy optimization
|
155
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
156
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
157
|
+
assert assembly.tail_pipe.aggregator?
|
158
|
+
assert_equal Java::CascadingOperationAggregator::Count, assembly.tail_pipe.aggregator.class
|
159
|
+
|
160
|
+
assert group.is_sorted
|
161
|
+
assert group.is_sort_reversed
|
162
|
+
|
163
|
+
grouping_fields = group.key_selectors['test']
|
164
|
+
sorting_fields = group.sorting_selectors['test']
|
165
|
+
assert_equal ['offset', 'line'], grouping_fields.to_a
|
166
|
+
assert_equal ['line'], sorting_fields.to_a
|
167
|
+
|
168
|
+
assert_equal ['offset', 'line', 'count'], assembly.scope.values_fields.to_a
|
169
|
+
assert_equal ['offset', 'line', 'count'], assembly.scope.grouping_fields.to_a
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_create_group_by_reverse
|
173
|
+
group = nil
|
174
|
+
assembly = mock_assembly do
|
175
|
+
group = group_by 'offset', 'line', :reverse => true do
|
176
|
+
count
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# :reverse invalidates AggregateBy optimization
|
181
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
182
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
183
|
+
assert assembly.tail_pipe.aggregator?
|
184
|
+
assert_equal Java::CascadingOperationAggregator::Count, assembly.tail_pipe.aggregator.class
|
185
|
+
|
186
|
+
assert !group.is_sorted
|
187
|
+
assert group.is_sort_reversed
|
188
|
+
|
189
|
+
grouping_fields = group.key_selectors['test']
|
190
|
+
sorting_fields = group.sorting_selectors['test']
|
191
|
+
assert_equal ['offset', 'line'], grouping_fields.to_a
|
192
|
+
assert_nil sorting_fields
|
193
|
+
|
194
|
+
assert_equal ['offset', 'line', 'count'], assembly.scope.values_fields.to_a
|
195
|
+
assert_equal ['offset', 'line', 'count'], assembly.scope.grouping_fields.to_a
|
196
|
+
end
|
197
|
+
|
198
|
+
# first chosen because it does not have a corresponding AggregateBy
|
199
|
+
def test_create_union
|
200
|
+
group = nil
|
201
|
+
assembly = mock_branched_assembly do
|
202
|
+
group = union 'test1', 'test2', :on => 'line' do
|
203
|
+
first 'offset'
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
208
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
209
|
+
assert assembly.tail_pipe.aggregator?
|
210
|
+
assert_equal Java::CascadingOperationAggregator::First, assembly.tail_pipe.aggregator.class
|
211
|
+
|
212
|
+
left_grouping_fields = group.key_selectors['test1']
|
213
|
+
assert_equal ['line'], left_grouping_fields.to_a
|
214
|
+
|
215
|
+
right_grouping_fields = group.key_selectors['test2']
|
216
|
+
assert_equal ['line'], right_grouping_fields.to_a
|
217
|
+
|
218
|
+
assert_equal ['line', 'offset'], assembly.scope.values_fields.to_a
|
219
|
+
assert_equal ['line', 'offset'], assembly.scope.grouping_fields.to_a
|
220
|
+
|
221
|
+
assembly = mock_branched_assembly do
|
222
|
+
group = union 'test1', 'test2', :on => 'offset' do
|
223
|
+
first 'line'
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
228
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
229
|
+
assert assembly.tail_pipe.aggregator?
|
230
|
+
assert_equal Java::CascadingOperationAggregator::First, assembly.tail_pipe.aggregator.class
|
231
|
+
|
232
|
+
left_grouping_fields = group.key_selectors['test1']
|
233
|
+
assert_equal ['offset'], left_grouping_fields.to_a
|
234
|
+
right_grouping_fields = group.key_selectors['test2']
|
235
|
+
assert_equal ['offset'], right_grouping_fields.to_a
|
236
|
+
|
237
|
+
assert_equal ['offset', 'line'], assembly.scope.values_fields.to_a
|
238
|
+
assert_equal ['offset', 'line'], assembly.scope.grouping_fields.to_a
|
239
|
+
|
240
|
+
assembly = mock_branched_assembly do
|
241
|
+
group = union 'test1', 'test2' do
|
242
|
+
min 'offset' => 'min_offset'
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
247
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
248
|
+
assert assembly.tail_pipe.aggregator?
|
249
|
+
assert_equal Java::CascadingOperationAggregator::Min, assembly.tail_pipe.aggregator.class
|
250
|
+
|
251
|
+
left_grouping_fields = group.key_selectors['test1']
|
252
|
+
assert_equal ['offset'], left_grouping_fields.to_a
|
253
|
+
right_grouping_fields = group.key_selectors['test2']
|
254
|
+
assert_equal ['offset'], right_grouping_fields.to_a
|
255
|
+
|
256
|
+
assert_equal ['offset', 'min_offset'], assembly.scope.values_fields.to_a
|
257
|
+
assert_equal ['offset', 'min_offset'], assembly.scope.grouping_fields.to_a
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_create_union_aggregate_by
|
261
|
+
group = nil
|
262
|
+
assembly = mock_branched_assembly do
|
263
|
+
group = union 'test1', 'test2', :on => 'line' do
|
264
|
+
sum 'offset'
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
# GroupBy replaced by SubAssembly, the tail of which is a Sum
|
269
|
+
assert_equal SubAssembly, group.class
|
270
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
271
|
+
assert assembly.tail_pipe.aggregator?
|
272
|
+
assert_equal Java::CascadingOperationAggregator::Sum, assembly.tail_pipe.aggregator.class
|
273
|
+
|
274
|
+
assert_equal ['line', 'offset'], assembly.scope.values_fields.to_a
|
275
|
+
assert_equal ['line', 'offset'], assembly.scope.grouping_fields.to_a
|
276
|
+
|
277
|
+
assembly = mock_branched_assembly do
|
278
|
+
group = union 'test1', 'test2', :on => 'offset' do
|
279
|
+
sum :mapping => {'offset' => 'sum_offset'}, :type => :double
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
# GroupBy replaced by SubAssembly, the tail of which is a Sum
|
284
|
+
assert_equal SubAssembly, group.class
|
285
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
286
|
+
assert assembly.tail_pipe.aggregator?
|
287
|
+
assert_equal Java::CascadingOperationAggregator::Sum, assembly.tail_pipe.aggregator.class
|
288
|
+
|
289
|
+
assert_equal ['offset', 'sum_offset'], assembly.scope.values_fields.to_a
|
290
|
+
assert_equal ['offset', 'sum_offset'], assembly.scope.grouping_fields.to_a
|
291
|
+
|
292
|
+
assembly = mock_branched_assembly do
|
293
|
+
group = union 'test1', 'test2' do
|
294
|
+
sum :mapping => {'offset' => 'sum_offset'}
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
# GroupBy replaced by SubAssembly, the tail of which is a Sum
|
299
|
+
assert_equal SubAssembly, group.class
|
300
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
301
|
+
assert assembly.tail_pipe.aggregator?
|
302
|
+
assert_equal Java::CascadingOperationAggregator::Sum, assembly.tail_pipe.aggregator.class
|
303
|
+
|
304
|
+
assert_equal ['offset', 'sum_offset'], assembly.scope.values_fields.to_a
|
305
|
+
assert_equal ['offset', 'sum_offset'], assembly.scope.grouping_fields.to_a
|
306
|
+
end
|
307
|
+
|
308
|
+
# max chosen because it does not have a corresponding AggregateBy
|
309
|
+
def test_create_union_many_fields
|
310
|
+
group = nil
|
311
|
+
assembly = mock_branched_assembly do
|
312
|
+
group = union 'test1', 'test2', :on => ['offset', 'line'] do
|
313
|
+
max 'offset' => 'max_offset'
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
318
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
319
|
+
assert assembly.tail_pipe.aggregator?
|
320
|
+
assert_equal Java::CascadingOperationAggregator::Max, assembly.tail_pipe.aggregator.class
|
321
|
+
|
322
|
+
left_grouping_fields = group.key_selectors['test1']
|
323
|
+
assert_equal ['offset', 'line'], left_grouping_fields.to_a
|
324
|
+
|
325
|
+
right_grouping_fields = group.key_selectors['test2']
|
326
|
+
assert_equal ['offset', 'line'], right_grouping_fields.to_a
|
327
|
+
|
328
|
+
assert_equal ['offset', 'line', 'max_offset'], assembly.scope.values_fields.to_a
|
329
|
+
assert_equal ['offset', 'line', 'max_offset'], assembly.scope.grouping_fields.to_a
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_create_union_aggregate_by_many_fields
|
333
|
+
group = nil
|
334
|
+
assembly = mock_branched_assembly do
|
335
|
+
group = union 'test1', 'test2', :on => ['offset', 'line'] do
|
336
|
+
count
|
337
|
+
average 'offset' => 'avg_offset'
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
# GroupBy replaced by SubAssembly, the tail of which is an AverageFinal, not an Average
|
342
|
+
assert_equal SubAssembly, group.class
|
343
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
344
|
+
assert assembly.tail_pipe.aggregator?
|
345
|
+
assert_equal Java::CascadingPipeAssembly::AverageBy::AverageFinal, assembly.tail_pipe.aggregator.class
|
346
|
+
|
347
|
+
assert_equal ['offset', 'line', 'count', 'avg_offset'], assembly.scope.values_fields.to_a
|
348
|
+
assert_equal ['offset', 'line', 'count', 'avg_offset'], assembly.scope.grouping_fields.to_a
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_create_union_with_sort
|
352
|
+
group = nil
|
353
|
+
assembly = mock_branched_assembly do
|
354
|
+
group = union 'test1', 'test2', :on => ['offset', 'line'], :sort_by => 'line' do
|
355
|
+
count
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
# :sort_by invalidates AggregateBy optimization
|
360
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
361
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
362
|
+
assert assembly.tail_pipe.aggregator?
|
363
|
+
assert_equal Java::CascadingOperationAggregator::Count, assembly.tail_pipe.aggregator.class
|
364
|
+
|
365
|
+
assert group.is_sorted
|
366
|
+
assert !group.is_sort_reversed
|
367
|
+
|
368
|
+
left_grouping_fields = group.key_selectors['test1']
|
369
|
+
right_grouping_fields = group.key_selectors['test2']
|
370
|
+
left_sorting_fields = group.sorting_selectors['test1']
|
371
|
+
right_sorting_fields = group.sorting_selectors['test2']
|
372
|
+
|
373
|
+
assert_equal ['offset', 'line'], left_grouping_fields.to_a
|
374
|
+
assert_equal ['offset', 'line'], right_grouping_fields.to_a
|
375
|
+
assert_equal ['line'], left_sorting_fields.to_a
|
376
|
+
assert_equal ['line'], right_sorting_fields.to_a
|
377
|
+
|
378
|
+
assert_equal ['offset', 'line', 'count'], assembly.scope.values_fields.to_a
|
379
|
+
assert_equal ['offset', 'line', 'count'], assembly.scope.grouping_fields.to_a
|
380
|
+
end
|
381
|
+
|
382
|
+
def test_create_union_with_sort_reverse
|
383
|
+
group = nil
|
384
|
+
assembly = mock_branched_assembly do
|
385
|
+
group = union 'test1', 'test2', :on => ['offset', 'line'], :sort_by => 'line', :reverse => true do
|
386
|
+
count
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
# :sort_by invalidates AggregateBy optimization
|
391
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
392
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
393
|
+
assert assembly.tail_pipe.aggregator?
|
394
|
+
assert_equal Java::CascadingOperationAggregator::Count, assembly.tail_pipe.aggregator.class
|
395
|
+
|
396
|
+
assert group.is_sorted
|
397
|
+
assert group.is_sort_reversed
|
398
|
+
|
399
|
+
left_grouping_fields = group.key_selectors['test1']
|
400
|
+
right_grouping_fields = group.key_selectors['test2']
|
401
|
+
left_sorting_fields = group.sorting_selectors['test1']
|
402
|
+
right_sorting_fields = group.sorting_selectors['test2']
|
403
|
+
|
404
|
+
assert_equal ['offset', 'line'], left_grouping_fields.to_a
|
405
|
+
assert_equal ['offset', 'line'], right_grouping_fields.to_a
|
406
|
+
assert_equal ['line'], left_sorting_fields.to_a
|
407
|
+
assert_equal ['line'], right_sorting_fields.to_a
|
408
|
+
|
409
|
+
assert_equal ['offset', 'line', 'count'], assembly.scope.values_fields.to_a
|
410
|
+
assert_equal ['offset', 'line', 'count'], assembly.scope.grouping_fields.to_a
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_create_union_reverse
|
414
|
+
group = nil
|
415
|
+
assembly = mock_branched_assembly do
|
416
|
+
group = union 'test1', 'test2', :on => ['offset', 'line'], :reverse => true do
|
417
|
+
count
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
# :reverse invalidates AggregateBy optimization
|
422
|
+
assert_equal Java::CascadingPipe::GroupBy, group.class
|
423
|
+
assert_equal Java::CascadingPipe::Every, assembly.tail_pipe.class
|
424
|
+
assert assembly.tail_pipe.aggregator?
|
425
|
+
assert_equal Java::CascadingOperationAggregator::Count, assembly.tail_pipe.aggregator.class
|
426
|
+
|
427
|
+
assert group.is_sorted # FIXME: Missing constructor in wip-255
|
428
|
+
assert group.is_sort_reversed
|
429
|
+
|
430
|
+
left_grouping_fields = group.key_selectors['test1']
|
431
|
+
right_grouping_fields = group.key_selectors['test2']
|
432
|
+
left_sorting_fields = group.sorting_selectors['test1']
|
433
|
+
right_sorting_fields = group.sorting_selectors['test2']
|
434
|
+
|
435
|
+
assert_equal ['offset', 'line'], left_grouping_fields.to_a
|
436
|
+
assert_equal ['offset', 'line'], right_grouping_fields.to_a
|
437
|
+
assert_equal ['offset', 'line'], left_sorting_fields.to_a # FIXME: Missing constructor in wip-255
|
438
|
+
assert_equal ['offset', 'line'], right_sorting_fields.to_a # FIXME: Missing constructor in wip-255
|
439
|
+
|
440
|
+
assert_equal ['offset', 'line', 'count'], assembly.scope.values_fields.to_a
|
441
|
+
assert_equal ['offset', 'line', 'count'], assembly.scope.grouping_fields.to_a
|
442
|
+
end
|
443
|
+
end
|