-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/optional rule name #316
Conversation
CHANGES_NEXT_RELEASE
Outdated
@@ -10,3 +10,4 @@ | |||
* sinon-chai | |||
* grunt and grunt related module | |||
* closure-linter-wrapper | |||
- Add Rule auto-naming on rule creation time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand issue #307 should be mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, #307 should be mentioned. Is enough with these comments?
By the way... it could be that the description that I established in the CNR for this functionality is not the most correct. It would seem appropriate to you if I change it to something like - Add 'ruleName' as variable automatically in rule text field on rule creation time
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think is a good alternative. Maybe an explicit mention to EPL is clarifying. I mean in sum something like this:
- Add 'ruleName' as variable automatically in rule text field (EPL) on rule creation time (#208)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0bfc9a0
|
||
var newAs = '"' + rule.name + '" as ruleName'; | ||
// Add "name as ruleName" if not exist | ||
if (rule.text && rule.text.indexOf(' as ruleName') === -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation should be changed to explain that now the name is not mandatory and which happens if the name is ommited (i.e. an example of autogenerated name would be great).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the documentation but I do not know if I have approached it in the right way, please check if the change seems appropriate. b356343
CHANGES_NEXT_RELEASE
Outdated
@@ -10,3 +10,4 @@ | |||
* sinon-chai | |||
* grunt and grunt related module | |||
* closure-linter-wrapper | |||
- Add 'ruleName' as variable automatically in rule text field (EPL) on rule creation time (#208) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ef4dda6
documentation/plain_rules.md
Outdated
* The *from* pattern must name the event as **ev** and the event stream from which take events must be **iotEvent** | ||
* A *type=* condition must be concatenated for avoiding mixing different kinds of entities | ||
* The name of the rule is not mandatory, but for backward compatibility, it can be present as ** ruleName ** alias (`e.g: select *, "blood_rule_update" as ruleName...`) in the select clause. If present, it must be equal to the ‘name’ field of the rule object. If it is not present, you can still use the variable 'ruleName' in the actions, because it will be included automatically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest split this and include part as in a a remarked "backward compatibility note". In particular I mean:
To leave this in the bullet list:
* The variable 'ruleName' in automatically added to the action, even if it is not present in the EPL text.
**Backward compatibility note:** since version 1.8.0 it is not mandatory to specify the name of the rule as part of the EPL text. In fact, it is not recommendable to do that. However, for backward compatibility, it can be present as *ruleName* alias (`e.g: select *, "blood_rule_update" as ruleName...`) in the select clause. If present, it must be equal to the ‘name’ field of the rule object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 55110fb
@@ -191,7 +191,7 @@ A simplified format in JSON can be used to represent rules. The former visual ru | |||
```json | |||
{ | |||
"name" : "prueba-test", | |||
"text" : "select *,\"prueba-test\" as ruleName from pattern [every ev=iotEvent((cast(id?, String) regexp \"asd\"))]", | |||
"text" : "select * from pattern [every ev=iotEvent((cast(id?, String) regexp \"asd\"))]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doubt: at rule creation time (POST /rules
, if I'm remembering correctly) it is clear that ruleName is not include in the EPL and it is automatically added.
However, what about of GET /rules/:id
? Is would be the automatically added ruleName added there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The ruleName is added during the creation automatically in the 'text' field. If the rule is requested using GET / rules/:id
or GET /rules
, it will include the ruleName in the 'text' field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's a good idea to mention it in the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0917cbd
lib/models/rules.js
Outdated
var newAs = '"' + rule.name + '" as ruleName'; | ||
// Add "name as ruleName" if not exist | ||
if (rule.text && rule.text.indexOf(' as ruleName') === -1) { | ||
var idx = rule.text.toLowerCase().indexOf('select') + 7; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7 seems to be a magic number, a bit obscure :)
Where it comes from? It seems to be len(select) +1, so maybe it would be more clear (i.e. less magical ;) something like this:
var offset = length('select') + 1;
var idx = rule.text.toLowerCase().indexOf('select') + offset;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in b25bd0f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
Edit: fixes #307