How to avoid Extra condition while Drools rule sheet is converted in rules? - drools

In this Drools sheet I am comparing a class variable with a variable of another class variable but the rule converted are not as expected. Is there a way to do this...
One thing is creating a problem and it is when this excel sheet is converted into rules the condition where I check stdId in college class is equals to id of Student class i.e. third column, the rule is generated as follows-
$c2: College(stdId == $s.id == "x")
The =="x" part is undesirable and creating trouble while running the rules.
What should be done to remove the extra undesired part.

The third column can be written as
CONDITION
$c2: College(stdId==$s.id)/*$param*/
match student id
x
x
...
The x is required to trigger insertion of the conditional expression from row 2.

Related

Merging multiple rows based on condition in Power BI

I have a table that looks like the one below.
Table I have
I want an output classifying the PART as either CLASS A or B. CLASS A and CLASS B should be created as two additional columns.
The conditions for classifications are:
-> IF Arrangement, Prefix and Range are the same, it will be classified as CLASS A and CLASS B, and the PART should be in both columns.
->
If the above condition is false, it will check the value in the TYPE column.
If the type column contains CLASS A, then the respective PART should be in the CLASS A column.
If the type column contains CLASS B, then the separate PART should be in the CLASS B column.
Here is the sample of the output I would need.
Table I want
So far, I have managed to get the below output but have not been able to merge the results into one row when the three columns are the same.
Results I got till now
Sample Data
Arrangements PREFIX RANGE PART TYPE
ARR1 1XJ 1-100 191123 TRANSMISSION CLASS A
ARR1 1XJ 1-100 299123 TRANSMISSION CLASS B
ARR1 9TC 1-100 191123 TRANSMISSION CLASS A
ARR2 5TJ 101-120 288123 TRANSMISSION CLASS B
In the Query Editor (Transform Data), you can
Group by Arrangements, Prefix and Range and use the ALL operation
Then add Custom Columns with the formula below for CLASS A
=try Table.SelectRows([Count], each Text.Contains([TYPE],"CLASS A"))[PART]{0} otherwise null
Add another Custom Column for CLASS B with the obvious changes
Delete the Count column
Try this in M Advanced Editor
Table.AddColumn(previousStepName, "Text After Delimiter", each Text.AfterDelimiter([TYPE], " "), type text)

Azure Data Factory DataFlow md5 specific columns

First of all, I have my array of columns parameter called $array_merge_keys
$array_merge_keys = ['Column1', 'Column2', 'NoColumnInSomeCases']
So then I am going to hash them, if the third NoColumnInSomeCases is not existed, I would like to treat it as null or some strings else there value.
But actually, when I use them with byNames(), it would return NULL because the last is not existed, even though first and second still have values. So I would expect byNames($array_merge_keys) always return value in order to hash them.
Since that problem cannot be solved, I am back to filter these only existed column
filter(columnNames('', true()), contains(['Column1', 'Column2', 'NoColumnInSomeCases'], #item_1 == #item)) => ['Column1', 'Column2']
But it comes to another problem that byNames() cannot compute on the fly, it said 'byNames' does not accept column or argument
array(byNames(filter(columnNames('', true()), contains(['Column1', 'Column2', 'NoColumnInSomeCases'], #item_1 == #item))))
Spark job failed: { "text/plain":
"{"runId":"649f28bf-35af-4472-a170-1b6ece50c551","sessionId":"a26089f4-b0f4-4d24-8b79-d2a91a9c52af","status":"Failed","payload":{"statusCode":400,"shortMessage":"DF-EXPR-030
at Derive 'CreateTypeFromFile'(Line 35/Col 36): Column name function
'byNames' does not accept column or argument
parameters","detailedMessage":"Failure 2022-04-13 05:26:31.317
failed DebugManager.processJob,
run=649f28bf-35af-4472-a170-1b6ece50c551, errorMessage=DF-EXPR-030 at
Derive 'CreateTypeFromFile'(Line 35/Col 36): Column name function
'byNames' does not accept column or argument parameters"}}\n" } -
RunId: 649f28bf-35af-4472-a170-1b6ece50c551
I have tried lots of ways, even created a new derived column (before that stream name) to store ['Column1', 'Column2']. But it said that column cannot be referenced within byNames() function
Do we have any elegant solution?
It is true that byName() cannot evaluate with late binding. You need to either use a Select transformation to set the columns in the stream you wish to hash first or send in the column names via a parameter. Since that is "early column binding", byName() will work.
You can use a get metadata activity in the pipeline to inspect which columns are present in your source before calling the data flow, allowing you to send a pipeline parameter with just those columns you wish to hash.
Alternatively, you can create a new branch, use a select matching rule, then hash the row based on those columns (see example below).

Drools decision table create object

I want to convert the below rule to decision table,
when
customer:Customer(purchase > 1000)
person:Person()
then
person.markValuableCustomer(customer.id);
end
I tried to convert this to decision table but I am not sure how to declare the person object. As you can see in the excel I created a new Condition for it.
I tried in a CONDITION column as person:Person but I get some error saying condition has to be entered.
So how to create a object in decision table which has to be used in Action column ?
Please find the excel data just in case if image uploaded is not opening.
RuleTable HelloWorld1
CONDITION CONDITION ACTION
customer:CustomerInfo
customer.purchase > "$param" && customer.valid person:Person(); person.markValuableCustomer(customer.id)
Purchase
1000
You can use this trick:
RuleTable HelloWorld1
CONDITION CONDITION ACTION
customer:CustomerInfo person:Person()
customer.purchase > "$param" /*$param*/ person.mark(customer.id)
Purchase
1000 x
You can join the cells of the condition column so that a single 'x' is sufficient.

Calculate sum in script in ABBYY Flexicapture

I would like to perform the function of a Calculate Sum rule with a Script rule in ABBYY Flexicapture, because I want to only perform the calculation based on evaluation of an if statement.
I have tried the following in a C# script rule:
IFields AllTaxes = Context.Field("cu_location_taxes").Rows;
which gives me the error "Field is not a table."
I have also tried
IFields AllTaxes = Context.Field("cu_location_taxes").Children;
which gives me the error "Cannot access fields not specified in rule settings." Even though I have added the repeating group cu_location_taxes to the c# script rule.
Once I am able to get them in some kind of array or list or IFields variable, I would like to sum the children values in some way. I am open to doing this with JScript or C#.
The reasons of the errors you are facing can be found in ABBYY FlexiCapture Help.
In the description of IField class you can find the following descriptions of properties:
Rows - A set of table rows. Unavailable for non-table fields.
Well, it seems to be that "cu_location_taxes" is not a table. You said, it is a repeating group.
Children - Child items of the field (cells for tables). Unavailable in script rules.
But as I understand, you are exactly using script rules.
To achieve correct results try to use Items property exactly of the fields that you are summing.
For example, you have a repeating group that contains number fields field_1 and field_2. And you want to calculate the sum of all field_1 instances.
Then you can use the following code (JScript):
sum = 0
for (i = 0; i < this.Field("field_1").Items.Count; ++i)
{
sum += this.Field("field_1").Items.Item(i).Value
}
Also do not forget to add the field_1 in available fields of your rule settings.
Hope this will help.

Drools decision table - one column - two fields

Let's suppose we have some class which is related to one or more codes: main and secondary. Every object of this class has at least main code and can have unlimited number of secondary codes:
class Something {
private String mainCode;
private List<String> secondaryCodes;
}
I want to make a rule in Drools decision table which allows me to check if value given in column is equal to mainCode or is contained by secondaryCodes.
So I need one column for two rules related to two different fields.
Is it even possible?
The constraint can be written as a compound Boolean expression:
mainCode == $param || secondaryCodes contains $param
There's no restriction as to the fields you refer to in such an expression.
You can do this in Guvnor using #{param} in a Condition BRL fragment like:
$s : Something (maincode == "#{codes}" || secondaryCodes contains "#{codes}"
That gives you one column.
-J