norikra 0.1.7-java → 1.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,5 +1,5 @@
1
1
  require 'java'
2
- require 'esper/lib/log4j-1.2.16.jar'
2
+ require 'esper/lib/log4j-1.2.17.jar'
3
3
  require 'mizuno/logger'
4
4
 
5
5
  module Mizuno
@@ -1,8 +1,8 @@
1
1
  require 'java'
2
- require 'esper-4.9.0.jar'
3
- require 'esper/lib/commons-logging-1.1.1.jar'
4
- require 'esper/lib/antlr-runtime-3.2.jar'
5
- require 'esper/lib/cglib-nodep-2.2.jar'
2
+ require 'esper-5.0.0.jar'
3
+ require 'esper/lib/commons-logging-1.1.3.jar'
4
+ require 'esper/lib/antlr-runtime-4.1.jar'
5
+ require 'esper/lib/cglib-nodep-3.1.jar'
6
6
 
7
7
  require 'norikra/error'
8
8
  require 'norikra/query/ast'
@@ -16,7 +16,8 @@ module Norikra
16
16
  @name = param[:name]
17
17
  raise Norikra::ArgumentError, "Query name MUST NOT be blank" if @name.nil? || @name.empty?
18
18
  @group = param[:group] # default nil
19
- @expression = param[:expression]
19
+ #TODO: ad-hoc query rewriting for https://jira.codehaus.org/browse/ESPER-788
20
+ @expression = param[:expression].gsub(/([ ,])(MIN|MAX)\(/){ $1 + $2.downcase + '(' }
20
21
  raise Norikra::ArgumentError, "Query expression MUST NOT be blank" if @expression.nil? || @expression.empty?
21
22
 
22
23
  @statement_name = nil
@@ -44,6 +45,10 @@ module Norikra
44
45
  end
45
46
  end
46
47
 
48
+ def self.loopback(group)
49
+ group && group =~ /^LOOPBACK\((.+)\)$/ && $1
50
+ end
51
+
47
52
  def dup
48
53
  self.class.new(:name => @name, :group => @group, :expression => @expression.dup)
49
54
  end
@@ -155,9 +160,9 @@ module Norikra
155
160
  end
156
161
 
157
162
  class ParseRuleSelectorImpl
158
- include com.espertech.esper.epl.parse.ParseRuleSelector
163
+ include Java::ComEspertechEsperEplParse::ParseRuleSelector
159
164
  def invokeParseRule(parser)
160
- parser.startEPLExpressionRule().getTree()
165
+ parser.startEPLExpressionRule()
161
166
  end
162
167
  end
163
168
 
@@ -166,10 +171,35 @@ module Norikra
166
171
  rule = ParseRuleSelectorImpl.new
167
172
  target = @expression.dup
168
173
  forerrmsg = @expression.dup
169
- result = com.espertech.esper.epl.parse.ParseHelper.parse(target, forerrmsg, true, rule, false)
170
-
171
- @ast = astnode(result.getTree)
174
+ result = Java::ComEspertechEsperEplParse::ParseHelper.parse(target, forerrmsg, true, rule, false)
175
+
176
+ # walk through AST and check syntax errors/semantic errors
177
+ ast = result.tree
178
+
179
+ services = Java::ComEspertechEsperClient::EPServiceProviderManager.getDefaultProvider.getServicesContext
180
+
181
+ walker = Java::ComEspertechEsperEplParse::EPLTreeWalkerListener.new(
182
+ result.getTokenStream,
183
+ services.getEngineImportService,
184
+ services.getVariableService,
185
+ services.getSchedulingService,
186
+ Java::ComEspertechEsperEplSpec::SelectClauseStreamSelectorEnum.mapFromSODA(
187
+ services.getConfigSnapshot.getEngineDefaults.getStreamSelection.getDefaultStreamSelector
188
+ ),
189
+ services.getEngineURI,
190
+ services.getConfigSnapshot,
191
+ services.getPatternNodeFactory,
192
+ services.getContextManagementService,
193
+ result.getScripts,
194
+ services.getExprDeclaredService
195
+ )
196
+
197
+ Java::ComEspertechEsperEplParse::ParseHelper.walk(ast, walker, target, forerrmsg)
198
+
199
+ @ast = astnode(ast)
172
200
  @ast
201
+ rescue Java::ComEspertechEsperEplParse::ASTWalkException => e
202
+ raise Norikra::QueryError, e.message
173
203
  rescue Java::ComEspertechEsperClient::EPStatementSyntaxException => e
174
204
  raise Norikra::QueryError, e.message
175
205
  end
@@ -284,7 +314,10 @@ module Norikra
284
314
  end
285
315
 
286
316
  ### Targets and fields re-writing supports (*) nodes
287
- # model.methods.select{|m| m.to_s.start_with?('get')}
317
+ # model.methods.select{|m| m.to_s.start_with?('get') && !m.to_s.start_with?('get_')}.sort
318
+
319
+ # :getAnnotations,
320
+ # :getClass,
288
321
  # :getContextName,
289
322
  # :getCreateContext,
290
323
  # :getCreateDataFlow,
@@ -338,6 +371,14 @@ module Norikra
338
371
  dig.call(c)
339
372
  end
340
373
  end
374
+ if node.respond_to?(:getExpression)
375
+ dig.call(node.getExpression)
376
+ end
377
+ if node.respond_to?(:getExpressions)
378
+ node.getExpressions.each do |e|
379
+ dig.call(e)
380
+ end
381
+ end
341
382
  }
342
383
 
343
384
  statement_model.getFromClause.getStreams.each do |stream|
@@ -361,9 +402,7 @@ module Norikra
361
402
 
362
403
  if statement_model.getSelectClause
363
404
  statement_model.getSelectClause.getSelectList.each do |item|
364
- if item.respond_to?(:getExpression)
365
- dig.call(item.getExpression)
366
- end
405
+ dig.call(item)
367
406
  end
368
407
  end
369
408
 
@@ -374,16 +413,14 @@ module Norikra
374
413
  end
375
414
 
376
415
  if statement_model.getGroupByClause
377
- statement_model.getGroupByClause.getGroupByExpressions.each do |child|
378
- dig.call(child)
416
+ statement_model.getGroupByClause.getGroupByExpressions.each do |item|
417
+ dig.call(item)
379
418
  end
380
419
  end
381
420
 
382
421
  if statement_model.getOrderByClause
383
422
  statement_model.getOrderByClause.getOrderByExpressions.each do |item|
384
- if item.respond_to?(:getExpression)
385
- dig.call(item.getExpression)
386
- end
423
+ dig.call(item)
387
424
  end
388
425
  end
389
426
 
@@ -1,152 +1,762 @@
1
1
  module Norikra
2
2
  class Query
3
- ### SELECT MAX(size) AS maxsize, fraud.aaa,bbb
3
+ ### SELECT max(size) AS maxsize, fraud.aaa, bbb
4
4
  ### FROM FraudWarningEvent.win:keepall() AS fraud,
5
5
  ### PINChangeEvent(size > 10).win:time(20 sec)
6
6
  ### WHERE fraud.accountNumber.substr(0,8) = substr(PINChangeEvent.accountNumber, 0, 8)
7
7
  ### AND cast(PINChangeEvent.size,double) > 10.5
8
- #
9
- # ["EPL_EXPR",
10
- # ["SELECTION_EXPR",
11
- # ["SELECTION_ELEMENT_EXPR",
12
- # ["LIB_FUNC_CHAIN",
13
- # ["LIB_FUNCTION",
14
- # "max",
15
- # ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "size"]],
16
- # "("]],
17
- # "maxsize"],
18
- # ["SELECTION_ELEMENT_EXPR",
19
- # ["EVENT_PROP_EXPR",
20
- # ["EVENT_PROP_SIMPLE", "fraud"],
21
- # ["EVENT_PROP_SIMPLE", "aaa"]]],
22
- # ["SELECTION_ELEMENT_EXPR",
23
- # ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "bbb"]]]],
24
- # ["STREAM_EXPR",
25
- # ["EVENT_FILTER_EXPR", "FraudWarningEvent"],
26
- # ["VIEW_EXPR", "win", "keepall"],
27
- # "fraud"],
28
- # ["STREAM_EXPR",
29
- # ["EVENT_FILTER_EXPR",
30
- # "PINChangeEvent",
31
- # [">", ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "size"]], "10"]],
32
- # ["VIEW_EXPR", "win", "time", ["TIME_PERIOD", ["SECOND_PART", "20"]]]],
33
- # ["WHERE_EXPR",
34
- # ["EVAL_AND_EXPR",
35
- # ["EVAL_EQUALS_EXPR",
36
- # ["LIB_FUNC_CHAIN",
37
- # ["LIB_FUNCTION", "fraud.accountNumber", "substr", "0", "8", "("]],
38
- # ["LIB_FUNC_CHAIN",
39
- # ["LIB_FUNCTION",
40
- # "substr",
41
- # ["EVENT_PROP_EXPR",
42
- # ["EVENT_PROP_SIMPLE", "PINChangeEvent"],
43
- # ["EVENT_PROP_SIMPLE", "accountNumber"]],
44
- # "0",
45
- # "8",
46
- # "("]]],
47
- # [">",
48
- # ["cast",
49
- # ["EVENT_PROP_EXPR",
50
- # ["EVENT_PROP_SIMPLE", "PINChangeEvent"],
51
- # ["EVENT_PROP_SIMPLE", "size"]],
52
- # "double"],
53
- # "10.5"]]]]
8
+
9
+ # ["startEPLExpressionRule",
10
+ # ["eplExpression",
11
+ # ["selectExpr",
12
+ # "SELECT",
13
+ # ["selectClause",
14
+ # ["selectionList",
15
+ # ["selectionListElement",
16
+ # ["selectionListElementExpr",
17
+ # ["expression",
18
+ # ["caseExpression",
19
+ # ["evalOrExpression",
20
+ # ["evalAndExpression",
21
+ # ["bitWiseExpression",
22
+ # ["negatedExpression",
23
+ # ["evalEqualsExpression",
24
+ # ["evalRelationalExpression",
25
+ # ["concatenationExpr",
26
+ # ["additiveExpression",
27
+ # ["multiplyExpression",
28
+ # ["unaryExpression",
29
+ # ["eventPropertyOrLibFunction",
30
+ # ["libFunction",
31
+ # ["libFunctionWithClass",
32
+ # ["funcIdentTop", "max"],
33
+ # "(",
34
+ # ["libFunctionArgs",
35
+ # ["libFunctionArgItem",
36
+ # ["expressionWithTime",
37
+ # ["expressionQualifyable",
38
+ # ["expression",
39
+ # ["caseExpression",
40
+ # ["evalOrExpression",
41
+ # ["evalAndExpression",
42
+ # ["bitWiseExpression",
43
+ # ["negatedExpression",
44
+ # ["evalEqualsExpression",
45
+ # ["evalRelationalExpression",
46
+ # ["concatenationExpr",
47
+ # ["additiveExpression",
48
+ # ["multiplyExpression",
49
+ # ["unaryExpression",
50
+ # ["eventPropertyOrLibFunction",
51
+ # ["eventProperty",
52
+ # ["eventPropertyAtomic",
53
+ # ["eventPropertyIdent",
54
+ # ["keywordAllowedIdent",
55
+ # "size"]]]]]]]]]]]]]]]]]]]]],
56
+ # ")"]]]]]]]]]]]]]]],
57
+ # "AS",
58
+ # ["keywordAllowedIdent", "maxsize"]]],
59
+ # ",",
60
+ # ["selectionListElement",
61
+ # ["selectionListElementExpr",
62
+ # ["expression",
63
+ # ["caseExpression",
64
+ # ["evalOrExpression",
65
+ # ["evalAndExpression",
66
+ # ["bitWiseExpression",
67
+ # ["negatedExpression",
68
+ # ["evalEqualsExpression",
69
+ # ["evalRelationalExpression",
70
+ # ["concatenationExpr",
71
+ # ["additiveExpression",
72
+ # ["multiplyExpression",
73
+ # ["unaryExpression",
74
+ # ["eventPropertyOrLibFunction",
75
+ # ["eventProperty",
76
+ # ["eventPropertyAtomic",
77
+ # ["eventPropertyIdent",
78
+ # ["keywordAllowedIdent", "fraud"]]],
79
+ # ".",
80
+ # ["eventPropertyAtomic",
81
+ # ["eventPropertyIdent",
82
+ # ["keywordAllowedIdent", "aaa"]]]]]]]]]]]]]]]]]]],
83
+ # ",",
84
+ # ["selectionListElement",
85
+ # ["selectionListElementExpr",
86
+ # ["expression",
87
+ # ["caseExpression",
88
+ # ["evalOrExpression",
89
+ # ["evalAndExpression",
90
+ # ["bitWiseExpression",
91
+ # ["negatedExpression",
92
+ # ["evalEqualsExpression",
93
+ # ["evalRelationalExpression",
94
+ # ["concatenationExpr",
95
+ # ["additiveExpression",
96
+ # ["multiplyExpression",
97
+ # ["unaryExpression",
98
+ # ["eventPropertyOrLibFunction",
99
+ # ["eventProperty",
100
+ # ["eventPropertyAtomic",
101
+ # ["eventPropertyIdent",
102
+ # ["keywordAllowedIdent", "bbb"]]]]]]]]]]]]]]]]]]]]],
103
+ # "FROM",
104
+ # ["fromClause",
105
+ # ["streamExpression",
106
+ # ["eventFilterExpression",
107
+ # ["classIdentifier", ["escapableStr", "FraudWarningEvent"]]],
108
+ # ".",
109
+ # ["viewExpression", "win", ":", "keepall", "(", ")"],
110
+ # "AS",
111
+ # "fraud"],
112
+ # ["regularJoin",
113
+ # ",",
114
+ # ["streamExpression",
115
+ # ["eventFilterExpression",
116
+ # ["classIdentifier", ["escapableStr", "PINChangeEvent"]],
117
+ # "(",
118
+ # ["expressionList",
119
+ # ["expression",
120
+ # ["caseExpression",
121
+ # ["evalOrExpression",
122
+ # ["evalAndExpression",
123
+ # ["bitWiseExpression",
124
+ # ["negatedExpression",
125
+ # ["evalEqualsExpression",
126
+ # ["evalRelationalExpression",
127
+ # ["concatenationExpr",
128
+ # ["additiveExpression",
129
+ # ["multiplyExpression",
130
+ # ["unaryExpression",
131
+ # ["eventPropertyOrLibFunction",
132
+ # ["eventProperty",
133
+ # ["eventPropertyAtomic",
134
+ # ["eventPropertyIdent",
135
+ # ["keywordAllowedIdent", "size"]]]]]]]]],
136
+ # ">",
137
+ # ["concatenationExpr",
138
+ # ["additiveExpression",
139
+ # ["multiplyExpression",
140
+ # ["unaryExpression",
141
+ # ["constant",
142
+ # ["numberconstant", ["number", "10"]]]]]]]]]]]]]]]],
143
+ # ")"],
144
+ # ".",
145
+ # ["viewExpression",
146
+ # "win",
147
+ # ":",
148
+ # "time",
149
+ # "(",
150
+ # ["expressionWithTimeList",
151
+ # ["expressionWithTimeInclLast",
152
+ # ["expressionWithTime",
153
+ # ["timePeriod",
154
+ # ["secondPart", ["numberconstant", ["number", "20"]], "sec"]]]]],
155
+ # ")"]]]],
156
+ # "WHERE",
157
+ # ["whereClause",
158
+ # ["evalOrExpression",
159
+ # ["evalAndExpression",
160
+ # ["bitWiseExpression",
161
+ # ["negatedExpression",
162
+ # ["evalEqualsExpression",
163
+ # ["evalRelationalExpression",
164
+ # ["concatenationExpr",
165
+ # ["additiveExpression",
166
+ # ["multiplyExpression",
167
+ # ["unaryExpression",
168
+ # ["eventPropertyOrLibFunction",
169
+ # ["libFunction",
170
+ # ["libFunctionWithClass",
171
+ # ["classIdentifier",
172
+ # ["escapableStr", "fraud"],
173
+ # ".",
174
+ # ["escapableStr", "accountNumber"]],
175
+ # ".",
176
+ # ["funcIdentTop", ["escapableIdent", "substr"]],
177
+ # "(",
178
+ # ["libFunctionArgs",
179
+ # ["libFunctionArgItem",
180
+ # ["expressionWithTime",
181
+ # ["expressionQualifyable",
182
+ # ["expression",
183
+ # ["caseExpression",
184
+ # ["evalOrExpression",
185
+ # ["evalAndExpression",
186
+ # ["bitWiseExpression",
187
+ # ["negatedExpression",
188
+ # ["evalEqualsExpression",
189
+ # ["evalRelationalExpression",
190
+ # ["concatenationExpr",
191
+ # ["additiveExpression",
192
+ # ["multiplyExpression",
193
+ # ["unaryExpression",
194
+ # ["constant",
195
+ # ["numberconstant",
196
+ # ["number", "0"]]]]]]]]]]]]]]]]]],
197
+ # ",",
198
+ # ["libFunctionArgItem",
199
+ # ["expressionWithTime",
200
+ # ["expressionQualifyable",
201
+ # ["expression",
202
+ # ["caseExpression",
203
+ # ["evalOrExpression",
204
+ # ["evalAndExpression",
205
+ # ["bitWiseExpression",
206
+ # ["negatedExpression",
207
+ # ["evalEqualsExpression",
208
+ # ["evalRelationalExpression",
209
+ # ["concatenationExpr",
210
+ # ["additiveExpression",
211
+ # ["multiplyExpression",
212
+ # ["unaryExpression",
213
+ # ["constant",
214
+ # ["numberconstant",
215
+ # ["number", "8"]]]]]]]]]]]]]]]]]]],
216
+ # ")"]]]]]]]],
217
+ # "=",
218
+ # ["evalRelationalExpression",
219
+ # ["concatenationExpr",
220
+ # ["additiveExpression",
221
+ # ["multiplyExpression",
222
+ # ["unaryExpression",
223
+ # ["eventPropertyOrLibFunction",
224
+ # ["libFunction",
225
+ # ["libFunctionWithClass",
226
+ # ["funcIdentTop", ["escapableIdent", "substr"]],
227
+ # "(",
228
+ # ["libFunctionArgs",
229
+ # ["libFunctionArgItem",
230
+ # ["expressionWithTime",
231
+ # ["expressionQualifyable",
232
+ # ["expression",
233
+ # ["caseExpression",
234
+ # ["evalOrExpression",
235
+ # ["evalAndExpression",
236
+ # ["bitWiseExpression",
237
+ # ["negatedExpression",
238
+ # ["evalEqualsExpression",
239
+ # ["evalRelationalExpression",
240
+ # ["concatenationExpr",
241
+ # ["additiveExpression",
242
+ # ["multiplyExpression",
243
+ # ["unaryExpression",
244
+ # ["eventPropertyOrLibFunction",
245
+ # ["eventProperty",
246
+ # ["eventPropertyAtomic",
247
+ # ["eventPropertyIdent",
248
+ # ["keywordAllowedIdent",
249
+ # "PINChangeEvent"]]],
250
+ # ".",
251
+ # ["eventPropertyAtomic",
252
+ # ["eventPropertyIdent",
253
+ # ["keywordAllowedIdent",
254
+ # "accountNumber"]]]]]]]]]]]]]]]]]]]],
255
+ # ",",
256
+ # ["libFunctionArgItem",
257
+ # ["expressionWithTime",
258
+ # ["expressionQualifyable",
259
+ # ["expression",
260
+ # ["caseExpression",
261
+ # ["evalOrExpression",
262
+ # ["evalAndExpression",
263
+ # ["bitWiseExpression",
264
+ # ["negatedExpression",
265
+ # ["evalEqualsExpression",
266
+ # ["evalRelationalExpression",
267
+ # ["concatenationExpr",
268
+ # ["additiveExpression",
269
+ # ["multiplyExpression",
270
+ # ["unaryExpression",
271
+ # ["constant",
272
+ # ["numberconstant",
273
+ # ["number", "0"]]]]]]]]]]]]]]]]]],
274
+ # ",",
275
+ # ["libFunctionArgItem",
276
+ # ["expressionWithTime",
277
+ # ["expressionQualifyable",
278
+ # ["expression",
279
+ # ["caseExpression",
280
+ # ["evalOrExpression",
281
+ # ["evalAndExpression",
282
+ # ["bitWiseExpression",
283
+ # ["negatedExpression",
284
+ # ["evalEqualsExpression",
285
+ # ["evalRelationalExpression",
286
+ # ["concatenationExpr",
287
+ # ["additiveExpression",
288
+ # ["multiplyExpression",
289
+ # ["unaryExpression",
290
+ # ["constant",
291
+ # ["numberconstant",
292
+ # ["number", "8"]]]]]]]]]]]]]]]]]]],
293
+ # ")"]]]]]]]]]]],
294
+ # "AND",
295
+ # ["bitWiseExpression",
296
+ # ["negatedExpression",
297
+ # ["evalEqualsExpression",
298
+ # ["evalRelationalExpression",
299
+ # ["concatenationExpr",
300
+ # ["additiveExpression",
301
+ # ["multiplyExpression",
302
+ # ["unaryExpression",
303
+ # ["builtinFunc",
304
+ # "cast",
305
+ # "(",
306
+ # ["expression",
307
+ # ["caseExpression",
308
+ # ["evalOrExpression",
309
+ # ["evalAndExpression",
310
+ # ["bitWiseExpression",
311
+ # ["negatedExpression",
312
+ # ["evalEqualsExpression",
313
+ # ["evalRelationalExpression",
314
+ # ["concatenationExpr",
315
+ # ["additiveExpression",
316
+ # ["multiplyExpression",
317
+ # ["unaryExpression",
318
+ # ["eventPropertyOrLibFunction",
319
+ # ["eventProperty",
320
+ # ["eventPropertyAtomic",
321
+ # ["eventPropertyIdent",
322
+ # ["keywordAllowedIdent", "PINChangeEvent"]]],
323
+ # ".",
324
+ # ["eventPropertyAtomic",
325
+ # ["eventPropertyIdent",
326
+ # ["keywordAllowedIdent", "size"]]]]]]]]]]]]]]]]],
327
+ # ",",
328
+ # ["classIdentifier", ["escapableStr", "double"]],
329
+ # ")"]]]]],
330
+ # ">",
331
+ # ["concatenationExpr",
332
+ # ["additiveExpression",
333
+ # ["multiplyExpression",
334
+ # ["unaryExpression",
335
+ # ["constant",
336
+ # ["numberconstant", ["number", "10.5"]]]]]]]]]]]]]]]],
337
+ # "<EOF>"]
54
338
 
55
339
  ### SELECT count(*) AS cnt
56
340
  ### FROM TestTable.win:time_batch(10 sec)
57
341
  ### WHERE params.$$path.$1="/" AND size.$0.bytes > 100 and opts.num.seq.length() > 0
58
342
 
59
- # ["EPL_EXPR",
60
- # ["SELECTION_EXPR", ["SELECTION_ELEMENT_EXPR", "count", "cnt"]],
61
- # ["STREAM_EXPR",
62
- # ["EVENT_FILTER_EXPR", "TestTable"],
63
- # ["VIEW_EXPR", "win", "time_batch", ["TIME_PERIOD", ["SECOND_PART", "10"]]]],
64
- # ["WHERE_EXPR",
65
- # ["EVAL_AND_EXPR",
66
- # ["EVAL_EQUALS_EXPR",
67
- # ["EVENT_PROP_EXPR",
68
- # ["EVENT_PROP_SIMPLE", "params"],
69
- # ["EVENT_PROP_SIMPLE", "$$path"],
70
- # ["EVENT_PROP_SIMPLE", "$1"]],
71
- # "\"/\""],
72
- # [">",
73
- # ["EVENT_PROP_EXPR",
74
- # ["EVENT_PROP_SIMPLE", "size"],
75
- # ["EVENT_PROP_SIMPLE", "$0"],
76
- # ["EVENT_PROP_SIMPLE", "bytes"]],
77
- # "100"],
78
- # [">",
79
- # ["LIB_FUNC_CHAIN", ["LIB_FUNCTION", "opts.num.seq", "length", "("]],
80
- # "0"]]]]
343
+ # ["startEPLExpressionRule",
344
+ # ["eplExpression",
345
+ # ["selectExpr",
346
+ # "SELECT",
347
+ # ["selectClause",
348
+ # ["selectionList",
349
+ # ["selectionListElement",
350
+ # ["selectionListElementExpr",
351
+ # ["expression",
352
+ # ["caseExpression",
353
+ # ["evalOrExpression",
354
+ # ["evalAndExpression",
355
+ # ["bitWiseExpression",
356
+ # ["negatedExpression",
357
+ # ["evalEqualsExpression",
358
+ # ["evalRelationalExpression",
359
+ # ["concatenationExpr",
360
+ # ["additiveExpression",
361
+ # ["multiplyExpression",
362
+ # ["unaryExpression",
363
+ # ["builtinFunc", "count", "(", "*", ")"]]]]]]]]]]]]],
364
+ # "AS",
365
+ # ["keywordAllowedIdent", "cnt"]]]]],
366
+ # "FROM",
367
+ # ["fromClause",
368
+ # ["streamExpression",
369
+ # ["eventFilterExpression",
370
+ # ["classIdentifier", ["escapableStr", "TestTable"]]],
371
+ # ".",
372
+ # ["viewExpression",
373
+ # "win",
374
+ # ":",
375
+ # "time_batch",
376
+ # "(",
377
+ # ["expressionWithTimeList",
378
+ # ["expressionWithTimeInclLast",
379
+ # ["expressionWithTime",
380
+ # ["timePeriod",
381
+ # ["secondPart", ["numberconstant", ["number", "10"]], "sec"]]]]],
382
+ # ")"]],
383
+ # "regularJoin"],
384
+ # "WHERE",
385
+ # ["whereClause",
386
+ # ["evalOrExpression",
387
+ # ["evalAndExpression",
388
+ # ["bitWiseExpression",
389
+ # ["negatedExpression",
390
+ # ["evalEqualsExpression",
391
+ # ["evalRelationalExpression",
392
+ # ["concatenationExpr",
393
+ # ["additiveExpression",
394
+ # ["multiplyExpression",
395
+ # ["unaryExpression",
396
+ # ["eventPropertyOrLibFunction",
397
+ # ["eventProperty",
398
+ # ["eventPropertyAtomic",
399
+ # ["eventPropertyIdent", ["keywordAllowedIdent", "params"]]],
400
+ # ".",
401
+ # ["eventPropertyAtomic",
402
+ # ["eventPropertyIdent", ["keywordAllowedIdent", "$$path"]]],
403
+ # ".",
404
+ # ["eventPropertyAtomic",
405
+ # ["eventPropertyIdent", ["keywordAllowedIdent", "$1"]]]]]]]]]],
406
+ # "=",
407
+ # ["evalRelationalExpression",
408
+ # ["concatenationExpr",
409
+ # ["additiveExpression",
410
+ # ["multiplyExpression",
411
+ # ["unaryExpression",
412
+ # ["constant", ["stringconstant", "\"/\""]]]]]]]]]],
413
+ # "AND",
414
+ # ["bitWiseExpression",
415
+ # ["negatedExpression",
416
+ # ["evalEqualsExpression",
417
+ # ["evalRelationalExpression",
418
+ # ["concatenationExpr",
419
+ # ["additiveExpression",
420
+ # ["multiplyExpression",
421
+ # ["unaryExpression",
422
+ # ["eventPropertyOrLibFunction",
423
+ # ["eventProperty",
424
+ # ["eventPropertyAtomic",
425
+ # ["eventPropertyIdent", ["keywordAllowedIdent", "size"]]],
426
+ # ".",
427
+ # ["eventPropertyAtomic",
428
+ # ["eventPropertyIdent", ["keywordAllowedIdent", "$0"]]],
429
+ # ".",
430
+ # ["eventPropertyAtomic",
431
+ # ["eventPropertyIdent",
432
+ # ["keywordAllowedIdent", "bytes"]]]]]]]]],
433
+ # ">",
434
+ # ["concatenationExpr",
435
+ # ["additiveExpression",
436
+ # ["multiplyExpression",
437
+ # ["unaryExpression",
438
+ # ["constant", ["numberconstant", ["number", "100"]]]]]]]]]]],
439
+ # "and",
440
+ # ["bitWiseExpression",
441
+ # ["negatedExpression",
442
+ # ["evalEqualsExpression",
443
+ # ["evalRelationalExpression",
444
+ # ["concatenationExpr",
445
+ # ["additiveExpression",
446
+ # ["multiplyExpression",
447
+ # ["unaryExpression",
448
+ # ["eventPropertyOrLibFunction",
449
+ # ["libFunction",
450
+ # ["libFunctionWithClass",
451
+ # ["classIdentifier",
452
+ # ["escapableStr", "opts"],
453
+ # ".",
454
+ # ["escapableStr", "num"],
455
+ # ".",
456
+ # ["escapableStr", "seq"]],
457
+ # ".",
458
+ # ["funcIdentTop", ["escapableIdent", "length"]],
459
+ # "(",
460
+ # ")"]]]]]]],
461
+ # ">",
462
+ # ["concatenationExpr",
463
+ # ["additiveExpression",
464
+ # ["multiplyExpression",
465
+ # ["unaryExpression",
466
+ # ["constant", ["numberconstant", ["number", "0"]]]]]]]]]]]]]]]],
467
+ # "<EOF>"]
81
468
 
82
469
  ### SELECT a.name, a.content, b.content
83
470
  ### FROM pattern[every a=EventA -> b=EventA(name = a.name, type = 'TYPE') WHERE timer:within(1 min)].win:time(2 hour)
84
471
  ### WHERE a.source in ('A', 'B')
85
472
 
86
- # ["EPL_EXPR",
87
- # ["SELECTION_EXPR",
88
- # ["SELECTION_ELEMENT_EXPR",
89
- # ["EVENT_PROP_EXPR",
90
- # ["EVENT_PROP_SIMPLE", "a"],
91
- # ["EVENT_PROP_SIMPLE", "name"]]],
92
- # ["SELECTION_ELEMENT_EXPR",
93
- # ["EVENT_PROP_EXPR",
94
- # ["EVENT_PROP_SIMPLE", "a"],
95
- # ["EVENT_PROP_SIMPLE", "content"]]],
96
- # ["SELECTION_ELEMENT_EXPR",
97
- # ["EVENT_PROP_EXPR",
98
- # ["EVENT_PROP_SIMPLE", "b"],
99
- # ["EVENT_PROP_SIMPLE", "content"]]]],
100
- # ["STREAM_EXPR",
101
- # ["PATTERN_INCL_EXPR",
102
- # ["FOLLOWED_BY_EXPR",
103
- # ["FOLLOWED_BY_ITEM", ["every", ["PATTERN_FILTER_EXPR", "a", "EventA"]]],
104
- # ["FOLLOWED_BY_ITEM",
105
- # ["GUARD_EXPR",
106
- # ["PATTERN_FILTER_EXPR",
107
- # "b",
108
- # "EventA",
109
- # ["EVAL_EQUALS_EXPR",
110
- # ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "name"]],
111
- # ["EVENT_PROP_EXPR",
112
- # ["EVENT_PROP_SIMPLE", "a"],
113
- # ["EVENT_PROP_SIMPLE", "name"]]],
114
- # ["EVAL_EQUALS_EXPR",
115
- # ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "type"]],
116
- # "'TYPE'"]],
117
- # "timer",
118
- # "within",
119
- # ["TIME_PERIOD", ["MINUTE_PART", "1"]]]]]],
120
- # ["VIEW_EXPR", "win", "time", ["TIME_PERIOD", ["HOUR_PART", "2"]]]],
121
- # ["WHERE_EXPR",
122
- # ["in",
123
- # ["EVENT_PROP_EXPR",
124
- # ["EVENT_PROP_SIMPLE", "a"],
125
- # ["EVENT_PROP_SIMPLE", "source"]],
126
- # "(",
127
- # "'A'",
128
- # "'B'",
129
- # ")"]]]
473
+ # ["startEPLExpressionRule",
474
+ # ["eplExpression",
475
+ # ["selectExpr",
476
+ # "SELECT",
477
+ # ["selectClause",
478
+ # ["selectionList",
479
+ # ["selectionListElement",
480
+ # ["selectionListElementExpr",
481
+ # ["expression",
482
+ # ["caseExpression",
483
+ # ["evalOrExpression",
484
+ # ["evalAndExpression",
485
+ # ["bitWiseExpression",
486
+ # ["negatedExpression",
487
+ # ["evalEqualsExpression",
488
+ # ["evalRelationalExpression",
489
+ # ["concatenationExpr",
490
+ # ["additiveExpression",
491
+ # ["multiplyExpression",
492
+ # ["unaryExpression",
493
+ # ["eventPropertyOrLibFunction",
494
+ # ["eventProperty",
495
+ # ["eventPropertyAtomic",
496
+ # ["eventPropertyIdent", ["keywordAllowedIdent", "a"]]],
497
+ # ".",
498
+ # ["eventPropertyAtomic",
499
+ # ["eventPropertyIdent",
500
+ # ["keywordAllowedIdent", "name"]]]]]]]]]]]]]]]]]]],
501
+ # ",",
502
+ # ["selectionListElement",
503
+ # ["selectionListElementExpr",
504
+ # ["expression",
505
+ # ["caseExpression",
506
+ # ["evalOrExpression",
507
+ # ["evalAndExpression",
508
+ # ["bitWiseExpression",
509
+ # ["negatedExpression",
510
+ # ["evalEqualsExpression",
511
+ # ["evalRelationalExpression",
512
+ # ["concatenationExpr",
513
+ # ["additiveExpression",
514
+ # ["multiplyExpression",
515
+ # ["unaryExpression",
516
+ # ["eventPropertyOrLibFunction",
517
+ # ["eventProperty",
518
+ # ["eventPropertyAtomic",
519
+ # ["eventPropertyIdent", ["keywordAllowedIdent", "a"]]],
520
+ # ".",
521
+ # ["eventPropertyAtomic",
522
+ # ["eventPropertyIdent",
523
+ # ["keywordAllowedIdent", "content"]]]]]]]]]]]]]]]]]]],
524
+ # ",",
525
+ # ["selectionListElement",
526
+ # ["selectionListElementExpr",
527
+ # ["expression",
528
+ # ["caseExpression",
529
+ # ["evalOrExpression",
530
+ # ["evalAndExpression",
531
+ # ["bitWiseExpression",
532
+ # ["negatedExpression",
533
+ # ["evalEqualsExpression",
534
+ # ["evalRelationalExpression",
535
+ # ["concatenationExpr",
536
+ # ["additiveExpression",
537
+ # ["multiplyExpression",
538
+ # ["unaryExpression",
539
+ # ["eventPropertyOrLibFunction",
540
+ # ["eventProperty",
541
+ # ["eventPropertyAtomic",
542
+ # ["eventPropertyIdent", ["keywordAllowedIdent", "b"]]],
543
+ # ".",
544
+ # ["eventPropertyAtomic",
545
+ # ["eventPropertyIdent",
546
+ # ["keywordAllowedIdent", "content"]]]]]]]]]]]]]]]]]]]]],
547
+ # "FROM",
548
+ # ["fromClause",
549
+ # ["streamExpression",
550
+ # ["patternInclusionExpression",
551
+ # "pattern",
552
+ # "[",
553
+ # ["patternExpression",
554
+ # ["followedByExpression",
555
+ # ["orExpression",
556
+ # ["andExpression",
557
+ # ["matchUntilExpression",
558
+ # ["qualifyExpression",
559
+ # "every",
560
+ # ["guardPostFix",
561
+ # ["atomicExpression",
562
+ # ["patternFilterExpression",
563
+ # "a",
564
+ # "=",
565
+ # ["classIdentifier", ["escapableStr", "EventA"]]]]]]]]],
566
+ # ["followedByRepeat",
567
+ # "->",
568
+ # ["orExpression",
569
+ # ["andExpression",
570
+ # ["matchUntilExpression",
571
+ # ["qualifyExpression",
572
+ # ["guardPostFix",
573
+ # ["atomicExpression",
574
+ # ["patternFilterExpression",
575
+ # "b",
576
+ # "=",
577
+ # ["classIdentifier", ["escapableStr", "EventA"]],
578
+ # "(",
579
+ # ["expressionList",
580
+ # ["expression",
581
+ # ["caseExpression",
582
+ # ["evalOrExpression",
583
+ # ["evalAndExpression",
584
+ # ["bitWiseExpression",
585
+ # ["negatedExpression",
586
+ # ["evalEqualsExpression",
587
+ # ["evalRelationalExpression",
588
+ # ["concatenationExpr",
589
+ # ["additiveExpression",
590
+ # ["multiplyExpression",
591
+ # ["unaryExpression",
592
+ # ["eventPropertyOrLibFunction",
593
+ # ["eventProperty",
594
+ # ["eventPropertyAtomic",
595
+ # ["eventPropertyIdent",
596
+ # ["keywordAllowedIdent", "name"]]]]]]]]]],
597
+ # "=",
598
+ # ["evalRelationalExpression",
599
+ # ["concatenationExpr",
600
+ # ["additiveExpression",
601
+ # ["multiplyExpression",
602
+ # ["unaryExpression",
603
+ # ["eventPropertyOrLibFunction",
604
+ # ["eventProperty",
605
+ # ["eventPropertyAtomic",
606
+ # ["eventPropertyIdent",
607
+ # ["keywordAllowedIdent", "a"]]],
608
+ # ".",
609
+ # ["eventPropertyAtomic",
610
+ # ["eventPropertyIdent",
611
+ # ["keywordAllowedIdent",
612
+ # "name"]]]]]]]]]]]]]]]]],
613
+ # ",",
614
+ # ["expression",
615
+ # ["caseExpression",
616
+ # ["evalOrExpression",
617
+ # ["evalAndExpression",
618
+ # ["bitWiseExpression",
619
+ # ["negatedExpression",
620
+ # ["evalEqualsExpression",
621
+ # ["evalRelationalExpression",
622
+ # ["concatenationExpr",
623
+ # ["additiveExpression",
624
+ # ["multiplyExpression",
625
+ # ["unaryExpression",
626
+ # ["eventPropertyOrLibFunction",
627
+ # ["eventProperty",
628
+ # ["eventPropertyAtomic",
629
+ # ["eventPropertyIdent",
630
+ # ["keywordAllowedIdent", "type"]]]]]]]]]],
631
+ # "=",
632
+ # ["evalRelationalExpression",
633
+ # ["concatenationExpr",
634
+ # ["additiveExpression",
635
+ # ["multiplyExpression",
636
+ # ["unaryExpression",
637
+ # ["constant",
638
+ # ["stringconstant", "'TYPE'"]]]]]]]]]]]]]]],
639
+ # ")"]],
640
+ # "WHERE",
641
+ # ["guardWhereExpression",
642
+ # "timer",
643
+ # ":",
644
+ # "within",
645
+ # "(",
646
+ # ["expressionWithTimeList",
647
+ # ["expressionWithTimeInclLast",
648
+ # ["expressionWithTime",
649
+ # ["timePeriod",
650
+ # ["minutePart",
651
+ # ["numberconstant", ["number", "1"]],
652
+ # "min"]]]]],
653
+ # ")"]]]]]]]]],
654
+ # "]"],
655
+ # ".",
656
+ # ["viewExpression",
657
+ # "win",
658
+ # ":",
659
+ # "time",
660
+ # "(",
661
+ # ["expressionWithTimeList",
662
+ # ["expressionWithTimeInclLast",
663
+ # ["expressionWithTime",
664
+ # ["timePeriod",
665
+ # ["hourPart", ["numberconstant", ["number", "2"]], "hour"]]]]],
666
+ # ")"]],
667
+ # "regularJoin"],
668
+ # "WHERE",
669
+ # ["whereClause",
670
+ # ["evalOrExpression",
671
+ # ["evalAndExpression",
672
+ # ["bitWiseExpression",
673
+ # ["negatedExpression",
674
+ # ["evalEqualsExpression",
675
+ # ["evalRelationalExpression",
676
+ # ["concatenationExpr",
677
+ # ["additiveExpression",
678
+ # ["multiplyExpression",
679
+ # ["unaryExpression",
680
+ # ["eventPropertyOrLibFunction",
681
+ # ["eventProperty",
682
+ # ["eventPropertyAtomic",
683
+ # ["eventPropertyIdent", ["keywordAllowedIdent", "a"]]],
684
+ # ".",
685
+ # ["eventPropertyAtomic",
686
+ # ["eventPropertyIdent",
687
+ # ["keywordAllowedIdent", "source"]]]]]]]]],
688
+ # "in",
689
+ # "(",
690
+ # ["expression",
691
+ # ["caseExpression",
692
+ # ["evalOrExpression",
693
+ # ["evalAndExpression",
694
+ # ["bitWiseExpression",
695
+ # ["negatedExpression",
696
+ # ["evalEqualsExpression",
697
+ # ["evalRelationalExpression",
698
+ # ["concatenationExpr",
699
+ # ["additiveExpression",
700
+ # ["multiplyExpression",
701
+ # ["unaryExpression",
702
+ # ["constant", ["stringconstant", "'A'"]]]]]]]]]]]]]],
703
+ # ",",
704
+ # ["expression",
705
+ # ["caseExpression",
706
+ # ["evalOrExpression",
707
+ # ["evalAndExpression",
708
+ # ["bitWiseExpression",
709
+ # ["negatedExpression",
710
+ # ["evalEqualsExpression",
711
+ # ["evalRelationalExpression",
712
+ # ["concatenationExpr",
713
+ # ["additiveExpression",
714
+ # ["multiplyExpression",
715
+ # ["unaryExpression",
716
+ # ["constant", ["stringconstant", "'B'"]]]]]]]]]]]]]],
717
+ # ")"]]]]]]]]],
718
+ # "<EOF>"]
130
719
 
131
720
  def astnode(tree)
132
- children = if tree.children
133
- tree.children.map{|c| astnode(c)}
134
- else
135
- []
136
- end
137
- cls = case tree.text
138
- when 'EVENT_PROP_EXPR' then ASTEventPropNode
139
- when 'SELECTION_ELEMENT_EXPR' then ASTSelectionElementNode
140
- when 'LIB_FUNCTION' then ASTLibFunctionNode
141
- when 'STREAM_EXPR' then ASTStreamNode
142
- when 'PATTERN_FILTER_EXPR' then ASTPatternNode
143
- when 'SUBSELECT_EXPR' then ASTSubSelectNode
721
+ # com.espertech.esper.epl.generated.EsperEPL2GrammarParser.ruleNames[ast.ruleIndex] #=> "startEPLExpressionRule"
722
+ # com.espertech.esper.epl.generated.EsperEPL2GrammarParser.ruleNames[ast.getChild(0).ruleIndex] #=> "eplExpression"
723
+
724
+ # ast.getChild(0).getChild(0).ruleIndex #=> 15
725
+ # com.espertech.esper.epl.generated.EsperEPL2GrammarParser.ruleNames[ast.getChild(0).getChild(0).ruleIndex] #=> "selectExpr"
726
+ # ast.getChild(0).getChild(0).getChild(0).symbol.text #=> 'select'
727
+ # ast.getChild(0).getChild(0).getChild(0).symbol.type #=> 24
728
+
729
+ # [23] pry(main)> ast.getChild(0).getChild(1)
730
+ # => nil
731
+ # [24] pry(main)> ast.getChild(0).getChild(0).getChild(1)
732
+ # => #<Java::ComEspertechEsperEplGenerated::EsperEPL2GrammarParser::SelectClauseContext:0x6437693>
733
+ # [25] pry(main)> ast.getChild(0).getChild(0).getChild(1).getChild(0)
734
+ # => #<Java::ComEspertechEsperEplGenerated::EsperEPL2GrammarParser::SelectionListContext:0x5de28c04>
735
+
736
+ name = if tree.respond_to?(:getRuleIndex)
737
+ Java::ComEspertechEsperEplGenerated::EsperEPL2GrammarParser.ruleNames[tree.getRuleIndex]
738
+ else
739
+ tree.symbol.text
740
+ end
741
+ children = []
742
+ tree.childCount.times do |i|
743
+ child = tree.getChild(i)
744
+ children << astnode(child) if child
745
+ end
746
+
747
+ cls = case name
748
+ when 'eventProperty' then ASTEventPropNode
749
+ when 'selectionListElementExpr' then ASTSelectionElementNode
750
+ when 'libFunction' then ASTLibFunctionNode
751
+ when 'streamExpression', 'subSelectFilterExpr' then ASTStreamNode
752
+ when 'patternFilterExpression' then ASTPatternNode
753
+ when 'subQueryExpr' then ASTSubSelectNode
144
754
  else ASTNode
145
755
  end
146
756
  if cls.respond_to?(:generate)
147
- cls.generate(tree.text, children, tree)
757
+ cls.generate(name, children, tree)
148
758
  else
149
- cls.new(tree.text, children, tree)
759
+ cls.new(name, children, tree)
150
760
  end
151
761
  end
152
762
 
@@ -203,117 +813,292 @@ module Norikra
203
813
  end
204
814
  end
205
815
 
206
- class ASTEventPropNode < ASTNode # EVENT_PROP_EXPR
207
- # "bbb" => ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "bbb"]]
208
- # "fraud.aaa" => ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "fraud"], ["EVENT_PROP_SIMPLE", "aaa"]]
209
- # "size.$0.bytes" => ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "size"], ["EVENT_PROP_SIMPLE", "$0"], ["EVENT_PROP_SIMPLE", "bytes"]]
210
- # "field.index("?")" => ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "path"], ["EVENT_PROP_MAPPED", "index", "\"?\""]]
211
- # "field.f1.index(".")" => ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "path"], ["EVENT_PROP_SIMPLE", "q1"], ["EVENT_PROP_MAPPED", "index", "\".\""]]
816
+ class ASTEventPropNode < ASTNode # eventProperty
817
+ ### "a"
818
+ # ["eventProperty", ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "a"]]]
819
+
820
+ ### "fraud.aaa"
821
+ # ["eventProperty",
822
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "fraud"]]],
823
+ # ".",
824
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "aaa"]]]]
825
+
826
+ ### "size.$0.bytes"
827
+ # ["eventProperty",
828
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "size"]]],
829
+ # ".",
830
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "$0"]]],
831
+ # ".",
832
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "bytes"]]]]
833
+
834
+ ### "field.index("?")"
835
+ # ["eventProperty",
836
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "field"]]],
837
+ # ".",
838
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "index"]], "(", "'?'", ")"]]
839
+
840
+ ### "field.f1.index(".")"
841
+ # ["eventProperty",
842
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "field"]]],
843
+ # ".",
844
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "f1"]]],
845
+ # ".",
846
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "index"]], "(", "'.'", ")"]]
212
847
 
213
848
  #### 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`"]]
849
+
850
+ ### "`path name`"
851
+ # ["eventProperty", ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "`field name`"]]]]
852
+
853
+ ### "`T Table`.`path name`"
854
+ # ["eventProperty",
855
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "`T table`"]]],
856
+ # ".",
857
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "`path name`"]]]]
858
+
859
+ ### "`size.num`"
860
+ # ["eventProperty", ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "`size.num`"]]]]
217
861
 
218
862
  def nodetype?(*sym)
219
863
  sym.include?(:prop) || sym.include?(:property)
220
864
  end
221
865
 
222
866
  def fields(default_target=nil, known_targets_aliases=[])
223
- props = self.listup('EVENT_PROP_SIMPLE')
867
+ props = self.listup('eventPropertyAtomic')
868
+ leading_name = props[0].find('eventPropertyIdent').find('keywordAllowedIdent').child.name
869
+
224
870
  if props.size > 1 # alias.fieldname or container_fieldname.key.$1 or fieldname.method(...)
225
- if known_targets_aliases.include?(props[0].child.name)
226
- [ {:f => props[1..-1].map{|n| n.child.name}.join("."), :t => props[0].child.name} ]
871
+ non_calls = props.select{|p| p.children.size == 1 }.map{|p| p.find('eventPropertyIdent').find('keywordAllowedIdent').child.name }
872
+ if known_targets_aliases.include?(leading_name)
873
+ [ {:f => non_calls[1..-1].join("."), :t => leading_name} ]
227
874
  else
228
- [ {:f => props.map{|n| n.child.name}.join("."), :t => default_target} ]
875
+ [ {:f => non_calls.join("."), :t => default_target} ]
229
876
  end
230
877
  else # fieldname (default target)
231
- [ {:f => props[0].child.name, :t => default_target } ]
878
+ # ["eventProperty", ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "a"]]]
879
+ [ {:f => leading_name, :t => default_target } ]
232
880
  end
233
881
  end
234
882
  end
235
883
 
236
- class ASTSelectionElementNode < ASTNode # SELECTION_ELEMENT_EXPR
237
- # "count(*) AS cnt" => ["SELECTION_ELEMENT_EXPR", "count", "cnt"]
238
- # "n.s as s" => ["SELECTION_ELEMENT_EXPR", ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "n"], ["EVENT_PROP_SIMPLE", "s"]], "s"]
884
+ class ASTSelectionElementNode < ASTNode # selectionListElementExpr
885
+ ### "s"
886
+ # ["selectionListElement",
887
+ # ["selectionListElementExpr",
888
+ # ["expression",
889
+ # ["caseExpression", ["evalOrExpression", ["evalAndExpression", ["bitWiseExpression", ["negatedExpression",
890
+ # ["evalEqualsExpression", ["evalRelationalExpression", ["concatenationExpr", ["additiveExpression",
891
+ # ["multiplyExpression", ["unaryExpression", ["eventPropertyOrLibFunction",
892
+ # ["eventProperty",
893
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "s"]]]]]]]]]]]]]]]]]]]
894
+
895
+ ### "count(*) AS cnt" => ["SELECTION_ELEMENT_EXPR", "count", "cnt"]
896
+ # ["selectionListElementExpr",
897
+ # ["expression",
898
+ # ["caseExpression", ["evalOrExpression", ["evalAndExpression", ["bitWiseExpression", ["negatedExpression",
899
+ # ["evalEqualsExpression", ["evalRelationalExpression", ["concatenationExpr", ["additiveExpression",
900
+ # ["multiplyExpression", ["unaryExpression",
901
+ # ["builtinFunc", "count", "(", "*", ")"]]]]]]]]]]]]],
902
+ # "AS",
903
+ # ["keywordAllowedIdent", "cnt"]]
904
+
905
+ ### "n.s as s"
906
+ # ["selectionListElementExpr",
907
+ # ["expression",
908
+ # ["caseExpression", ["evalOrExpression", ["evalAndExpression", ["bitWiseExpression", ["negatedExpression",
909
+ # ["evalEqualsExpression", ["evalRelationalExpression", ["concatenationExpr", ["additiveExpression",
910
+ # ["multiplyExpression", ["unaryExpression", ["eventPropertyOrLibFunction",
911
+ # ["eventProperty",
912
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "n"]]],
913
+ # ".",
914
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "s"]]]]]]]]]]]]]]]]],
915
+ # "as",
916
+ # ["keywordAllowedIdent", "s"]]]
917
+
239
918
  def nodetype?(*sym)
240
919
  sym.include?(:selection)
241
920
  end
242
921
 
243
922
  def alias
244
- @children.size == 2 ? @children[1].name : nil
923
+ @children.size == 3 && @children[1].name.downcase == 'as' ? @children[2].child.name : nil
245
924
  end
246
925
  end
247
926
 
248
927
  class ASTLibFunctionNode < ASTNode # LIB_FUNCTION
249
928
  ### foo is function
250
- # "foo()" => ["LIB_FUNCTION", "foo", "("]
251
- # "foo(10)" => ["LIB_FUNCTION", "foo", "10", "("]
252
- # "foo(10,0)" => ["LIB_FUNCTION", "foo", "10", "0", "("]
253
- # "foo(bar)" => ["LIB_FUNCTION", "foo", ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "bar"]], "("]
929
+ # "foo()" => ["libFunction", ["libFunctionWithClass", ["funcIdentTop", ["escapableIdent", "foo"]], "(", ")"]]
930
+
931
+ ### "foo(10)"
932
+ # ["libFunction",
933
+ # ["libFunctionWithClass",
934
+ # ["funcIdentTop", ["escapableIdent", "foo"]],
935
+ # "(",
936
+ # ["libFunctionArgs",
937
+ # ["libFunctionArgItem", ["expressionWithTime", ["expressionQualifyable", ["expression", EXPRESSION... ]]]]]
938
+ # ")"]]
939
+
940
+ ### "foo(10,0)"
941
+ # ["libFunction",
942
+ # ["libFunctionWithClass",
943
+ # ["funcIdentTop", ["escapableIdent", "foo"]],
944
+ # "(",
945
+ # ["libFunctionArgs",
946
+ # ["libFunctionArgItem", ["expressionWithTime", ["expressionQualifyable", ["expression", EXPRESSION... ]]]],
947
+ # ",",
948
+ # ["libFunctionArgItem", ["expressionWithTime", ["expressionQualifyable", ["expression", EXPRESSION... ]]]]],
949
+ # ")"]]
254
950
 
255
951
  ### foo is property
256
- # "foo.bar()" => ["LIB_FUNCTION", "foo", "bar", "("]
257
- # "foo.bar(0)" => ["LIB_FUNCTION", "foo", "bar", "0", "("]
258
- # "foo.bar(0,8)" => ["LIB_FUNCTION", "foo", "bar", "0", "8", "("]
952
+ ### "foo.bar()"
953
+ # ["libFunction",
954
+ # ["libFunctionWithClass",
955
+ # ["classIdentifier", ["escapableStr", "foo"]],
956
+ # ".",
957
+ # ["funcIdentTop", ["escapableIdent", "bar"]],
958
+ # "(",
959
+ # ")"]]
259
960
 
260
- ### nested field access
261
- # "foo.bar.$0.baz()" => ["LIB_FUNCTION", "foo.bar.$0", "baz", "("]
961
+ ### Math.abs()
962
+ # ["libFunction",
963
+ # ["libFunctionWithClass",
964
+ # ["classIdentifier", ["escapableStr", "Math"]],
965
+ # ".",
966
+ # ["funcIdentTop", ["escapableIdent", "abs"]],
967
+ # "(",
968
+ # ["libFunctionArgs",
969
+ # ["libFunctionArgItem",
970
+ # ["expressionWithTime",
971
+ # ["expression", EXPRESSION... ]]]],
972
+ # ")"]]
262
973
 
263
- # 2nd child is bare-word (like [a-z][a-z0-9]*) -> this is function -> 1st child is receiver -> property
264
- # 2nd child is literal or property or none -> 1st child is built-in function
974
+ ### "foo.bar(0)"
975
+ # ["libFunction",
976
+ # ["libFunctionWithClass",
977
+ # ["classIdentifier", ["escapableStr", "foo"]],
978
+ # ".",
979
+ # ["funcIdentTop", ["escapableIdent", "bar"]],
980
+ # "(",
981
+ # ["libFunctionArgs",
982
+ # ["libFunctionArgItem",
983
+ # ["expressionWithTime",
984
+ # ["expressionQualifyable",
985
+ # ["expression", EXPRESSION....
986
+ # ["constant", ["numberconstant", ["number", "0"]]]]]]]],
987
+ # ")"]]
988
+
989
+ ### chain
990
+ ### "field.substr(0).length()"
991
+ # ["libFunction",
992
+ # ["libFunctionWithClass",
993
+ # ["classIdentifier", ["escapableStr", "field"]],
994
+ # ".",
995
+ # ["funcIdentTop", ["escapableIdent", "substr"]],
996
+ # "(",
997
+ # ["libFunctionArgs",
998
+ # ["libFunctionArgItem",
999
+ # ["expressionWithTime",
1000
+ # ["expressionQualifyable",
1001
+ # ["expression", EXPRESSION...,
1002
+ # ["constant", ["numberconstant", ["number", "0"]]]]]]]],
1003
+ # ")"],
1004
+ # ".",
1005
+ # ["libFunctionNoClass",
1006
+ # ["funcIdentChained", ["escapableIdent", "length"]],
1007
+ # "(",
1008
+ # ")"]]
1009
+
1010
+ ### nested function call
1011
+ # ["libFunction",
1012
+ # ["libFunctionWithClass",
1013
+ # ["classIdentifier", ["escapableStr", "Math"]],
1014
+ # ".",
1015
+ # ["funcIdentTop", ["escapableIdent", "abs"]],
1016
+ # "(",
1017
+ # ["libFunctionArgs",
1018
+ # ["libFunctionArgItem",
1019
+ # ["expressionWithTime",
1020
+ # ["expressionQualifyable",
1021
+ # ["expression", EXPRESSION...,
1022
+ # ["eventPropertyOrLibFunction",
1023
+ # ["libFunction",
1024
+ # ["libFunctionWithClass",
1025
+ # ["classIdentifier",
1026
+ # ["escapableStr", "Math"]],
1027
+ # ".",
1028
+ # ["funcIdentTop",
1029
+ # ["escapableIdent", "abs"]],
1030
+ # "(",
1031
+ # ["libFunctionArgs",
1032
+ # ["libFunctionArgItem",
1033
+ # ["expressionWithTime",
1034
+ # ["expressionQualifyable",
1035
+ # ["expression", EXPRESSION...,
1036
+ # ["eventPropertyOrLibFunction",
1037
+ # ["eventProperty",
1038
+ # ["eventPropertyAtomic", ["eventPropertyIdent", ["keywordAllowedIdent", "a"]]]]]]]]]],
1039
+ # ")"]]]]]]]],
1040
+ # ")"]]
1041
+
1042
+ ### nested field access
1043
+ ### "foo.bar.$0.baz()"
1044
+ # ["libFunction",
1045
+ # ["libFunctionWithClass",
1046
+ # ["classIdentifier",
1047
+ # ["escapableStr", "foo"],
1048
+ # ".",
1049
+ # ["escapableStr", "bar"],
1050
+ # ".",
1051
+ # ["escapableStr", "$0"]],
1052
+ # ".",
1053
+ # ["funcIdentTop", ["escapableIdent", "baz"]],
1054
+ # "(",
1055
+ # ")"]]
265
1056
 
266
1057
  ### escaped name access
267
- # "`T Table`.param.length()" => ["LIB_FUNC_CHAIN", ["LIB_FUNCTION", "TestTable Testing.param", "length", "("]]
268
- ## Oops! we CANNOT support this syntax
1058
+ # "`T Table`.param.length()"
1059
+ # ["libFunction",
1060
+ # ["libFunctionWithClass",
1061
+ # ["classIdentifier",
1062
+ # ["escapableStr", "`T Table`"],
1063
+ # ".",
1064
+ # ["escapableStr", "param"]],
1065
+ # ".",
1066
+ # ["funcIdentTop", ["escapableIdent", "length"]],
1067
+ # "(",
1068
+ # ")"]]
269
1069
 
270
1070
  def nodetype?(*sym)
271
1071
  sym.include?(:lib) || sym.include?(:libfunc)
272
1072
  end
273
1073
 
274
1074
  def fields(default_target=nil, known_targets_aliases=[])
275
- if @children.size <= 2
276
- # single function like 'now()', function-name and "("
277
- []
1075
+ identifier = self.find("classIdentifier")
278
1076
 
279
- elsif @children[1].nodetype?(:prop, :lib, :subquery)
280
- # first element should be func name if second element is property, library call or subqueries
281
- self.listup('EVENT_PROP_EXPR').map{|c| c.fields(default_target, known_targets_aliases)}.reduce(&:+) || []
1077
+ return [] if identifier.nil? # built-in function call (no receivers exists)
282
1078
 
283
- elsif @children[1].name =~ /^(-)?\d+(\.\d+)?$/ || @children[1].name =~ /^'[^']*'$/ || @children[1].name =~ /^"[^"]*"$/
284
- # first element should be func name if secod element is number/string literal
285
- self.listup('EVENT_PROP_EXPR').map{|c| c.fields(default_target, known_targets_aliases)}.reduce(&:+) || []
286
-
287
- elsif Norikra::Query.imported_java_class?(@children[0].name)
1079
+ if identifier.children.size == 1 && Norikra::Query.imported_java_class?(identifier.find("escapableStr").child.name)
288
1080
  # Java imported class name (ex: 'Math.abs(-1)')
289
- self.listup('EVENT_PROP_EXPR').map{|c| c.fields(default_target, known_targets_aliases)}.reduce(&:+) || []
290
-
1081
+ self.listup(:prop).map{|c| c.fields(default_target, known_targets_aliases)}.reduce(&:+) || []
291
1082
  else
292
- # first element may be property ########## or function
293
- # * simple 'fieldname.funcname()'
294
- # * fully qualified 'target.fieldname.funcname()'
295
- # * simple/fully-qualified container field access 'fieldname.key.$0.funcname()' or 'target.fieldname.$1.funcname()'
296
- target,fieldname = if @children[0].name.include?('.')
297
- parts = @children[0].name.split('.')
298
- if known_targets_aliases.include?(parts[0])
299
- [ parts[0], parts[1..-1].join(".") ]
300
- else
301
- [ default_target, @children[0].name ]
302
- end
303
- else
304
- [default_target,@children[0].name]
305
- end
306
- children_list = self.listup('EVENT_PROP_EXPR').map{|c| c.fields(default_target, known_targets_aliases)}.reduce(&:+) || []
1083
+ parts = identifier.listup('escapableStr').map{|node| node.child.name }
1084
+ target, fieldname = if parts.size == 1
1085
+ [ default_target, parts.first ]
1086
+ elsif known_targets_aliases.include?( parts.first )
1087
+ [ parts[0], parts[1..-1].join(".") ]
1088
+ else
1089
+ [ default_target, parts.join(".") ]
1090
+ end
1091
+ children_list = self.listup(:prop).map{|c| c.fields(default_target, known_targets_aliases)}.reduce(&:+) || []
307
1092
  [{:f => fieldname, :t => target}] + children_list
308
1093
  end
309
1094
  end
310
1095
  end
311
1096
 
312
- class ASTStreamNode < ASTNode # STREAM_EXPR
1097
+ class ASTStreamNode < ASTNode # streamExpression, subSelectFilterExpr
313
1098
  def self.generate(name, children, tree)
314
- if children.first.name == 'EVENT_FILTER_EXPR'
1099
+ if children.first.name == 'eventFilterExpression'
315
1100
  ASTStreamEventNode.new(name, children, tree)
316
- elsif children.first.name == 'PATTERN_INCL_EXPR'
1101
+ elsif children.first.name == 'patternInclusionExpression'
317
1102
  ASTStreamPatternNode.new(name, children, tree)
318
1103
  else
319
1104
  raise "unexpected stream node type! report to norikra developer!: #{children.map(&:name).join(',')}"
@@ -344,38 +1129,77 @@ module Norikra
344
1129
  ##### [ stream_def ... ]
345
1130
  #
346
1131
  # single Event stream name ( ex: FROM events.win:time(...) AS e )
347
- #
348
- # ["STREAM_EXPR",
349
- # ["EVENT_FILTER_EXPR", "FraudWarningEvent"],
350
- # ["VIEW_EXPR", "win", "keepall"],
1132
+
1133
+ # ["streamExpression",
1134
+ # ["eventFilterExpression",
1135
+ # ["classIdentifier", ["escapableStr", "TestTable"]]],
1136
+ # ".",
1137
+ # ["viewExpression",
1138
+ # "win",
1139
+ # ":",
1140
+ # "time_batch",
1141
+ # "(",
1142
+ # ["expressionWithTimeList",
1143
+ # ["expressionWithTimeInclLast",
1144
+ # ["expressionWithTime",
1145
+ # ["timePeriod",
1146
+ # ["secondPart", ["numberconstant", ["number", "10"]], "sec"]]]]],
1147
+ # ")"],
1148
+ # "regularJoin",
1149
+
1150
+ # ["streamExpression",
1151
+ # ["eventFilterExpression",
1152
+ # ["classIdentifier", ["escapableStr", "FraudWarningEvent"]]],
1153
+ # ".",
1154
+ # ["viewExpression", "win", ":", "keepall", "(", ")"],
1155
+ # "AS",
351
1156
  # "fraud"],
352
- #
353
- # ["STREAM_EXPR",
354
- # ["EVENT_FILTER_EXPR",
355
- # "PINChangeEvent",
356
- # [">", ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "size"]], "10"]],
357
- # ["VIEW_EXPR", "win", "time", ["TIME_PERIOD", ["SECOND_PART", "20"]]]],
1157
+ # ["regularJoin",
1158
+ # ",",
1159
+ # ["streamExpression",
1160
+ # ["eventFilterExpression",
1161
+ # ["classIdentifier", ["escapableStr", "PINChangeEvent"]],
1162
+ # "(",
1163
+ # ["expressionList",
1164
+ # ["expression", EXPRESSION...]],
1165
+ # ")"],
1166
+ # ".",
1167
+ # ["viewExpression",
1168
+ # "win",
1169
+ # ":",
1170
+ # "time",
1171
+ # "(",
1172
+ # ["expressionWithTimeList",
1173
+ # ["expressionWithTimeInclLast",
1174
+ # ["expressionWithTime",
1175
+ # ["timePeriod",
1176
+ # ["secondPart", ["numberconstant", ["number", "20"]], "sec"]]]]],
1177
+ # ")"]]]],
358
1178
 
359
- NON_ALIAS_NODES = ['EVENT_FILTER_EXPR','VIEW_EXPR','unidirectional','retain-union','retain-intersection']
1179
+ NON_ALIAS_NODES = ['eventFilterExpression','viewExpression','.','unidirectional','retain-union','retain-intersection']
360
1180
 
361
1181
  def targets
362
- [self.find('EVENT_FILTER_EXPR').child.name]
1182
+ [ self.find('eventFilterExpression').find('classIdentifier').find('escapableStr').child.name ]
363
1183
  end
364
1184
 
365
1185
  def aliases
366
1186
  alias_nodes = children.select{|n| not NON_ALIAS_NODES.include?(n.name) }
367
- if alias_nodes.size < 1
1187
+ if alias_nodes.size == 2
1188
+ if alias_nodes[0].name =~ /^as$/i
1189
+ [ [ alias_nodes[1].name, self.targets.first ] ]
1190
+ else
1191
+ raise "unexpected FROM clause (non-AS for alias pattern): #{alias_nodes.map(&:name).join(',')}"
1192
+ end
1193
+ elsif alias_nodes.size == 0
368
1194
  []
369
- elsif alias_nodes.size > 1
370
- raise "unexpected FROM clause (includes 2 or more alias words): #{alias_nodes.map(&:name).join(',')}"
371
- else
372
- [ [ alias_nodes.first.name, self.targets.first ] ]
1195
+ else # 1 or 3 or more
1196
+ raise "unexpected FROM clause (non-AS for alias pattern): #{alias_nodes.map(&:name).join(',')}"
373
1197
  end
374
1198
  end
375
1199
 
376
1200
  def fields(default_target=nil, known_targets_aliases=[])
377
1201
  this_target = self.targets.first
378
- self.listup('EVENT_PROP_EXPR').map{|p| p.fields(this_target,known_targets_aliases)}.reduce(&:+) || []
1202
+ self.listup(:prop).map{|p| p.fields(this_target, known_targets_aliases)}.reduce(&:+) || []
379
1203
  end
380
1204
  end
381
1205
 
@@ -385,28 +1209,48 @@ module Norikra
385
1209
  #
386
1210
  # pattern ( ex: FROM pattern[ every a=events1 -> b=Events1(name=a.name, type='T') where timer:within(1 min) ].win:time(2 hour) )
387
1211
  #
388
- # ["STREAM_EXPR",
389
- # ["PATTERN_INCL_EXPR",
390
- # ["FOLLOWED_BY_EXPR",
391
- # ["FOLLOWED_BY_ITEM", ["every", ["PATTERN_FILTER_EXPR", "a", "EventA"]]],
392
- # ["FOLLOWED_BY_ITEM",
393
- # ["GUARD_EXPR",
394
- # ["PATTERN_FILTER_EXPR",
395
- # "b",
396
- # "EventA",
397
- # ["EVAL_EQUALS_EXPR",
398
- # ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "name"]],
399
- # ["EVENT_PROP_EXPR",
400
- # ["EVENT_PROP_SIMPLE", "a"],
401
- # ["EVENT_PROP_SIMPLE", "name"]]],
402
- # ["EVAL_EQUALS_EXPR",
403
- # ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "type"]],
404
- # "'TYPE'"]],
405
- # "timer",
406
- # "within",
407
- # ["TIME_PERIOD", ["MINUTE_PART", "1"]]]]]],
408
- # ["VIEW_EXPR", "win", "time", ["TIME_PERIOD", ["HOUR_PART", "2"]]]],
409
-
1212
+ #
1213
+ # ["streamExpression",
1214
+ # ["patternInclusionExpression",
1215
+ # "pattern",
1216
+ # "[",
1217
+ # ["patternExpression",
1218
+ # ["followedByExpression",
1219
+ # ["orExpression", ["andExpression",
1220
+ # ["matchUntilExpression", ["qualifyExpression",
1221
+ # "every",
1222
+ # ["guardPostFix",
1223
+ # ["atomicExpression",
1224
+ # ["patternFilterExpression", "a", "=", ["classIdentifier", ["escapableStr", "EventA"]]]]]]]]],
1225
+ # ["followedByRepeat",
1226
+ # "->",
1227
+ # ["orExpression", ["andExpression",
1228
+ # ["matchUntilExpression", ["qualifyExpression",
1229
+ # ["guardPostFix",
1230
+ # ["atomicExpression",
1231
+ # ["patternFilterExpression", "b", "=", ["classIdentifier", ["escapableStr", "EventA"]],
1232
+ # "(",
1233
+ # ["expressionList", ["expression", EXPRESSION...], ",", ["expression", EXPRESSION...]],
1234
+ # ")"],
1235
+ # "WHERE",
1236
+ # ["guardWhereExpression",
1237
+ # "timer",
1238
+ # ":",
1239
+ # "within",
1240
+ # "(",
1241
+ # ["expressionWithTimeList", ["expressionWithTimeInclLast", ["expressionWithTime",
1242
+ # ["timePeriod", ["minutePart", ["numberconstant", ["number", "1"]], "min"]]]]],
1243
+ # ")"]]]]]]]]],
1244
+ # "]"]],
1245
+ # ".",
1246
+ # ["viewExpression",
1247
+ # "win",
1248
+ # ":",
1249
+ # "time",
1250
+ # "(",
1251
+ # ["expressionWithTimeList", ["expressionWithTimeInclLast", ["expressionWithTime",
1252
+ # ["timePeriod", ["hourPart", ["numberconstant", ["number", "2"]], "hour"]]]]],
1253
+ # ")"]],
410
1254
  def targets
411
1255
  self.listup(:pattern).map(&:target)
412
1256
  end
@@ -421,39 +1265,78 @@ module Norikra
421
1265
  end
422
1266
 
423
1267
  class ASTPatternNode < ASTNode
424
- # ["PATTERN_FILTER_EXPR", "a", "EventA"]
425
- #
426
- # ["PATTERN_FILTER_EXPR",
427
- # "b",
428
- # "EventA",
429
- # ["EVAL_EQUALS_EXPR",
430
- # ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "name"]],
431
- # ["EVENT_PROP_EXPR",
432
- # ["EVENT_PROP_SIMPLE", "a"],
433
- # ["EVENT_PROP_SIMPLE", "name"]]],
434
- # ["EVAL_EQUALS_EXPR",
435
- # ["EVENT_PROP_EXPR", ["EVENT_PROP_SIMPLE", "type"]],
436
- # "'TYPE'"]],
1268
+ # ["patternFilterExpression", "a", "=", ["classIdentifier", ["escapableStr", "EventA"]]]
1269
+
1270
+ # ["patternFilterExpression", "b", "=", ["classIdentifier", ["escapableStr", "EventA"]],
1271
+ # "(",
1272
+ # ["expressionList", ["expression", EXPRESSION...], ",", ["expression", EXPRESSION...]],
1273
+ # ")"]
437
1274
 
438
1275
  def nodetype?(*sym)
439
1276
  sym.include?(:pattern)
440
1277
  end
441
1278
 
442
1279
  def target
443
- children[1].name
1280
+ self.find('classIdentifier').find('escapableStr').child.name
444
1281
  end
445
1282
 
446
1283
  def alias
447
- children[0].name
1284
+ @children[0].name
448
1285
  end
449
1286
 
450
1287
  def fields(default_target=nil, known_targets_aliases=[])
451
1288
  this_target = self.target
452
- self.listup('EVENT_PROP_EXPR').map{|p| p.fields(this_target, known_targets_aliases) }.reduce(&:+) || []
1289
+ self.listup(:prop).map{|p| p.fields(this_target, known_targets_aliases) }.reduce(&:+) || []
453
1290
  end
454
1291
  end
455
1292
 
456
- class ASTSubSelectNode < ASTNode # SUBSELECT_EXPR
1293
+ class ASTSubSelectNode < ASTNode
1294
+ # ["startEPLExpressionRule",
1295
+ # ["eplExpression",
1296
+ # ["selectExpr",
1297
+ # "select",
1298
+ # ["selectClause", ["selectionList", ["selectionListElement", "*"]]],
1299
+ # "from",
1300
+ # ["fromClause",
1301
+ # ["streamExpression", ["eventFilterExpression", ["classIdentifier", ["escapableStr", "RfidEvent"]]], "as", "RFID"],
1302
+ # "regularJoin"],
1303
+ # "where",
1304
+ # ["whereClause",
1305
+ # ["evalOrExpression", ["evalAndExpression", ["bitWiseExpression", ["negatedExpression",
1306
+ # ["evalEqualsExpression", ["evalRelationalExpression", ["concatenationExpr", ["additiveExpression",
1307
+ # ["multiplyExpression", ["unaryExpression",
1308
+ # ["constant", ["stringconstant", "\"Dock 1\""]]]]]]],
1309
+ # "=",
1310
+ # ["evalRelationalExpression",
1311
+ # ["concatenationExpr", ["additiveExpression", ["multiplyExpression", ["unaryExpression",
1312
+ # ["rowSubSelectExpression",
1313
+ # ["subQueryExpr",
1314
+ # "(",
1315
+ # "select",
1316
+ # ["selectionList",
1317
+ # ["selectionListElement",
1318
+ # ["selectionListElementExpr",
1319
+ # ["expression", EXPRESSION...]]]],
1320
+ # "from",
1321
+ # ["subSelectFilterExpr",
1322
+ # ["eventFilterExpression", ["classIdentifier", ["escapableStr", "Zones"]]],
1323
+ # ".",
1324
+ # ["viewExpression",
1325
+ # "std",
1326
+ # ":",
1327
+ # "unique",
1328
+ # "(",
1329
+ # ["expressionWithTimeList",
1330
+ # ["expressionWithTimeInclLast",
1331
+ # ["expressionWithTime",
1332
+ # ["expressionQualifyable",
1333
+ # ["expression", EXPRESSION...]]]]],
1334
+ # ")"]],
1335
+ # "where",
1336
+ # ["whereClause", ...],
1337
+ # ")"]]]]]]]]]]]]]]],
1338
+ # "<EOF>"]
1339
+
457
1340
  def nodetype?(*sym)
458
1341
  sym.include?(:subquery)
459
1342
  end