norikra 0.1.6-java → 0.1.7-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: 0250e9866cf7d804dee32f348e8aa7832fbf5ef2
4
- data.tar.gz: a91fb11a6ed74fd8bc2bc56108c62e4a4d3e8b0e
3
+ metadata.gz: c60623a71ba50774fd30d435b33ddd5abddb5a32
4
+ data.tar.gz: 4540758d58b47d144feaa504087a393a7853d380
5
5
  SHA512:
6
- metadata.gz: 506b88f4cb736f441566f9ee02d34fbe7d2c990cddcf8bf8c30c2ebe907010a8dc44fc5586db57985d86fcf8f6aa784f09b80e12d8211147315621d230fbd8b6
7
- data.tar.gz: 5913062545c129fcdd227260c1c0081ed8f7ff3682103f833f03e41740571be637ca35968e6264d94690900e62b499b0460270a14a1fcb2a5e5c6c9a0ab80f87
6
+ metadata.gz: fba4984d9d6c96573f169d5d7fe1f62e6bf711666c0546886d11fce7723beaaf64dce7a30d884b1c05870c7edce49603345e18d660c6d67824d408e22ef768ba
7
+ data.tar.gz: 3359da4c4bd851e4f2191ab859b902843619d17124da18b5fe6ab7f3c9fe1d07afed9d12b0e4579fc5b81c40ebba7db0a8035fe1e831dd0dea3ec7367c7d820f
@@ -260,22 +260,22 @@ module Norikra
260
260
  # Subqueries can only consist of a select clause, a from clause and a where clause.
261
261
  # The group by and having clauses, as well as joins, outer-joins and output rate limiting are not permitted within subqueries.
262
262
 
263
- # model.getFromClause.getStreams[0].getFilter.setEventTypeName("hoge")
263
+ # model.getFromClause.getStreams[0].getFilter.setEventTypeName("hoge") # normal Stream
264
+ # model.getFromClause.getStreams[1].getExpression.getChildren[0].getChildren[0].getFilter.getEventTypeName # pattern
264
265
 
265
266
  # model.getSelectClause.getSelectList[1].getExpression => #<Java::ComEspertechEsperClientSoda::SubqueryExpression:0x3344c133>
266
267
  # model.getSelectClause.getSelectList[1].getExpression.getModel.getFromClause.getStreams[0].getFilter.getEventTypeName
267
268
  # model.getWhereClause.getChildren[1] .getModel.getFromClause.getStreams[0].getFilter.getEventTypeName
268
269
 
269
- statement_model.getFromClause.getStreams.each do |stream|
270
- target_name = stream.getFilter.getEventTypeName
271
- unless mapping[target_name]
272
- raise RuntimeError, "target missing in mapping, maybe BUG"
273
- end
274
- stream.getFilter.setEventTypeName(mapping[target_name])
275
- end
276
-
277
270
  rewriter = lambda {|node|
278
- # nothing for query expression clauses
271
+ if node.respond_to?(:getEventTypeName)
272
+ target_name = node.getEventTypeName
273
+ rewrite_name = mapping[ target_name ]
274
+ unless rewrite_name
275
+ raise RuntimeError, "target missing in mapping, maybe BUG: #{target_name}"
276
+ end
277
+ node.setEventTypeName(rewrite_name)
278
+ end
279
279
  }
280
280
  recaller = lambda {|node|
281
281
  Norikra::Query.rewrite_event_type_name(node.getModel, mapping)
@@ -314,6 +314,7 @@ module Norikra
314
314
  def self.traverse_fields(rewriter, recaller, statement_model)
315
315
  #NOTICE: SQLStream is not supported yet.
316
316
  dig = lambda {|node|
317
+ return unless node
317
318
  rewriter.call(node)
318
319
 
319
320
  if node.is_a?(Java::ComEspertechEsperClientSoda::SubqueryExpression)
@@ -344,7 +345,7 @@ module Norikra
344
345
  dig.call(stream.getExpression)
345
346
  end
346
347
  if stream.respond_to?(:getFilter) # Filter < ProjectedStream
347
- dig.call(stream.getFilter.getFilter) #=> Expression
348
+ dig.call(stream.getFilter)
348
349
  end
349
350
  if stream.respond_to?(:getParameterExpressions) # MethodInvocationStream
350
351
  dig.call(stream.getParameterExpressions)
@@ -210,6 +210,11 @@ module Norikra
210
210
  # "field.index("?")" => ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "path"], ["EVENT_PROP_MAPPED", "index", "\"?\""]]
211
211
  # "field.f1.index(".")" => ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "path"], ["EVENT_PROP_SIMPLE", "q1"], ["EVENT_PROP_MAPPED", "index", "\".\""]]
212
212
 
213
+ #### escapes: Oops!!!! unsupported yet.
214
+ # "`path name`" => ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "`path name`"]]
215
+ # "`T Table`.`path name`" => ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "`T Testing`"], ["EVENT_PROP_SIMPLE", "`path name`"]]
216
+ # "`size.num`" => ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "`size.num`"]]
217
+
213
218
  def nodetype?(*sym)
214
219
  sym.include?(:prop) || sym.include?(:property)
215
220
  end
@@ -258,6 +263,10 @@ module Norikra
258
263
  # 2nd child is bare-word (like [a-z][a-z0-9]*) -> this is function -> 1st child is receiver -> property
259
264
  # 2nd child is literal or property or none -> 1st child is built-in function
260
265
 
266
+ ### escaped name access
267
+ # "`T Table`.param.length()" => ["LIB_FUNC_CHAIN", ["LIB_FUNCTION", "TestTable Testing.param", "length", "("]]
268
+ ## Oops! we CANNOT support this syntax
269
+
261
270
  def nodetype?(*sym)
262
271
  sym.include?(:lib) || sym.include?(:libfunc)
263
272
  end
@@ -1,3 +1,3 @@
1
1
  module Norikra
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -32,8 +32,8 @@ def administrator
32
32
  $administrator ||= service.getEPAdministrator
33
33
  end
34
34
 
35
- def compileEPL(query_str)
36
- administrator.compileEPL(query_str)
35
+ def compileEPL(query)
36
+ administrator.compileEPL(query.expression)
37
37
  end
38
38
 
39
39
  def query_string(model)
@@ -43,7 +43,11 @@ def query_string(model)
43
43
  model.toEPLElement(writer)
44
44
  writer.toString
45
45
  elsif model.respond_to?(:toPrecedenceFreeEPL)
46
- model.toPrecedenceFreeEPL(writer)
46
+ begin
47
+ model.toPrecedenceFreeEPL(writer)
48
+ rescue ArgumentError
49
+ model.toPrecedenceFreeEPL(writer, formatter)
50
+ end
47
51
  writer.toString
48
52
  elsif model.is_a?(Java::ComEspertechEsperClientSoda::EPStatementObjectModel)
49
53
  model.toEPL
@@ -53,6 +57,16 @@ def query_string(model)
53
57
  end
54
58
  end
55
59
 
60
+ def compiledExpression(query)
61
+ model = compileEPL(query)
62
+ mapping = {}
63
+ query.targets.each do |target|
64
+ mapping[target] = target
65
+ end
66
+ Norikra::Query.rewrite_query(model, mapping)
67
+ query_string(model)
68
+ end
69
+
56
70
  puts <<DESC
57
71
 
58
72
  Example:
@@ -24,6 +24,54 @@ describe Norikra::Query do
24
24
  end
25
25
  end
26
26
 
27
+ ### Escaped target/field names are not supported yet!
28
+ # context 'with escaped abnormal field name' do
29
+ # it 'returns instance wrongly parsed for field with instance method call' do
30
+ # expression = 'SELECT count(*) AS cnt FROM `TestTable Testing`.win:time_batch(10 sec) WHERE `path name`="/" AND size > 100 and `param string`.length() > 0'
31
+ # q = Norikra::Query.new(
32
+ # :name => 'TestTable query1.1', :expression => expression
33
+ # )
34
+ # expect(q.name).to eql('TestTable query1.1')
35
+ # expect(q.group).to be_nil
36
+ # expect(q.expression).to eql(expression)
37
+ # expect(q.targets).to eql(['TestTable Testing'])
38
+
39
+ # expect(q.fields).to eql(['param string', '`path name`', 'size'].sort)
40
+ # expect(q.fields('TestTable Testing')).to eql(['param string','`path name`','size'].sort) # 'param string' is not escaped!
41
+ # expect(q.fields(nil)).to eql([])
42
+ # end
43
+
44
+ # it 'returns instance correctly parsed w/ fully-qualified escaped name fields' do
45
+ # expression = 'SELECT count(*) AS cnt FROM `TestTable Testing`.win:time_batch(10 sec) WHERE `TestTable Testing`.`path name`="/" AND `size.num` > 100 and `TestTable Testing`.param.length() > 0'
46
+ # q = Norikra::Query.new(
47
+ # :name => 'TestTable query1.2', :expression => expression
48
+ # )
49
+ # expect(q.name).to eql('TestTable query1.2')
50
+ # expect(q.group).to be_nil
51
+ # expect(q.expression).to eql(expression)
52
+ # expect(q.targets).to eql(['TestTable Testing'])
53
+
54
+ # expect(q.fields).to eql(['param', '`path name`', '`size.num`'].sort)
55
+ # expect(q.fields('TestTable Testing')).to eql(['param','`path name`','`size.num`'].sort)
56
+ # expect(q.fields(nil)).to eql([])
57
+ # end
58
+
59
+ # it 'returns instance correctly parsed w/ fully-qualified escaped name fields' do
60
+ # expression = 'SELECT count(*) AS cnt FROM `TestTable Testing`.win:time_batch(10 sec) WHERE path\.name="/" AND size\.num > 100 and `TestTable Testing`.param\.name.length() > 0'
61
+ # q = Norikra::Query.new(
62
+ # :name => 'TestTable query1.3', :expression => expression
63
+ # )
64
+ # expect(q.name).to eql('TestTable query1.3')
65
+ # expect(q.group).to be_nil
66
+ # expect(q.expression).to eql(expression)
67
+ # expect(q.targets).to eql(['TestTable Testing'])
68
+
69
+ # expect(q.fields).to eql(['param\.name', 'path\.name', 'size\.num'].sort)
70
+ # expect(q.fields('TestTable Testing')).to eql(['param\.name', 'path\.name', 'size\.num'].sort)
71
+ # expect(q.fields(nil)).to eql([])
72
+ # end
73
+ # end
74
+
27
75
  context 'with top-level built-in functions' do
28
76
  it 'returns query instances collectly parsed' do
29
77
  expression = 'SELECT rate(10) FROM TestTable output snapshot every 2 sec'
@@ -90,6 +138,21 @@ describe Norikra::Query do
90
138
  expect(q.fields('StreamB')).to eql(['size','header'].sort)
91
139
  expect(q.fields(nil)).to eql(['product'])
92
140
  end
141
+
142
+ it 'returns query instances collectly parsed, with field accessing views' do
143
+ expression = 'select product, max(sta.size) as maxsize from StreamA.win:ext_timed_batch(ts1, 1 hours, 0L) as sta, StreamB(size > 10).win:ext_timed_batch(ts2, 20 sec) as stb where sta.data.substr(0,8) = stb.header AND Math.abs(sta.size) > 3'
144
+ q = Norikra::Query.new(
145
+ :name => 'TestTable query3.1', :expression => expression
146
+ )
147
+ expect(q.name).to eql('TestTable query3.1')
148
+ expect(q.expression).to eql(expression)
149
+ expect(q.targets).to eql(['StreamA', 'StreamB'])
150
+
151
+ expect(q.fields).to eql(['product', 'size', 'ts1', 'data', 'header', 'ts2'].sort)
152
+ expect(q.fields('StreamA')).to eql(['size','data','ts1'].sort)
153
+ expect(q.fields('StreamB')).to eql(['size','header','ts2'].sort)
154
+ expect(q.fields(nil)).to eql(['product'])
155
+ end
93
156
  end
94
157
 
95
158
  context 'with query with subquery (where clause)' do
@@ -189,6 +252,16 @@ describe Norikra::Query do
189
252
  end
190
253
  end
191
254
 
255
+ context 'with simple query and views with field reference' do
256
+ it 'returns query instances collectly parsed' do
257
+ expression = 'SELECT count(*) AS c FROM TestTable.win:ext_timed_batch(ts, 1 min, 0L) WHERE path.source.length() > 0'
258
+ q = Norikra::Query.new(:name => 'TestTable query8.3', :expression => expression)
259
+ expect(q.fields).to eql(['path.source', 'ts'].sort)
260
+ expect(q.fields('TestTable')).to eql(['path.source', 'ts'].sort)
261
+ expect(q.fields(nil)).to eql([])
262
+ end
263
+ end
264
+
192
265
  context 'with query with patterns' do
193
266
  it 'returns query instances collectly parsed' do
194
267
 
@@ -352,6 +425,20 @@ describe Norikra::Query do
352
425
  mapping = {'TestTable' => 'T1'}
353
426
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x1)
354
427
 
428
+ ## not supported yet!
429
+ # # escaped abnormal field name / target name
430
+ # e1a = 'select count(*) as cnt from `TestTable Testing`.win:time_batch(10 sec) where `TestTable testing`.`path name`="/" and size > 100 and param.length() > 0'
431
+ # x1a = 'select count(*) as cnt from T2.win:time_batch(10 seconds) where T2.`path name`="/" and size > 100 and (param.length()) > 0'
432
+ # model = administrator.compileEPL(e1a)
433
+ # mapping = {'TestTable Testing' => 'T2'}
434
+ # expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x1a)
435
+
436
+ # e1b = 'select count(*) as cnt from `TestTable Testing`.win:time_batch(10 sec) where path\.name="/" and size\.num > 100 and `testtable testing`.param\.name.length() > 0'
437
+ # x1b = 'select count(*) as cnt from T2.win:time_batch(10 seconcds) where path\.name="/" and size\.num > 100 and T2.param\.name.length() > 0'
438
+ # model = administrator.compileEPL(e1b)
439
+ # mapping = {'TestTable Testing' => 'T2'}
440
+ # expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x1b)
441
+
355
442
  # nested container field access
356
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'
357
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'
@@ -380,6 +467,12 @@ describe Norikra::Query do
380
467
  mapping = {'TestTable' => 'T1'}
381
468
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x3b)
382
469
 
470
+ # 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'
473
+ model = administrator.compileEPL(e3c)
474
+ mapping = {'TestTable' => 'T1'}
475
+ expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x3c)
383
476
 
384
477
  # Fully-qualified field access
385
478
  e4 = 'select count(*) as cnt from TestTable.win:time_batch(10 seconds) where path = "/" and TestTable.size > 100 and (param.length()) > 0'
@@ -450,6 +543,13 @@ describe Norikra::Query do
450
543
  model = administrator.compileEPL(e13)
451
544
  mapping = {'logs' => 'L111'}
452
545
  expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x13)
546
+
547
+ # 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)]'
550
+ model = administrator.compileEPL(e14)
551
+ mapping = {'TestTable' => 'T1'}
552
+ expect(Norikra::Query.rewrite_query(model, mapping).toEPL).to eql(x14)
453
553
  end
454
554
  end
455
555
  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: 0.1.6
4
+ version: 0.1.7
5
5
  platform: java
6
6
  authors:
7
7
  - TAGOMORI Satoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mizuno