Complete rule for Rule-based row filter as variable


I'm trying to dynamically assign multi-line rules (generated using java snippet) to a Rule-based row filter node , and as far as I can see, there is no way to assign a ruleset represented as a string via a variable.

It is possible to add individual rules by assigning different flow variable to each rule line, but this does not help me much because I want to automate this assignment process

Am I missing something? Did anyone have a similar problem? How did you solve it?




Hi Milos,

since you are generating your rules with a Java Snippet node and then you want to use them to filter rows, why not using directly a Java Snippet Row Filter node?

To my knowledge assigning directly each row of the rule to a flow variable, like each one would contain a piece of the rule itself, doesn't work and produces an error. What you can do is to use a flow variable as part of a rule (e.g. as comparison term).


An alternative might be creating the rules as PMML RuleSets and filter based on the results of those. (I know the fromat it is quite different from PMML.)

In case you have a limit on the number of rules, it is also possible to add comments in the dialog's text field and generate multiple variables as the flow variable replacements of some of the comments. (This is what I used and worked.)



This wouldn't work for me because I am generating ruleset from one data flow, and injecting them via variable to another. 



Thanks, the second solution did the trick for me (for now while the number of rules is small - hop[efully it stays that way).



Is there a reason why it had to be done this way? why is each individual rule a separate variable? It is very inconvenient and I cannot imagine a case where this comes in handy. Again, am I missing somethin?

Furthermore, one other issue surfaced now. When I have a bunch of flow variables, I need to somehow initialize them in a java snippet, and it is not possible to do it easily outside the row processing loop, as java snippet does not support snippet initialization - only definition of globals for the snippet loop.

Would it be possible to add an initializer function to the snippet?




Hi Milos,

   I think if you want to replace all values, probably it is best to use the Dictionary-based rule nodes. Not sure how do you create the flow variables, but if you create a table instead, it is certainly easier to configure a Dictionary-based rule not to use that.

   I am not sure I understand your problem with snippets in loops. Could you provide a workflow demonstrating the problem?

Thanks, gabor

Hi Gabor,

For example, I create a set of 4 rules (rule0, rule1, rule2 and rule3) using a java snippet- this is not hardcoded, it depends on the number of actual input rows, it could also be zero or 10 depending on the input). As part of the specification of a java snippet we have to specify all it's inputs and outputs, which means both the output flow variables containing rules and the ones that remain empty. However, it is not possible to easily initialize those that remain empty, as there is no explicit initializer function (or constructor) from which you could initialize all 10 rules.

There is a separate heading for custom imports and for initialization of user custom variables in a snippet, but no "constructor" of sorts which would "set up" the snippet (e.g set up some computational values based on the values of flow variables, or number of rows, you get the point).

Right now I am using an ugly conditional at the beginning of the snippet code which runs just before the processing of the first row starts, for the rest of the rows it is skipped.

Best regards,