cascading.jruby 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/spec/expr_spec.rb CHANGED
@@ -1,10 +1,230 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe Object do
3
+ context ExprStub do
4
4
  it 'should allow expr syntax' do
5
5
  test_assembly do
6
6
  insert 'foo' => 1, 'bar' => expr('offset:int')
7
7
  check_scope :values_fields => ['offset', 'line', 'bar', 'foo']
8
8
  end
9
9
  end
10
+
11
+ it 'should compile expressions' do
12
+ e = ExprStub.new('x:int + y:int')
13
+ e.compile
14
+ end
15
+
16
+ it 'should throw an exception for parsing failures' do
17
+ e = ExprStub.new('x:int + doesnotparse y:string')
18
+ lambda{ e.compile }.should raise_error CascadingException
19
+ end
20
+
21
+ it 'should throw an exception for compile failures' do
22
+ e = ExprStub.new('new DoesNotExist(x:int).doesnotcompile()')
23
+ lambda{ e.compile }.should raise_error CascadingException
24
+ end
25
+
26
+ it 'should throw an exception for compile failures' do
27
+ e = ExprStub.new('true ? x:int : y:string')
28
+ lambda{ e.compile }.should raise_error CascadingException
29
+ end
30
+
31
+ it 'should evaluate expressions' do
32
+ e = ExprStub.new('x:int + y:int')
33
+ result = e.eval(:x => 2, :y => 3)
34
+ result.should == 5
35
+
36
+ e = ExprStub.new('x:int + y:string')
37
+ result = e.eval(:x => 2, :y => 'blah')
38
+ result.should == '2blah'
39
+
40
+ e = ExprStub.new('x:long + y:int')
41
+ result = e.eval(:x => 2, :y => 3)
42
+ result.should == 5
43
+
44
+ e = ExprStub.new('x:double + y:int')
45
+ result = e.eval(:x => 2.0, :y => 3)
46
+ result.should == 5.0
47
+
48
+ e = ExprStub.new('x:float + y:int')
49
+ result = e.eval(:x => 2.0, :y => 3)
50
+ result.should == 5.0
51
+
52
+ e = ExprStub.new('x:bool && y:bool')
53
+ result = e.eval(:x => true, :y => false)
54
+ result.should == false
55
+ end
56
+
57
+ it 'should evaluate expressions despite argument order' do
58
+ e = ExprStub.new('x:int + y:int')
59
+ result = e.eval(:y => 3, :x => 2)
60
+ result.should == 5
61
+ end
62
+
63
+ it 'should throw an exception for invalid actual arguments' do
64
+ e = ExprStub.new('x:int + y:int')
65
+ lambda{ e.eval(:x => 2, :y => 'blah') }.should raise_error CascadingException
66
+
67
+ # Janino does not coerce numeric strings to Java Integers
68
+ e = ExprStub.new('x:int + y:int')
69
+ lambda{ e.eval(:x => 2, :y => '3') }.should raise_error CascadingException
70
+
71
+ # eval should not coerce numeric strings to Java Floats
72
+ e = ExprStub.new('x:int + y:float')
73
+ lambda{ e.eval(:x => 2, :y => '3') }.should raise_error CascadingException
74
+
75
+ # eval should not coerce numeric strings to Java Longs
76
+ e = ExprStub.new('x:long + y:int')
77
+ lambda{ e.eval(:x => '2', :y => 3) }.should raise_error CascadingException
78
+
79
+ # eval should not coerce floats to Java Longs
80
+ e = ExprStub.new('x:long + y:int')
81
+ lambda{ e.eval(:x => 2.0, :y => 3) }.should raise_error CascadingException
82
+
83
+ # eval should not coerce integers to Java Floats
84
+ e = ExprStub.new('x:int + y:float')
85
+ lambda{ e.eval(:x => 2, :y => 3) }.should raise_error CascadingException
86
+
87
+ e = ExprStub.new('x:float + y:int')
88
+ lambda{ e.eval(:x => 'blah', :y => 3) }.should raise_error CascadingException
89
+
90
+ e = ExprStub.new('x:long + y:int')
91
+ lambda{ e.eval(:x => [], :y => 3) }.should raise_error CascadingException
92
+
93
+ e = ExprStub.new('x:long + y:int')
94
+ lambda{ e.eval(:x => nil, :y => 3) }.should raise_error CascadingException
95
+ end
96
+
97
+ it 'should throw an exception for missing actual arguments' do
98
+ e = ExprStub.new('x:int + y:int')
99
+ lambda{ e.eval(:x => 2) }.should raise_error ExprArgException
100
+ end
101
+
102
+ it 'should ignore extraneous actual arguments' do
103
+ e = ExprStub.new('x:int + y:int')
104
+ result = e.eval(:x => 2, :y => 3, :z => 'unused')
105
+ result.should == 5
106
+ end
107
+
108
+ it 'should use default actual arguments to validate' do
109
+ e = ExprStub.new('x:int + y:int')
110
+ result = e.validate
111
+ result.should == 0
112
+
113
+ e = ExprStub.new('x:long + y:int')
114
+ result = e.validate
115
+ result.should == 0
116
+
117
+ e = ExprStub.new('x:double + y:int')
118
+ result = e.validate
119
+ result.should == 0.0
120
+
121
+ e = ExprStub.new('x:float + y:int')
122
+ result = e.validate
123
+ result.should == 0.0
124
+
125
+ e = ExprStub.new('x:bool && y:bool')
126
+ result = e.validate
127
+ result.should == false
128
+
129
+ e = ExprStub.new('x:int + y:string')
130
+ result = e.validate
131
+ result.should == '0null'
132
+
133
+ e = ExprStub.new('x:string + y:string')
134
+ result = e.validate
135
+ result.should == 'nullnull'
136
+ end
137
+
138
+ it 'should fail to validate these expressions with default actual arguments' do
139
+ e = ExprStub.new('x:string.indexOf("R") == -1')
140
+ lambda { e.validate }.should raise_error CascadingException
141
+
142
+ e = ExprStub.new('x:string.substring(0, 8)')
143
+ lambda { e.validate }.should raise_error CascadingException
144
+ end
145
+
146
+ it 'should allow overriding default actual arguments for validation' do
147
+ e = ExprStub.new('x:string.indexOf("R") == -1')
148
+ result = e.validate(:x => 'nothinghere')
149
+ result.should == true
150
+
151
+ e = ExprStub.new('x:string.substring(0, 8)')
152
+ result = e.validate(:x => 'atleast8chars')
153
+ result.should == 'atleast8'
154
+ end
155
+
156
+ it 'should allow overriding default actual arguments for validation via expr' do
157
+ expr('x:string.indexOf("R") == -1', :validate_with => { :x => 'nothinghere' })
158
+ expr('x:string.substring(0, 8)', :validate_with => { :x => 'atleast8chars' })
159
+ end
160
+
161
+ it 'should allow overriding default actual arguments for validation via filter' do
162
+ test_assembly do
163
+ filter :expression => 'line:string.indexOf("R") == -1', :validate_with => { :line => 'nothinghere' }
164
+ check_scope :values_fields => ['offset', 'line']
165
+ end
166
+ end
167
+
168
+ it 'should allow overriding default actual arguments for validation via where' do
169
+ test_assembly do
170
+ where 'line:string.equals("not_set") && "0".equals(offset:string)', :validate_with => { :line => 'nulls_rejected' }
171
+ check_scope :values_fields => ['offset', 'line']
172
+ end
173
+ end
174
+
175
+ it 'should allow disabling validation via expr' do
176
+ expr('x:string.indexOf("R") == -1', :validate => false)
177
+ expr('x:string.substring(0, 8)', :validate => false)
178
+ end
179
+
180
+ it 'should allow disabling validation via filter' do
181
+ test_assembly do
182
+ filter :expression => 'line:string.indexOf("R") == -1', :validate => false
183
+ check_scope :values_fields => ['offset', 'line']
184
+ end
185
+ end
186
+
187
+ it 'should allow disabling validation via where' do
188
+ test_assembly do
189
+ where 'line:string.indexOf("R") == -1', :validate => false
190
+ check_scope :values_fields => ['offset', 'line']
191
+ end
192
+ end
193
+
194
+ it 'should only allow floating point division by zero' do
195
+ e = ExprStub.new('x:float / y:float')
196
+ result = e.validate
197
+ result.nan?.should == true
198
+
199
+ e = ExprStub.new('x:double / y:double')
200
+ result = e.validate
201
+ result.nan?.should == true
202
+
203
+ # From: http://download.oracle.com/javase/6/docs/api/java/lang/ArithmeticException.html
204
+ # Thrown when an exceptional arithmetic condition has occurred. For
205
+ # example, an integer "divide by zero" throws an instance of this class.
206
+
207
+ e = ExprStub.new('x:long / y:long')
208
+ lambda { e.validate }.should raise_error CascadingException
209
+
210
+ e = ExprStub.new('x:int / y:int')
211
+ lambda { e.validate }.should raise_error CascadingException
212
+ end
213
+
214
+ it 'should catch missing fields in filter expressions' do
215
+ lambda do
216
+ test_assembly do
217
+ filter :expression => 'doesnotexist:int > offset:int'
218
+ check_scope :values_fields => ['offset', 'line', 'bar', 'foo']
219
+ end
220
+ end.should raise_error ExprArgException
221
+ end
222
+
223
+ it 'should catch missing fields in insert expressions' do
224
+ lambda do
225
+ test_assembly do
226
+ insert 'foo' => 1, 'bar' => expr('doesnotexist:int + offset:int')
227
+ end
228
+ end.should raise_error ExprArgException
229
+ end
10
230
  end
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ context Object do
4
+ it 'should definitely not do this' do
5
+ names = ['x', 'y'].to_java(java.lang.String)
6
+ types = [java.lang.Integer.java_class, java.lang.Integer.java_class].to_java(java.lang.Class)
7
+ evaluator = Java::OrgCodehausJanino::ExpressionEvaluator.new('x + y', java.lang.Comparable.java_class, names, types)
8
+
9
+ thrown = nil
10
+ exception = nil
11
+ begin
12
+ evaluator.evaluate([nil, nil].to_java)
13
+ rescue java.lang.IllegalArgumentException => iae
14
+ thrown = 'IllegalArgumentException'
15
+ exception = iae
16
+ rescue java.lang.reflect.InvocationTargetException => ite
17
+ thrown = 'InvocationTargetException'
18
+ exception = ite
19
+ end
20
+
21
+ # How can this be? A nil exception?
22
+ thrown.should == 'InvocationTargetException'
23
+ exception.should be_nil
24
+ end
25
+
26
+ case JRUBY_VERSION
27
+ when '1.2.0'
28
+ it 'should handle Fixnum -> Long for ExprStub#eval' do
29
+ e = ExprStub.new('x:long + y:long')
30
+ result = e.eval(:x => 2, :y => 3)
31
+ result.should == 5
32
+ end
33
+
34
+ it 'should handle Fixnum -> Long for ExprStub#validate' do
35
+ e = ExprStub.new('x:long + y:long')
36
+ result = e.validate
37
+ result.should == 0
38
+ end
39
+ when '1.4.0'
40
+ # This test previously failed for 1.4.0 (it's duplicated in cascading_spec)
41
+ it 'should handle string and integer field names' do
42
+ f = fields(['a', 1, 'b', 2])
43
+ f.to_a.should == ['a', 1, 'b', 2]
44
+ end
45
+
46
+ it 'should handle Fixnum -> Integer for ExprStub#eval' do
47
+ e = ExprStub.new('x:int + y:int')
48
+ result = e.eval(:x => 2, :y => 3)
49
+ result.should == 5
50
+ end
51
+
52
+ it 'should handle Fixnum -> Integer for ExprStub#validate' do
53
+ e = ExprStub.new('x:int + y:int')
54
+ result = e.validate
55
+ result.should == 0
56
+ end
57
+ when '1.5.3'
58
+ it 'should handle Fixnum -> Integer for ExprStub#eval' do
59
+ e = ExprStub.new('x:int + y:int')
60
+ result = e.eval(:x => 2, :y => 3)
61
+ result.should == 5
62
+ end
63
+
64
+ it 'should handle Fixnum -> Integer for ExprStub#validate' do
65
+ e = ExprStub.new('x:int + y:int')
66
+ result = e.validate
67
+ result.should == 0
68
+ end
69
+ else
70
+ raise "cascading.jruby has not been tested with JRuby version #{JRUBY_VERSION}"
71
+ end
72
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe Cascading::Scope do
3
+ context Cascading::Scope do
4
4
  it 'should allow override of primary key' do
5
5
  test_assembly do
6
6
  split 'line', ['x', 'y'], :pattern => /,/
data/spec/scope_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe Cascading::Scope do
3
+ context Cascading::Scope do
4
4
  it 'should match Cascading fields names from source tap scheme' do
5
5
  test_assembly do
6
6
  # Pass that uses our scope instead of all_fields
data/spec/spec_util.rb CHANGED
@@ -171,7 +171,7 @@ def verify_assembly_output(assembly_name, params, &block)
171
171
  end
172
172
 
173
173
  def describe_job(job_file, &block)
174
- describe Object do
174
+ context Object do
175
175
  before(:each) do
176
176
  @properties = cascading_properties
177
177
  # Must artificially fill ARGV to prevent errors when creating multi-taps
data/tasks/spec.rake CHANGED
@@ -37,7 +37,7 @@ namespace :spec do
37
37
  t.rcov_opts = PROJ.rcov.opts + ['--exclude', 'spec']
38
38
  end
39
39
 
40
- RCov::VerifyTask.new(:verify) do |t|
40
+ RCov::VerifyTask.new(:verify) do |t|
41
41
  t.threshold = PROJ.rcov.threshold
42
42
  t.index_html = File.join(PROJ.rcov.dir, 'index.html')
43
43
  t.require_exact_threshold = PROJ.rcov.threshold_exact
metadata CHANGED
@@ -1,137 +1,128 @@
1
1
  --- !ruby/object:Gem::Specification
2
- name: cascading.jruby
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 4
9
- version: 0.0.4
10
- platform: ruby
11
- authors:
12
- - Matt Walker
13
- - "Gr\xC3\xA9goire Marabout"
14
- autorequire:
15
- bindir: bin
16
- cert_chain: []
17
-
18
- date: 2011-04-05 00:00:00 -05:00
19
- default_executable:
20
- dependencies: []
21
-
22
- description: cascading.jruby is a small DSL above Cascading, written in JRuby
2
+ required_ruby_version: !ruby/object:Gem::Requirement
3
+ requirements:
4
+ - - '>='
5
+ - !ruby/object:Gem::Version
6
+ version: "0"
7
+ version:
23
8
  email: mwalker@etsy.com
24
- executables:
25
- - make_job
26
- extensions: []
9
+ cert_chain: []
27
10
 
11
+ summary: A JRuby DSL for Cascading
12
+ post_install_message:
28
13
  extra_rdoc_files:
29
- - History.txt
30
- - LICENSE.txt
31
- - bin/make_job
32
- - samples/data/data2.txt
33
- - samples/data/data_join1.txt
34
- - samples/data/data_join2.txt
35
- - samples/data/data_join3.txt
36
- - spec/resource/join_input.txt
37
- - spec/resource/test_input.txt
38
- - test/data/data1.txt
39
- - test/data/data2.txt
40
- files:
41
- - HACKING.md
42
- - History.txt
43
- - LICENSE.txt
44
- - README.md
45
- - Rakefile
46
- - bin/make_job
47
- - lib/cascading.rb
48
- - lib/cascading/assembly.rb
49
- - lib/cascading/base.rb
50
- - lib/cascading/cascade.rb
51
- - lib/cascading/cascading.rb
52
- - lib/cascading/cascading_exception.rb
53
- - lib/cascading/expr_stub.rb
54
- - lib/cascading/ext/array.rb
55
- - lib/cascading/flow.rb
56
- - lib/cascading/operations.rb
57
- - lib/cascading/scope.rb
58
- - samples/branch.rb
59
- - samples/cascading.rb
60
- - samples/copy.rb
61
- - samples/data/data2.txt
62
- - samples/data/data_join1.txt
63
- - samples/data/data_join2.txt
64
- - samples/data/data_join3.txt
65
- - samples/join.rb
66
- - samples/logwordcount.rb
67
- - samples/project.rb
68
- - samples/rename.rb
69
- - samples/scorenames.rb
70
- - samples/splitter.rb
71
- - samples/union.rb
72
- - spec/cascading_spec.rb
73
- - spec/expr_spec.rb
74
- - spec/primary_key_spec.rb
75
- - spec/resource/join_input.txt
76
- - spec/resource/test_input.txt
77
- - spec/scope_spec.rb
78
- - spec/spec.opts
79
- - spec/spec_helper.rb
80
- - spec/spec_util.rb
81
- - src/cascading/jruby/Main.java
82
- - src/cascading/jruby/runner.rb
83
- - tags
84
- - tasks/ann.rake
85
- - tasks/ant.rake
86
- - tasks/bones.rake
87
- - tasks/gem.rake
88
- - tasks/git.rake
89
- - tasks/notes.rake
90
- - tasks/post_load.rake
91
- - tasks/rdoc.rake
92
- - tasks/rubyforge.rake
93
- - tasks/samples.rake
94
- - tasks/setup.rb
95
- - tasks/spec.rake
96
- - tasks/svn.rake
97
- - tasks/test.rake
98
- - test/data/data1.txt
99
- - test/data/data2.txt
100
- - test/test_assembly.rb
101
- - test/test_cascading.rb
102
- - test/test_flow.rb
103
- has_rdoc: true
14
+ - History.txt
15
+ - LICENSE.txt
16
+ - bin/make_job
17
+ - samples/data/data2.txt
18
+ - samples/data/data_join1.txt
19
+ - samples/data/data_join2.txt
20
+ - samples/data/data_join3.txt
21
+ - spec/resource/join_input.txt
22
+ - spec/resource/test_input.txt
23
+ - test/data/data1.txt
24
+ - test/data/data2.txt
104
25
  homepage: http://github.com/etsy/cascading.jruby
105
- licenses: []
106
-
107
- post_install_message:
26
+ signing_key:
27
+ name: cascading.jruby
108
28
  rdoc_options:
109
- - --main
110
- - README.md
111
- require_paths:
112
- - lib
113
- required_ruby_version: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- segments:
118
- - 0
119
- version: "0"
29
+ - --main
30
+ - README.md
31
+ autorequire:
32
+ rubyforge_project: cascading.jruby
33
+ executables:
34
+ - make_job
35
+ description: cascading.jruby is a small DSL above Cascading, written in JRuby
36
+ specification_version: 2
37
+ default_executable:
38
+ files:
39
+ - HACKING.md
40
+ - History.txt
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - bin/make_job
45
+ - lib/cascading.rb
46
+ - lib/cascading/assembly.rb
47
+ - lib/cascading/base.rb
48
+ - lib/cascading/cascade.rb
49
+ - lib/cascading/cascading.rb
50
+ - lib/cascading/cascading_exception.rb
51
+ - lib/cascading/expr_stub.rb
52
+ - lib/cascading/ext/array.rb
53
+ - lib/cascading/flow.rb
54
+ - lib/cascading/operations.rb
55
+ - lib/cascading/scope.rb
56
+ - samples/branch.rb
57
+ - samples/cascading.rb
58
+ - samples/copy.rb
59
+ - samples/data/data2.txt
60
+ - samples/data/data_join1.txt
61
+ - samples/data/data_join2.txt
62
+ - samples/data/data_join3.txt
63
+ - samples/join.rb
64
+ - samples/logwordcount.rb
65
+ - samples/project.rb
66
+ - samples/rename.rb
67
+ - samples/scorenames.rb
68
+ - samples/splitter.rb
69
+ - samples/union.rb
70
+ - spec/cascading_spec.rb
71
+ - spec/expr_spec.rb
72
+ - spec/jruby_version_spec.rb
73
+ - spec/primary_key_spec.rb
74
+ - spec/resource/join_input.txt
75
+ - spec/resource/test_input.txt
76
+ - spec/scope_spec.rb
77
+ - spec/spec.opts
78
+ - spec/spec_helper.rb
79
+ - spec/spec_util.rb
80
+ - src/cascading/jruby/Main.java
81
+ - src/cascading/jruby/runner.rb
82
+ - tasks/ann.rake
83
+ - tasks/ant.rake
84
+ - tasks/bones.rake
85
+ - tasks/gem.rake
86
+ - tasks/git.rake
87
+ - tasks/notes.rake
88
+ - tasks/post_load.rake
89
+ - tasks/rdoc.rake
90
+ - tasks/rubyforge.rake
91
+ - tasks/samples.rake
92
+ - tasks/setup.rb
93
+ - tasks/spec.rake
94
+ - tasks/svn.rake
95
+ - tasks/test.rake
96
+ - test/data/data1.txt
97
+ - test/data/data2.txt
98
+ - test/test_assembly.rb
99
+ - test/test_cascading.rb
100
+ - test/test_flow.rb
120
101
  required_rubygems_version: !ruby/object:Gem::Requirement
121
102
  requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- segments:
125
- - 0
126
- version: "0"
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ version:
107
+ extensions: []
108
+
109
+ rubygems_version: 1.3.1
127
110
  requirements: []
128
111
 
129
- rubyforge_project: cascading.jruby
130
- rubygems_version: 1.3.6
131
- signing_key:
132
- specification_version: 3
133
- summary: A JRuby DSL for Cascading
112
+ authors:
113
+ - Matt Walker
114
+ - "Gr\xc3\xa9goire Marabout"
115
+ date: 2011-08-22 04:00:00 +00:00
116
+ platform: ruby
134
117
  test_files:
135
- - test/test_assembly.rb
136
- - test/test_cascading.rb
137
- - test/test_flow.rb
118
+ - test/test_assembly.rb
119
+ - test/test_cascading.rb
120
+ - test/test_flow.rb
121
+ version: !ruby/object:Gem::Version
122
+ version: 0.0.5
123
+ require_paths:
124
+ - lib
125
+ dependencies: []
126
+
127
+ bindir: bin
128
+ has_rdoc: true