norikra 0.1.7-java → 1.0.0-java

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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -0
  3. data/esper/changelog.txt +103 -0
  4. data/esper/{esper-4.9.0.jar → esper-5.0.0.jar} +0 -0
  5. data/esper/esper/lib/antlr-runtime-4.1.jar +0 -0
  6. data/esper/esper/lib/cglib-nodep-3.1.jar +0 -0
  7. data/esper/esper/lib/commons-logging-1.1.3.jar +0 -0
  8. data/esper/esper/lib/esper_3rdparties.license +7 -13
  9. data/esper/esper/lib/log4j-1.2.17.jar +0 -0
  10. data/esper/esper/lib/readme.txt +7 -7
  11. data/lib/norikra/cli.rb +8 -2
  12. data/lib/norikra/engine.rb +55 -6
  13. data/lib/norikra/field.rb +14 -1
  14. data/lib/norikra/logger.rb +37 -11
  15. data/lib/norikra/logger_mizuno_patch.rb +1 -1
  16. data/lib/norikra/query.rb +56 -19
  17. data/lib/norikra/query/ast.rb +1129 -246
  18. data/lib/norikra/rpc/handler.rb +8 -0
  19. data/lib/norikra/server.rb +5 -4
  20. data/lib/norikra/stats.rb +7 -1
  21. data/lib/norikra/udf.rb +11 -2
  22. data/lib/norikra/udf_spec_helper.rb +3 -1
  23. data/lib/norikra/version.rb +1 -1
  24. data/lib/norikra/webui.rb +1 -0
  25. data/lib/norikra/webui/api.rb +168 -0
  26. data/lib/norikra/webui/handler.rb +6 -1
  27. data/lib/norikra/webui/http.rb +5 -0
  28. data/norikra.gemspec +1 -1
  29. data/public/css/norikra.css +20 -0
  30. data/public/js/jquery.min.js +6 -0
  31. data/public/js/norikra.webui.js +12 -1
  32. data/script/spec_server_pry +27 -13
  33. data/spec/field_spec.rb +20 -8
  34. data/spec/fieldset_spec.rb +11 -0
  35. data/spec/query_spec.rb +161 -52
  36. data/spec/stats_spec.rb +6 -1
  37. data/views/base.erb +2 -1
  38. data/views/index.erb +12 -0
  39. metadata +10 -62
  40. data/esper/esper/lib/antlr-runtime-3.2.jar +0 -0
  41. data/esper/esper/lib/cglib-nodep-2.2.jar +0 -0
  42. data/esper/esper/lib/commons-logging-1.1.1.jar +0 -0
  43. data/esper/esper/lib/log4j-1.2.16.jar +0 -0
  44. data/esper/esperio-amqp-4.9.0.jar +0 -0
  45. data/esper/esperio-amqp/lib/commons-cli-1.1.jar +0 -0
  46. data/esper/esperio-amqp/lib/commons-io-1.2.jar +0 -0
  47. data/esper/esperio-amqp/lib/esperio_3rdparties.license +0 -1328
  48. data/esper/esperio-amqp/lib/esperio_amqp_jars.txt +0 -2
  49. data/esper/esperio-amqp/lib/rabbitmq-client.jar +0 -0
  50. data/esper/esperio-csv-4.9.0.jar +0 -0
  51. data/esper/esperio-csv/lib/esperio_3rdparties.license +0 -1328
  52. data/esper/esperio-db-4.9.0.jar +0 -0
  53. data/esper/esperio-db/lib/esperio_3rdparties.license +0 -1328
  54. data/esper/esperio-http-4.9.0.jar +0 -0
  55. data/esper/esperio-http/lib/esperio_3rdparties.license +0 -1328
  56. data/esper/esperio-http/lib/httpclient-4.0.1.jar +0 -0
  57. data/esper/esperio-http/lib/httpcore-4.0.1.jar +0 -0
  58. data/esper/esperio-http/lib/httpcore-nio-4.0.1.jar +0 -0
  59. data/esper/esperio-license.txt +0 -95
  60. data/esper/esperio-socket-4.9.0.jar +0 -0
  61. data/esper/esperio-socket/lib/esperio_3rdparties.license +0 -1328
  62. data/esper/esperio-springjms-4.9.0.jar +0 -0
  63. data/esper/esperio-springjms/lib/activation-1.1.jar +0 -0
  64. data/esper/esperio-springjms/lib/activemq-core-5.7.0.jar +0 -0
  65. data/esper/esperio-springjms/lib/activemq-pool-5.7.0.jar +0 -0
  66. data/esper/esperio-springjms/lib/commons-pool-1.6.jar +0 -0
  67. data/esper/esperio-springjms/lib/esperio_3rdparties.license +0 -1328
  68. data/esper/esperio-springjms/lib/geronimo-j2ee-management_1.1_spec-1.0.1.jar +0 -0
  69. data/esper/esperio-springjms/lib/geronimo-jms_1.1_spec-1.1.1.jar +0 -0
  70. data/esper/esperio-springjms/lib/junit-4.8.2.jar +0 -0
  71. data/esper/esperio-springjms/lib/org.springframework.asm-3.1.1.RELEASE.jar +0 -0
  72. data/esper/esperio-springjms/lib/org.springframework.beans-3.1.1.RELEASE.jar +0 -0
  73. data/esper/esperio-springjms/lib/org.springframework.context-3.1.1.RELEASE.jar +0 -0
  74. data/esper/esperio-springjms/lib/org.springframework.core-3.1.1.RELEASE.jar +0 -0
  75. data/esper/esperio-springjms/lib/org.springframework.expression-3.1.1.RELEASE.jar +0 -0
  76. data/esper/esperio-springjms/lib/org.springframework.jms-3.1.1.RELEASE.jar +0 -0
  77. data/esper/esperio-springjms/lib/org.springframework.transaction-3.1.1.RELEASE.jar +0 -0
  78. data/esper/esperio-springjms/lib/slf4j-api-1.7.2.jar +0 -0
  79. data/esper/esperio-springjms/lib/slf4j-log4j12-1.7.2.jar +0 -0
  80. data/esper/esperio-stax-4.9.0.jar +0 -0
  81. data/esper/esperio-stax/lib/axiom-api-1.2.9.jar +0 -0
  82. data/esper/esperio-stax/lib/axiom-c14n-1.2.9.jar +0 -0
  83. data/esper/esperio-stax/lib/axiom-dom-1.2.9.jar +0 -0
  84. data/esper/esperio-stax/lib/axiom-impl-1.2.9.jar +0 -0
  85. data/esper/esperio-stax/lib/commons-logging-1.1.1.jar +0 -0
  86. data/esper/esperio-stax/lib/commons-logging-LICENSE.txt +0 -203
  87. data/esper/esperio-stax/lib/esperio_3rdparties.license +0 -1328
  88. data/esper/esperio-stax/lib/geronimo-activation-LICENSE.txt +0 -203
  89. data/esper/esperio-stax/lib/geronimo-activation_1.1_spec-1.0.2.jar +0 -0
  90. data/esper/esperio-stax/lib/geronimo-javamail-LICENSE.txt +0 -203
  91. data/esper/esperio-stax/lib/geronimo-javamail_1.4_spec-1.6.jar +0 -0
  92. data/esper/esperio-stax/lib/geronimo-stax-api-LICENSE.txt +0 -203
  93. data/esper/esperio-stax/lib/geronimo-stax-api_1.0_spec-1.0.1.jar +0 -0
  94. data/esper/esperio-stax/lib/jaxen-1.1.1.jar +0 -0
  95. data/esper/esperio-stax/lib/jaxen-LICENSE.txt +0 -33
  96. data/esper/esperio-stax/lib/wstx-LICENSE.txt +0 -203
  97. data/esper/esperio-stax/lib/wstx-asl-3.2.9.jar +0 -0
@@ -145,9 +145,10 @@ describe Norikra::Field do
145
145
  expect(f.format(' ')).to eql(' ')
146
146
  expect(f.format(true)).to eql('true')
147
147
  expect(f.format(false)).to eql('false')
148
- expect(f.format(nil)).to eql('')
149
- expect(f.format({})).to eql('{}')
150
- expect(f.format([])).to eql('[]')
148
+
149
+ expect(f.format(nil)).to be_nil
150
+ expect(f.format({})).to be_nil
151
+ expect(f.format([])).to be_nil
151
152
  end
152
153
  end
153
154
  end
@@ -158,11 +159,14 @@ describe Norikra::Field do
158
159
  f = Norikra::Field.new('x', 'boolean')
159
160
  expect(f.format(true)).to eql(true)
160
161
  expect(f.format(false)).to eql(false)
161
- expect(f.format(nil)).to eql(false)
162
162
  expect(f.format('')).to eql(true)
163
163
 
164
164
  expect(f.format('true')).to eql(true)
165
165
  expect(f.format('false')).to eql(false)
166
+
167
+ expect(f.format(nil)).to be_nil
168
+ expect(f.format({})).to be_nil
169
+ expect(f.format([])).to be_nil
166
170
  end
167
171
  end
168
172
  end
@@ -177,7 +181,9 @@ describe Norikra::Field do
177
181
  expect(f.format('.1')).to eql(0)
178
182
  expect(f.format('')).to eql(0)
179
183
  expect(f.format(' ')).to eql(0)
180
- expect(f.format(nil)).to eql(0)
184
+ expect(f.format(nil)).to be_nil
185
+ expect(f.format({})).to be_nil
186
+ expect(f.format([])).to be_nil
181
187
 
182
188
  f = Norikra::Field.new('x', 'long')
183
189
  expect(f.format('1')).to eql(1)
@@ -186,7 +192,9 @@ describe Norikra::Field do
186
192
  expect(f.format('.1')).to eql(0)
187
193
  expect(f.format('')).to eql(0)
188
194
  expect(f.format(' ')).to eql(0)
189
- expect(f.format(nil)).to eql(0)
195
+ expect(f.format(nil)).to be_nil
196
+ expect(f.format({})).to be_nil
197
+ expect(f.format([])).to be_nil
190
198
 
191
199
  f = Norikra::Field.new('x', 'float')
192
200
  expect(f.format('1')).to eql(1.0)
@@ -195,7 +203,9 @@ describe Norikra::Field do
195
203
  expect(f.format('.1')).to eql(0.1)
196
204
  expect(f.format('')).to eql(0.0)
197
205
  expect(f.format(' ')).to eql(0.0)
198
- expect(f.format(nil)).to eql(0.0)
206
+ expect(f.format(nil)).to be_nil
207
+ expect(f.format({})).to be_nil
208
+ expect(f.format([])).to be_nil
199
209
 
200
210
  f = Norikra::Field.new('x', 'double')
201
211
  expect(f.format('1')).to eql(1.0)
@@ -204,7 +214,9 @@ describe Norikra::Field do
204
214
  expect(f.format('.1')).to eql(0.1)
205
215
  expect(f.format('')).to eql(0.0)
206
216
  expect(f.format(' ')).to eql(0.0)
207
- expect(f.format(nil)).to eql(0.0)
217
+ expect(f.format(nil)).to be_nil
218
+ expect(f.format({})).to be_nil
219
+ expect(f.format([])).to be_nil
208
220
  end
209
221
  end
210
222
  end
@@ -350,6 +350,17 @@ describe Norikra::FieldSet do
350
350
  expect(d['f$foo$$$0']).to be_instance_of(String)
351
351
  expect(d['f$foo$$$0']).to eql('zero')
352
352
  end
353
+
354
+ it 'returns nil for value field but events has nested record' do
355
+ t = Norikra::FieldSet.new({'a' => 'string', 'b' => 'boolean', 'c' => 'long', 'd.$0' => 'double'})
356
+
357
+ d = t.format({'a'=>{'a1'=>"1"}, 'b'=>[1,2,3], 'c'=>{'cc'=>0.01}, 'd' => [ {'value'=>0.1} ]})
358
+ expect(d.size).to eql(4)
359
+ expect(d['a']).to be_nil
360
+ expect(d['b']).to be_nil
361
+ expect(d['c']).to be_nil
362
+ expect(d['d$$0']).to be_nil
363
+ end
353
364
  end
354
365
  end
355
366
  end
@@ -281,6 +281,25 @@ describe Norikra::Query do
281
281
  end
282
282
  end
283
283
 
284
+ describe '.looback' do
285
+ it 'returns nil for nil group' do
286
+ expect(Norikra::Query.loopback(nil)).to be_nil
287
+ end
288
+
289
+ it 'returns nil for string group name without prefix' do
290
+ expect(Norikra::Query.loopback('a')).to be_nil
291
+ expect(Norikra::Query.loopback('group1')).to be_nil
292
+ expect(Norikra::Query.loopback('LOOPBACK')).to be_nil
293
+ end
294
+
295
+ it 'returns specified string as loopback target by parentheses' do
296
+ expect(Norikra::Query.loopback('LOOPBACK()')).to be_nil
297
+ expect(Norikra::Query.loopback('LOOPBACK(a)')).to eql('a')
298
+ expect(Norikra::Query.loopback('LOOPBACK(loopback_target)')).to eql('loopback_target')
299
+ expect(Norikra::Query.loopback('LOOPBACK(target name)')).to eql('target name') # should be invalid on 'open'
300
+ end
301
+ end
302
+
284
303
  describe '#dup' do
285
304
  context 'for queries without group (default group)' do
286
305
  it 'returns query object with default group' do
@@ -307,7 +326,7 @@ describe Norikra::Query do
307
326
 
308
327
  describe '.rewrite_event_field_name' do
309
328
  context 'without any container field access' do
310
- expression = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path = "/" and size > 100 and (param.length()) > 0'
329
+ expression = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path="/" and size>100 and (param.length())>0'
311
330
  it 'returns same query with original' do
312
331
  with_engine do
313
332
  model = administrator.compileEPL(expression)
@@ -317,8 +336,8 @@ describe Norikra::Query do
317
336
  end
318
337
 
319
338
  context 'with container field access' do
320
- expression = 'select max(result.$0.size) as cnt from TestTable.win:time_batch(10 seconds) where req.path = "/" and result.$0.size > 100 and (req.param.length()) > 0'
321
- expected = 'select max(result$$0$size) as cnt from TestTable.win:time_batch(10 seconds) where req$path = "/" and result$$0$size > 100 and (req$param.length()) > 0'
339
+ expression = 'select max(result.$0.size) as cnt from TestTable.win:time_batch(10 seconds) where req.path="/" and result.$0.size>100 and (req.param.length())>0'
340
+ expected = 'select max(result$$0$size) as cnt from TestTable.win:time_batch(10 seconds) where req$path="/" and result$$0$size>100 and (req$param.length())>0'
322
341
  it 'returns query with encoded container fields' do
323
342
  with_engine do
324
343
  model = administrator.compileEPL(expression)
@@ -328,8 +347,8 @@ describe Norikra::Query do
328
347
  end
329
348
 
330
349
  context 'with container field access with joins' do
331
- expression = 'select product, max(sta.param.size) as maxsize from StreamA.win:keepall() as sta, StreamB(size > 10).win:time(20 seconds) as stb where (sta.data.$0.$$body.substr(0, 8)) = stb.header and (Math.abs(sta.size)) > 3'
332
- expected = 'select product, max(sta.param$size) as maxsize from StreamA.win:keepall() as sta, StreamB(size > 10).win:time(20 seconds) as stb where (sta.data$$0$$$body.substr(0, 8)) = stb.header and (Math.abs(sta.size)) > 3'
350
+ expression = 'select product, max(sta.param.size) as maxsize from StreamA.win:keepall() as sta, StreamB(size>10).win:time(20 seconds) as stb where (sta.data.$0.$$body.substr(0,8))=stb.header and (Math.abs(sta.size))>3'
351
+ expected = 'select product, max(sta.param$size) as maxsize from StreamA.win:keepall() as sta, StreamB(size>10).win:time(20 seconds) as stb where (sta.data$$0$$$body.substr(0,8))=stb.header and (Math.abs(sta.size))>3'
333
352
  it 'returns query with encoded container fields' do
334
353
  with_engine do
335
354
  model = administrator.compileEPL(expression)
@@ -339,8 +358,8 @@ describe Norikra::Query do
339
358
  end
340
359
 
341
360
  context 'without any container field access, but with alias specification, without joins' do
342
- expression = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path = "/" and TestTable.size > 100 and (param.length()) > 0'
343
- expected = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path = "/" and T1.size > 100 and (param.length()) > 0'
361
+ expression = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path="/" and TestTable.size>100 and (param.length())>0'
362
+ expected = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path="/" and T1.size>100 and (param.length())>0'
344
363
  it 'returns query expression' do
345
364
  with_engine do
346
365
  model = administrator.compileEPL(expression)
@@ -350,8 +369,8 @@ describe Norikra::Query do
350
369
  end
351
370
 
352
371
  context 'with subquery in select clause' do
353
- expression = 'select RfidEvent.zoneId.$0, (select name.x from Zones.std:unique(zoneName) where zoneId = RfidEvent.zoneId.$0) as name from RfidEvent'
354
- expected = 'select Z2.zoneId$$0, (select name$x from Zones.std:unique(zoneName) where zoneId = Z2.zoneId$$0) as name from RfidEvent'
372
+ expression = 'select RfidEvent.zoneId.$0, (select name.x from Zones.std:unique(zoneName) where zoneId=RfidEvent.zoneId.$0) as name from RfidEvent'
373
+ expected = 'select Z2.zoneId$$0, (select name$x from Zones.std:unique(zoneName) where zoneId=Z2.zoneId$$0) as name from RfidEvent'
355
374
  it 'returns query model which have replaced stream name, for only targets of fully qualified field name access' do
356
375
  with_engine do
357
376
  model = administrator.compileEPL(expression)
@@ -361,8 +380,8 @@ describe Norikra::Query do
361
380
  end
362
381
 
363
382
  context 'with container field accesses, with targets, aliases and joins' do
364
- expression = 'select StreamA.product, max(sta.param.size) as maxsize from StreamA.win:keepall() as sta, StreamB(size > 10).win:time(20 seconds) as stb where (sta.data.$0.$$body.substr(0, 8)) = StreamB.header.$0 and (Math.abs(StreamA.size.$0.$$abs)) > 3'
365
- expected = 'select S1.product, max(sta.param$size) as maxsize from StreamA.win:keepall() as sta, StreamB(size > 10).win:time(20 seconds) as stb where (sta.data$$0$$$body.substr(0, 8)) = S2.header$$0 and (Math.abs(S1.size$$0$$$abs)) > 3'
383
+ expression = 'select StreamA.product, max(sta.param.size) as maxsize from StreamA.win:keepall() as sta, StreamB(size>10).win:time(20 seconds) as stb where (sta.data.$0.$$body.substr(0,8))=StreamB.header.$0 and (Math.abs(StreamA.size.$0.$$abs))>3'
384
+ expected = 'select S1.product, max(sta.param$size) as maxsize from StreamA.win:keepall() as sta, StreamB(size>10).win:time(20 seconds) as stb where (sta.data$$0$$$body.substr(0,8))=S2.header$$0 and (Math.abs(S1.size$$0$$$abs))>3'
366
385
  it 'returns query model which have replaced stream name, for only targets of fully qualified field name access' do
367
386
  with_engine do
368
387
  model = administrator.compileEPL(expression)
@@ -374,7 +393,7 @@ describe Norikra::Query do
374
393
 
375
394
  describe '.rewrite_event_type_name' do
376
395
  context 'with simple query' do
377
- expression = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path = "/" and size > 100 and (param.length()) > 0'
396
+ expression = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path="/" and size>100 and (param.length())>0'
378
397
 
379
398
  it 'returns query model which have replaced stream name' do
380
399
  with_engine do
@@ -384,8 +403,8 @@ describe Norikra::Query do
384
403
  end
385
404
  end
386
405
  context 'with subquery in select clause' do
387
- expression = 'select zoneId.$0, (select name.x from Zones.std:unique(zoneName) where zoneId = RfidEvent.zoneId.$0) as name from RfidEvent'
388
- expected = 'select zoneId.$0, (select name.x from Z1.std:unique(zoneName) where zoneId = RfidEvent.zoneId.$0) as name from Z2'
406
+ expression = 'select zoneId.$0, (select name.x from Zones.std:unique(zoneName) where zoneId=RfidEvent.zoneId.$0) as name from RfidEvent'
407
+ expected = 'select zoneId.$0, (select name.x from Z1.std:unique(zoneName) where zoneId=RfidEvent.zoneId.$0) as name from Z2'
389
408
  it 'returns query model which have replaced stream name, for only From clause' do
390
409
  with_engine do
391
410
  model = administrator.compileEPL(expression)
@@ -394,8 +413,8 @@ describe Norikra::Query do
394
413
  end
395
414
  end
396
415
  context 'with subquery in from clause' do
397
- expression = "select * from BarData(ticker='MSFT', sub(closePrice, (select movAgv from SMA20Stream(ticker='MSFT').std:lastevent())) > 0)"
398
- expected = 'select * from B1(ticker = "MSFT" and (sub(closePrice, (select movAgv from B2(ticker = "MSFT").std:lastevent()))) > 0)'
416
+ expression = "select * from BarData(ticker='MSFT', sub(closePrice,(select movAgv from SMA20Stream(ticker='MSFT').std:lastevent()))>0)"
417
+ expected = 'select * from B1(ticker="MSFT" and (sub(closePrice,(select movAgv from B2(ticker="MSFT").std:lastevent())))>0)'
399
418
  it 'returns query model which have replaced stream name' do
400
419
  with_engine do
401
420
  model = administrator.compileEPL(expression)
@@ -404,7 +423,7 @@ describe Norikra::Query do
404
423
  end
405
424
  end
406
425
  context 'with joins' do
407
- expression = 'select product, max(sta.size) as maxsize from StreamA.win:keepall() as sta, StreamB(size > 10).win:time(20 seconds) as stb where (sta.data.substr(0, 8)) = stb.header and (Math.abs(sta.size)) > 3'
426
+ expression = 'select product, max(sta.size) as maxsize from StreamA.win:keepall() as sta, StreamB(size>10).win:time(20 seconds) as stb where (sta.data.substr(0,8))=stb.header and (Math.abs(sta.size))>3'
408
427
  it 'returns query model which have replaced stream name' do
409
428
  with_engine do
410
429
  model = administrator.compileEPL(expression)
@@ -416,11 +435,11 @@ describe Norikra::Query do
416
435
  end
417
436
 
418
437
  describe '.rewrite_query' do
419
- it 'rewrites all of targets and container-field-accesses' do
438
+ it 'rewrites all of targets and container-field-accesses, for single simple query' do
420
439
  with_engine do
421
440
  # single simple query
422
- e1 = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path = "/" and size > 100 and (param.length()) > 0'
423
- x1 = 'select count(*) as cnt from T1.win:time_batch(10 seconds) where path = "/" and size > 100 and (param.length()) > 0'
441
+ e1 = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path="/" and size>100 and (param.length())>0'
442
+ x1 = 'select count(*) as cnt from T1.win:time_batch(10 seconds) where path="/" and size>100 and (param.length())>0'
424
443
  model = administrator.compileEPL(e1)
425
444
  mapping = {'TestTable' => 'T1'}
426
445
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x1)
@@ -440,113 +459,203 @@ describe Norikra::Query do
440
459
  # expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x1b)
441
460
 
442
461
  # nested container field access
443
- e2 = 'select max(result.$0.size) as cnt from TestTable.win:time_batch(10 seconds) where req.path = "/" and result.$0.size > 100 and (req.param.length()) > 0'
444
- x2 = 'select max(result$$0$size) as cnt from T1.win:time_batch(10 seconds) where req$path = "/" and result$$0$size > 100 and (req$param.length()) > 0'
462
+ e2 = 'select max(result.$0.size) as cnt from TestTable.win:time_batch(10 seconds) where req.path="/" and result.$0.size>100 and (req.param.length())>0'
463
+ x2 = 'select max(result$$0$size) as cnt from T1.win:time_batch(10 seconds) where req$path="/" and result$$0$size>100 and (req$param.length())>0'
445
464
  model = administrator.compileEPL(e2)
446
465
  mapping = {'TestTable' => 'T1'}
447
466
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x2)
467
+ end
468
+ end
448
469
 
470
+ it 'rewrites targets/container field accesses w/ function calls and aliases' do
471
+ with_engine do
449
472
  # nested container field access w/ function call and alias
450
- e3 = 'select product, max(sta.param.size) as maxsize from StreamA.win:keepall() as sta, StreamB(size > 10).win:time(20 seconds) as stb where (sta.data.$0.$$body.substr(0, 8)) = stb.header and (Math.abs(sta.size)) > 3'
451
- x3 = 'select product, max(sta.param$size) as maxsize from S1.win:keepall() as sta, S2(size > 10).win:time(20 seconds) as stb where (sta.data$$0$$$body.substr(0, 8)) = stb.header and (Math.abs(sta.size)) > 3'
473
+ e3 = 'select product, max(sta.param.size) as maxsize from StreamA.win:keepall() as sta, StreamB(size>10).win:time(20 seconds) as stb where (sta.data.$0.$$body.substr(0,8))=stb.header and (Math.abs(sta.size))>3'
474
+ x3 = 'select product, max(sta.param$size) as maxsize from S1.win:keepall() as sta, S2(size>10).win:time(20 seconds) as stb where (sta.data$$0$$$body.substr(0,8))=stb.header and (Math.abs(sta.size))>3'
452
475
  model = administrator.compileEPL(e3)
453
476
  mapping = {'StreamA' => 'S1', 'StreamB' => 'S2'}
454
477
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x3)
455
478
 
456
479
  # nested function call
457
- e3a = 'select path.substring(0, path.index("?")) as urlpath, count(*) as count from TestTable.win:time_batch(60 seconds) group by path.substring(0, path.index("?"))'
458
- x3a = 'select path.substring(0, path.index("?")) as urlpath, count(*) as count from T1.win:time_batch(60 seconds) group by path.substring(0, path.index("?"))'
480
+ e3a = 'select path.substring(0,path.index("?")) as urlpath, count(*) as count from TestTable.win:time_batch(60 seconds) group by path.substring(0,path.index("?"))'
481
+ x3a = 'select path.substring(0,path.index("?")) as urlpath, count(*) as count from T1.win:time_batch(60 seconds) group by path.substring(0,path.index("?"))'
459
482
  model = administrator.compileEPL(e3a)
460
483
  mapping = {'TestTable' => 'T1'}
461
484
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x3a)
462
485
 
463
486
  # nested function call w/ container field access
464
- e3b = 'select path.f1.substring(0, path.f1.index("?")) as urlpath, count(*) as count from TestTable.win:time_batch(60 seconds) group by path.f1.substring(0, path.f1.index("?"))'
465
- x3b = 'select path$f1.substring(0, path$f1.index("?")) as urlpath, count(*) as count from T1.win:time_batch(60 seconds) group by path$f1.substring(0, path$f1.index("?"))'
487
+ e3b = 'select path.f1.substring(0,path.f1.index("?")) as urlpath, count(*) as count from TestTable.win:time_batch(60 seconds) group by path.f1.substring(0,path.f1.index("?"))'
488
+ x3b = 'select path$f1.substring(0,path$f1.index("?")) as urlpath, count(*) as count from T1.win:time_batch(60 seconds) group by path$f1.substring(0,path$f1.index("?"))'
466
489
  model = administrator.compileEPL(e3b)
467
490
  mapping = {'TestTable' => 'T1'}
468
491
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x3b)
469
492
 
470
493
  # views w/ field access
471
- e3c = 'select count(*) as c from TestTable.win:ext_timed_batch(TestTable.ts, 1 min, 0L) where path.source.length() > 0'
472
- x3c = 'select count(*) as c from T1.win:ext_timed_batch(T1.ts, 1 minutes, 0L) where (path$source.length()) > 0'
494
+ e3c = 'select count(*) as c from TestTable.win:ext_timed_batch(TestTable.ts,1 min,0L) where path.source.length()>0'
495
+ x3c = 'select count(*) as c from T1.win:ext_timed_batch(T1.ts,1 minutes,0L) where (path$source.length())>0'
473
496
  model = administrator.compileEPL(e3c)
474
497
  mapping = {'TestTable' => 'T1'}
475
498
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x3c)
476
499
 
477
500
  # Fully-qualified field access
478
- e4 = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path = "/" and TestTable.size > 100 and (param.length()) > 0'
479
- x4 = 'select count(*) as cnt from T1.win:time_batch(10 seconds) where path = "/" and T1.size > 100 and (param.length()) > 0'
501
+ e4 = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path="/" and TestTable.size>100 and (param.length())>0'
502
+ x4 = 'select count(*) as cnt from T1.win:time_batch(10 seconds) where path="/" and T1.size>100 and (param.length())>0'
480
503
  model = administrator.compileEPL(e4)
481
504
  mapping = {'TestTable' => 'T1'}
482
505
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x4)
483
506
 
484
507
  # Fully-qualified field access w/ container field access
485
- e5 = 'select RfidEvent.zoneId.$0, (select name.x from Zones.std:unique(zoneName) where zoneId = RfidEvent.zoneId.$0) as name from RfidEvent'
486
- x5 = 'select R1.zoneId$$0, (select name$x from Z1.std:unique(zoneName) where zoneId = R1.zoneId$$0) as name from R1'
508
+ e5 = 'select RfidEvent.zoneId.$0, (select name.x from Zones.std:unique(zoneName) where zoneId=RfidEvent.zoneId.$0) as name from RfidEvent'
509
+ x5 = 'select R1.zoneId$$0, (select name$x from Z1.std:unique(zoneName) where zoneId=R1.zoneId$$0) as name from R1'
487
510
  model = administrator.compileEPL(e5)
488
511
  mapping = {'RfidEvent' => 'R1', 'Zones' => 'Z1'}
489
512
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x5)
513
+ end
514
+ end
490
515
 
516
+ it 'rewrites targets and container field accesses with JOINs and SubQueries' do
517
+ with_engine do
491
518
  # Fully-qualified field access w/ container field access and function calls, JOINs
492
- e6 = 'select StreamA.product, max(sta.param.size) as maxsize from StreamA.win:keepall() as sta, StreamB(size > 10).win:time(20 seconds) as stb where (sta.data.$0.$$body.substr(0, 8)) = StreamB.header.$0 and (Math.abs(StreamA.size.$0.$$abs)) > 3'
493
- x6 = 'select S1.product, max(sta.param$size) as maxsize from S1.win:keepall() as sta, S2(size > 10).win:time(20 seconds) as stb where (sta.data$$0$$$body.substr(0, 8)) = S2.header$$0 and (Math.abs(S1.size$$0$$$abs)) > 3'
519
+ e6 = 'select StreamA.product, max(sta.param.size) as maxsize from StreamA.win:keepall() as sta, StreamB(size>10).win:time(20 seconds) as stb where (sta.data.$0.$$body.substr(0,8))=StreamB.header.$0 and (Math.abs(StreamA.size.$0.$$abs))>3'
520
+ x6 = 'select S1.product, max(sta.param$size) as maxsize from S1.win:keepall() as sta, S2(size>10).win:time(20 seconds) as stb where (sta.data$$0$$$body.substr(0,8))=S2.header$$0 and (Math.abs(S1.size$$0$$$abs))>3'
494
521
  model = administrator.compileEPL(e6)
495
522
  mapping = {'StreamA' => 'S1', 'StreamB' => 'S2'}
496
523
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x6)
497
524
 
498
525
  # ??? simple query
499
- e7 = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path = "/" and size > 100 and (param.length()) > 0'
500
- x7 = 'select count(*) as cnt from T1.win:time_batch(10 seconds) where path = "/" and size > 100 and (param.length()) > 0'
526
+ e7 = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path="/" and size>100 and (param.length())>0'
527
+ x7 = 'select count(*) as cnt from T1.win:time_batch(10 seconds) where path="/" and size>100 and (param.length())>0'
501
528
  model = administrator.compileEPL(e7)
502
529
  mapping = {'TestTable' => 'T1'}
503
530
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x7)
504
531
 
505
532
  # subquery
506
- e8 = 'select RfidEvent.zoneId.$0, (select name.x from Zones.std:unique(zoneName) where zoneId = RfidEvent.zoneId.$0) as name from RfidEvent'
507
- x8 = 'select R1.zoneId$$0, (select name$x from Z1.std:unique(zoneName) where zoneId = R1.zoneId$$0) as name from R1'
533
+ e8 = 'select RfidEvent.zoneId.$0, (select name.x from Zones.std:unique(zoneName) where zoneId=RfidEvent.zoneId.$0) as name from RfidEvent'
534
+ x8 = 'select R1.zoneId$$0, (select name$x from Z1.std:unique(zoneName) where zoneId=R1.zoneId$$0) as name from R1'
508
535
  model = administrator.compileEPL(e8)
509
536
  mapping = {'Zones' => 'Z1', 'RfidEvent' => 'R1'}
510
537
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x8)
511
538
 
512
539
  # filters and subquery
513
- e9 = 'select * from BarData(ticker = "MSFT" and (sub(closePrice, (select movAgv from SMA20Stream(ticker = "MSFT").std:lastevent())) > 0))'
514
- x9 = 'select * from B1(ticker = "MSFT" and (sub(closePrice, (select movAgv from S1(ticker = "MSFT").std:lastevent()))) > 0)'
540
+ e9 = 'select * from BarData(ticker="MSFT" and (sub(closePrice,(select movAgv from SMA20Stream(ticker="MSFT").std:lastevent()))>0))'
541
+ x9 = 'select * from B1(ticker="MSFT" and (sub(closePrice,(select movAgv from S1(ticker="MSFT").std:lastevent())))>0)'
515
542
  model = administrator.compileEPL(e9)
516
543
  mapping = {'BarData' => 'B1', 'SMA20Stream' => 'S1'}
517
544
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x9)
518
545
 
519
546
  # JOINs
520
- e10 = 'select product, max(sta.size) as maxsize from StreamA.win:keepall() as sta, StreamB(size > 10).win:time(20 seconds) as stb where (sta.data.substr(0, 8)) = stb.header and (Math.abs(sta.size)) > 3'
521
- x10 = 'select product, max(sta.size) as maxsize from S1.win:keepall() as sta, S2(size > 10).win:time(20 seconds) as stb where (sta.data.substr(0, 8)) = stb.header and (Math.abs(sta.size)) > 3'
547
+ e10 = 'select product, max(sta.size) as maxsize from StreamA.win:keepall() as sta, StreamB(size>10).win:time(20 seconds) as stb where (sta.data.substr(0,8))=stb.header and (Math.abs(sta.size))>3'
548
+ x10 = 'select product, max(sta.size) as maxsize from S1.win:keepall() as sta, S2(size>10).win:time(20 seconds) as stb where (sta.data.substr(0,8))=stb.header and (Math.abs(sta.size))>3'
522
549
  model = administrator.compileEPL(e10)
523
550
  mapping = {'StreamA' => 'S1', 'StreamB' => 'S2'}
524
551
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x10)
552
+ end
553
+ end
525
554
 
555
+ it 'rewrites targets and container field accesses with GROUP BY' do
556
+ with_engine do
526
557
  # GROUP BY clause
527
- e11 = 'select applog.campaign.id as campaign_id, member.region as region, member.lang as lang, count(*) as click, count(distinct member.id) as uu from applog.win:time_batch(1 minutes) where type = "click" group by applog.campaign.id, member.region, member.lang'
528
- x11 = 'select A1.campaign$id as campaign_id, member$region as region, member$lang as lang, count(*) as click, count(distinct member$id) as uu from A1.win:time_batch(1 minutes) where type = "click" group by A1.campaign$id, member$region, member$lang'
558
+ e11 = 'select applog.campaign.id as campaign_id, member.region as region, member.lang as lang, count(*) as click, count(distinct member.id) as uu from applog.win:time_batch(1 minutes) where type="click" group by applog.campaign.id, member.region, member.lang'
559
+ x11 = 'select A1.campaign$id as campaign_id, member$region as region, member$lang as lang, count(*) as click, count(distinct member$id) as uu from A1.win:time_batch(1 minutes) where type="click" group by A1.campaign$id, member$region, member$lang'
529
560
  model = administrator.compileEPL(e11)
530
561
  mapping = {'applog' => 'A1'}
531
562
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x11)
532
563
 
564
+ # GROUP BY with MIN()/MAX()
565
+ e11a = 'select applog.campaign.id as campaign_id, member.region as region, member.lang as lang, MIN(login.times) as min, MAX(login.times) as max, count(*) as click, count(distinct member.id) as uu from applog.win:time_batch(1 minutes) where type="click" group by applog.campaign.id, member.region, member.lang'
566
+ x11a = 'select A1.campaign$id as campaign_id, member$region as region, member$lang as lang, min(login$times) as min, max(login$times) as max, count(*) as click, count(distinct member$id) as uu from A1.win:time_batch(1 minutes) where type="click" group by A1.campaign$id, member$region, member$lang'
567
+ q11a = Norikra::Query.new(name: 'q11a', expression: e11a)
568
+ model = administrator.compileEPL(q11a.expression)
569
+ mapping = {'applog' => 'A1'}
570
+ expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x11a)
571
+ end
572
+ end
573
+
574
+ it 'rewrites targets and container field accesses with GROUP BY ROLLUP' do
575
+ with_engine do
576
+ e1 = 'select f1.$0.Symbol, StockTickEvent.data.feed, sum(f1.volume) from StockTickEvent.win:time_batch(30 seconds) as event group by rollup(f1.$0.Symbol, StockTickEvent.data.feed)'
577
+ x1 = 'select f1$$0$Symbol, S1.data$feed, sum(f1$volume) from S1.win:time_batch(30 seconds) as event group by rollup(f1$$0$Symbol, S1.data$feed)'
578
+ model = administrator.compileEPL(e1)
579
+ mapping = {'StockTickEvent' => 'S1'}
580
+ expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x1)
581
+ end
582
+ end
583
+
584
+ it 'rewrites targets and container field accesses with GROUP BY CUBE' do
585
+ with_engine do
586
+ e1 = 'select f1.$0.Symbol, StockTickEvent.data.feed, sum(f1.volume) from StockTickEvent.win:time_batch(30 seconds) as event group by cube(f1.$0.Symbol, StockTickEvent.data.feed)'
587
+ x1 = 'select f1$$0$Symbol, S1.data$feed, sum(f1$volume) from S1.win:time_batch(30 seconds) as event group by cube(f1$$0$Symbol, S1.data$feed)'
588
+ model = administrator.compileEPL(e1)
589
+ mapping = {'StockTickEvent' => 'S1'}
590
+ expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x1)
591
+ end
592
+ end
593
+
594
+ it 'rewrites targets and container field accesses with GROUP BY GROUPING SETS' do
595
+ with_engine do
596
+ e1 = 'select f1.$0.Symbol, StockTickEvent.data.feed, sum(f1.volume) from StockTickEvent.win:time_batch(30 seconds) as event group by grouping sets(f1.$0.Symbol, StockTickEvent.data.feed)'
597
+ x1 = 'select f1$$0$Symbol, S1.data$feed, sum(f1$volume) from S1.win:time_batch(30 seconds) as event group by grouping sets(f1$$0$Symbol, S1.data$feed)'
598
+ model = administrator.compileEPL(e1)
599
+ mapping = {'StockTickEvent' => 'S1'}
600
+ expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x1)
601
+ end
602
+ end
603
+
604
+ it 'rewrites targets and container field accesses with GROUP BY using complex combinations' do
605
+ with_engine do
606
+ e1 = 'select f1.$0.Symbol, StockTickEvent.data.feed, sum(f1.volume) from StockTickEvent.win:time_batch(30 seconds) as event group by f1.$0.Symbol, rollup(StockTickEvent.data.feed)'
607
+ x1 = 'select f1$$0$Symbol, S1.data$feed, sum(f1$volume) from S1.win:time_batch(30 seconds) as event group by f1$$0$Symbol, rollup(S1.data$feed)'
608
+ model = administrator.compileEPL(e1)
609
+ mapping = {'StockTickEvent' => 'S1'}
610
+ expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x1)
611
+
612
+ e2 = 'select f1.$0.Symbol, StockTickEvent.data.feed, sum(f1.volume) from StockTickEvent.win:time_batch(30 seconds) as event group by grouping sets((f1.$0.Symbol, StockTickEvent.data.feed), f1.$0.Symbol)'
613
+ x2 = 'select f1$$0$Symbol, S1.data$feed, sum(f1$volume) from S1.win:time_batch(30 seconds) as event group by grouping sets((f1$$0$Symbol, S1.data$feed), f1$$0$Symbol)'
614
+ model = administrator.compileEPL(e2)
615
+ mapping = {'StockTickEvent' => 'S1'}
616
+ expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x2)
617
+
618
+ e3 = 'select f1.$0.Symbol, StockTickEvent.data.feed, sum(f1.volume) from StockTickEvent.win:time_batch(30 seconds) as event group by grouping sets(f1.$0.Symbol, StockTickEvent.data.feed, ())'
619
+ x3 = 'select f1$$0$Symbol, S1.data$feed, sum(f1$volume) from S1.win:time_batch(30 seconds) as event group by grouping sets(f1$$0$Symbol, S1.data$feed, ())'
620
+ model = administrator.compileEPL(e3)
621
+ mapping = {'StockTickEvent' => 'S1'}
622
+ expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x3)
623
+
624
+ e4 = 'select f1.$0.Symbol, StockTickEvent.data.feed, sum(f1.volume) from StockTickEvent.win:time_batch(30 seconds) as event group by grouping sets(rollup(f1.$0.Symbol, StockTickEvent.data.feed), StockTickEvent.data.feed)'
625
+ x4 = 'select f1$$0$Symbol, S1.data$feed, sum(f1$volume) from S1.win:time_batch(30 seconds) as event group by grouping sets(rollup(f1$$0$Symbol, S1.data$feed), S1.data$feed)'
626
+ model = administrator.compileEPL(e4)
627
+ mapping = {'StockTickEvent' => 'S1'}
628
+ expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x4)
629
+ end
630
+ end
631
+
632
+ it 'rewrites targets and container field accesses with ORDER BY' do
633
+ with_engine do
533
634
  # ORDER BY clause
534
- e12 = 'select campaign.id, member.region as region, member.lang as lang, count(*) as click, count(distinct member.id) as uu from applog.win:time_batch(1 minutes) where type = "click" group by campaign.id, member.region, member.lang order by campaign.id'
535
- x12 = 'select campaign$id, member$region as region, member$lang as lang, count(*) as click, count(distinct member$id) as uu from A1.win:time_batch(1 minutes) where type = "click" group by campaign$id, member$region, member$lang order by campaign$id'
635
+ e12 = 'select campaign.id, member.region as region, member.lang as lang, count(*) as click, count(distinct member.id) as uu from applog.win:time_batch(1 minutes) where type="click" group by campaign.id, member.region, member.lang order by campaign.id'
636
+ x12 = 'select campaign$id, member$region as region, member$lang as lang, count(*) as click, count(distinct member$id) as uu from A1.win:time_batch(1 minutes) where type="click" group by campaign$id, member$region, member$lang order by campaign$id'
536
637
  model = administrator.compileEPL(e12)
537
638
  mapping = {'applog' => 'A1'}
538
639
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x12)
640
+ end
641
+ end
539
642
 
643
+ it 'rewrites targets and container field accesses with HAVING' do
644
+ with_engine do
540
645
  # HAVING clause
541
- e13 = 'select path, max(response.duration) from logs.win:time_batch(10 seconds) where path.startsWith("/api/") group by path having max(response.duration) >= 100'
542
- x13 = 'select path, max(response$duration) from L111.win:time_batch(10 seconds) where path.startsWith("/api/") group by path having max(response$duration) >= 100'
646
+ e13 = 'select path, max(response.duration) from logs.win:time_batch(10 seconds) where path.startsWith("/api/") group by path having max(response.duration)>=100'
647
+ x13 = 'select path, max(response$duration) from L111.win:time_batch(10 seconds) where path.startsWith("/api/") group by path having max(response$duration)>=100'
543
648
  model = administrator.compileEPL(e13)
544
649
  mapping = {'logs' => 'L111'}
545
650
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x13)
651
+ end
652
+ end
546
653
 
654
+ it 'rewrites targets and container field accesses with Patterns' do
655
+ with_engine do
547
656
  # Pattern
548
- e14 = 'select a.type from pattern [every a=TestTable -> b=TestTable(type = a.type)]'
549
- x14 = 'select a.type from pattern [every a=T1 -> b=T1(type = a.type)]'
657
+ e14 = 'select a.type from pattern [every a=TestTable -> b=TestTable(type=a.type)]'
658
+ x14 = 'select a.type from pattern [every a=T1 -> b=T1(type=a.type)]'
550
659
  model = administrator.compileEPL(e14)
551
660
  mapping = {'TestTable' => 'T1'}
552
661
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x14)