norikra 1.2.0-java → 1.2.1-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7e969ece3deb5788c7e7e76c9d6cc4961b4307c
4
- data.tar.gz: bbfdc5a4056935c355082877e6ef347b7ded54ec
3
+ metadata.gz: 0e2938132b83a49bb328d060517750c5cb9d7e95
4
+ data.tar.gz: 7c20e09c3795b209946f08f49d3503ccccec3caf
5
5
  SHA512:
6
- metadata.gz: 4ea0f4f04ba875e2432db51a179d75e3ae18e3a05fc03e945b14fdce187b61da969cd334e11d67aaf8a49b0a032b389f2f57a6c385c98f284b4ecd5bd3156156
7
- data.tar.gz: 0add6a6f2539d188f2de82856f1d8cc222f9e6dd60b31b96acbc10167f047d9395c71273dde65a97d23b9b0838d30e0c7661b899d226077def93301e272515da
6
+ metadata.gz: 6a684145944825a6c813ec8695a7eee3ee6411de5654af120a90a77f7ee4e0fae9becef6535c476b5afce4754a7923d9188a8feca8c912a0c55393f2a6989794
7
+ data.tar.gz: 4140d210916fcb7d575527fce40f9b3bda7d7fc3a9f7af9d88b2ef1c6202678d63b28c7369f71d227df399548d708486ccfea5aca2b7bfeb6f771acfda88e773
data/Changes.md CHANGED
@@ -3,6 +3,8 @@
3
3
  Changes of norikra.
4
4
 
5
5
  ## v1
6
+ * v1.2.1
7
+ * Fix bug to fail to rewrite nullable fields
6
8
  * v1.2.0
7
9
  * Add `NULLABLE(...)` field to query NULL explicitly
8
10
  * Pluggable listener and user defined listener gems
data/lib/norikra/query.rb CHANGED
@@ -261,16 +261,39 @@ module Norikra
261
261
  def self.rewrite_nullable_fields(statement_model)
262
262
  # NULLABLE(field) -> field
263
263
  ## NOTICE: NULLABLE(...) cannot be used in view parameters. ex: target.std:unique(NULLABLE(a)) -> x
264
+ check_nullable = lambda {|exp|
265
+ # top-level lib function
266
+ # exp.getChain[0] #=> Java::ComEspertechEsperClientSoda::DotExpressionItem
267
+ exp &&
268
+ exp.is_a?(Java::ComEspertechEsperClientSoda::DotExpression) &&
269
+ exp.getChain.size == 1 &&
270
+ exp.getChain[0].name.upcase == 'NULLABLE'
271
+ }
272
+ fetch_field = lambda {|exp| exp.getChain[0].getParameters[0] }
273
+
264
274
  rewriter = lambda {|node|
265
- if node.respond_to?(:getExpression)
266
- exp = node.getExpression
267
- if exp && exp.is_a?(Java::ComEspertechEsperClientSoda::DotExpression) && exp.getChain.size == 1
268
- # top-level lib function
269
- # exp.getChain[0] #=> Java::ComEspertechEsperClientSoda::DotExpressionItem
270
- if exp.getChain[0].name.upcase == 'NULLABLE'
271
- node.setExpression(exp.getChain[0].getParameters[0])
272
- end
273
- end
275
+ # without loop of parameters because this code shows which parameter cause errors in user's environment
276
+ if node.respond_to?(:getExpression) && check_nullable.(node.getExpression)
277
+ node.setExpression(fetch_field.(node.getExpression))
278
+ end
279
+
280
+ if node.respond_to?(:getFilter) && check_nullable.(node.getFilter)
281
+ node.setFilter(fetch_field.(node.getFilter))
282
+ end
283
+
284
+ if node.respond_to?(:getChildren) && node.getChildren.any?{|exp| check_nullable.(exp) }
285
+ node.setChildren(node.getChildren.map{|e| check_nullable.(e) ? fetch_field.(e) : e })
286
+ end
287
+
288
+ if node.respond_to?(:getParameters) && node.getParameters.any?{|exp| check_nullable.(exp) }
289
+ node.setParameters(node.getParameters.map{|e| check_nullable.(e) ? fetch_field.(e) : e })
290
+ end
291
+ if node.respond_to?(:getChain) && node.getChain.any?{|exp| check_nullable.(exp) }
292
+ node.setChain(node.getChain.map{|e| check_nullable.(e) ? fetch_field.(e) : e })
293
+ end
294
+
295
+ if node.respond_to?(:getExpressions) && node.getExpressions.any?{|exp| check_nullable.(exp) }
296
+ node.setExpressions(node.getExpressions.map{|e| check_nullable.(e) ? fetch_field.(e) : e })
274
297
  end
275
298
  }
276
299
  recaller = lambda {|node|
@@ -1,3 +1,3 @@
1
1
  module Norikra
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
data/spec/query_spec.rb CHANGED
@@ -158,6 +158,27 @@ describe Norikra::Query do
158
158
 
159
159
  expect(q.invalid?).to be_falsy
160
160
  end
161
+
162
+ it 'returns query instances correctly parsed, with built-in NULLABLE() in CASE' do
163
+ expression = 'SELECT CASE WHEN eventType = 1 AND NULLABLE(detail.type) = 1 THEN 1 ELSE 0 END AS type, COUNT(*) AS c FROM TestTable.win:time_batch(10 sec) GROUP BY CASE WHEN eventType = 1 AND NULLABLE(detail.type) = 1 THEN 1 ELSE 0 END'
164
+ q = Norikra::Query.new(
165
+ :name => 'TestTable query1', :expression => expression
166
+ )
167
+ expect(q.name).to eql('TestTable query1')
168
+ expect(q.group).to be_nil
169
+ expect(q.expression).to eql(expression)
170
+ expect(q.targets).to eql(['TestTable'])
171
+
172
+ expect(q.fields).to eql(['detail.type', 'eventType'])
173
+ expect(q.fields('TestTable')).to eql(['detail.type', 'eventType'])
174
+ expect(q.fields(nil)).to eql([])
175
+
176
+ expect(q.nullable_fields).to eql(['detail.type'])
177
+ expect(q.nullable_fields('TestTable')).to eql(['detail.type'])
178
+ expect(q.nullable_fields(nil)).to eql([])
179
+
180
+ expect(q.invalid?).to be_falsy
181
+ end
161
182
  end
162
183
 
163
184
  context 'with order by' do
@@ -491,7 +512,7 @@ describe Norikra::Query do
491
512
  it 'returns query without NULLABLE()' do
492
513
  with_engine do
493
514
  model = administrator.compileEPL(expression)
494
- expect(Norikra::Query.rewrite_event_field_name(model, {'TestTable' => 'T1'}).toEPL).to eql(expression)
515
+ expect(Norikra::Query.rewrite_nullable_fields(model).toEPL).to eql(expected)
495
516
  end
496
517
  end
497
518
  end
@@ -502,18 +523,29 @@ describe Norikra::Query do
502
523
  it 'returns query without NULLABLE()' do
503
524
  with_engine do
504
525
  model = administrator.compileEPL(expression)
505
- expect(Norikra::Query.rewrite_event_field_name(model, {'TestTable' => 'T1'}).toEPL).to eql(expression)
526
+ expect(Norikra::Query.rewrite_nullable_fields(model).toEPL).to eql(expected)
527
+ end
528
+ end
529
+ end
530
+
531
+ context 'with NULLABLE() in CASE' do
532
+ expression = 'select case when eventType=1 and nullable(detail.type)=1 then 1 else 0 end as type, count(*) AS c from TestTable.win:time_batch(10 seconds) group by case when eventType=1 and nullable(detail.type)=1 then 1 else 0 end'
533
+ expected = 'select case when eventType=1 and detail.type=1 then 1 else 0 end as type, count(*) as c from TestTable.win:time_batch(10 seconds) group by case when eventType=1 and detail.type=1 then 1 else 0 end'
534
+ it 'returns query without NULLABLE()' do
535
+ with_engine do
536
+ model = administrator.compileEPL(expression)
537
+ expect(Norikra::Query.rewrite_nullable_fields(model).toEPL).to eql(expected)
506
538
  end
507
539
  end
508
540
  end
509
541
 
510
542
  context 'with some NULLABLE()' do
511
543
  expression = 'select a, NULLABLE(b), NULLABLE(c), count(*) as cnt from TestTable.win:time_batch(10 seconds) where c>0 group by a, b, c'
512
- expected = 'select a, b, c, count(*) AS cnt from TestTable.win:time_batch(10 seconds) where c>0 group by a, b, c'
544
+ expected = 'select a, b, c, count(*) as cnt from TestTable.win:time_batch(10 seconds) where c>0 group by a, b, c'
513
545
  it 'returns query without NULLABLE()' do
514
546
  with_engine do
515
547
  model = administrator.compileEPL(expression)
516
- expect(Norikra::Query.rewrite_event_field_name(model, {'TestTable' => 'T1'}).toEPL).to eql(expression)
548
+ expect(Norikra::Query.rewrite_nullable_fields(model).toEPL).to eql(expected)
517
549
  end
518
550
  end
519
551
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: norikra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: java
6
6
  authors:
7
7
  - TAGOMORI Satoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mizuno