Use rule engin for replace value on row

Dears,
I used rule engin node which has filled with some condition like these:

$CAB_TYPE$ = “031” AND MISSING $DA_ID$ => “264”
$CAB_TYPE$ = “033” AND MISSING $DA_ID$ => “106”

in next step I wanna set another condition which like this:
if (A= B) => value (clumn (Fee)) = 0

but my problem is rule engin create the new clumn to set value… or replcae whole of this clumn , I dont want to make new clumn. I wanna replce the value of specefic row with zero.
To be clear I need to run below order with something like this:
if A = B than “the Corresponding value of clumn Fee should be zero”.

image

with python I have used thise code, but I perefer to use knime node. is there any suggestion?

df.loc[df[‘A’].isin(input_table_2[‘B’]), ‘Fee’]=0

Hi,
simply set the value to the current value if the condition is not met:

$A$ = $B$ => 0
TRUE => $Fee$

Then select to replace column “Fee” with the output of the node and you are set.
Kind regards
Alexander

3 Likes

Dear @AlexanderFillbrunn,
Is there any way to compare tow string (one item from a file) and other item in rule engin?
if A=B than fee=> ‘0’
A red from XLSX.
image

BR,
Milad

Hi,
you mean you want to do what you did above, but one column comes from the rule engine and the other from an Excel file? In that case you first have to merge the tables somehow, most likely using a Joiner.
Kind regards
Alexander

Dear @AlexanderFillbrunn
Yes exactly, I want to import 2 stream in to rule engin. but as you know for large data like 100 M or more, the cost of join is to much (Time and Ram usage). Is there any other way? to be clear I want to make a comparision of one string between the file and the rule engin. meybe using of simple java snipp is better? is it?

BR,
Milad

Hi,
you mean you want to compare a column with a constant value that does not change for each row? In that case you should read the Excel file and extract the value to compare with into a flow variable. Can you show some minimal example data to highlight what you want to achieve?
Kind regards
Alexander

Dear @AlexanderFillbrunn,
Hi,
This is my table:
The value in our file is not with a constant value.

A B Fee
1100 99362987434 No action
1101202010 99362984434 No action
1101202020 99362981434 No action
110206012 99362978434 No action
111111 11111 0
1112 1112 0
1115 99362969434 No action
1123 99362966434 No action
1234 99362963434 No action
201212 99362960434 No action
….

A= read from excel file
B= the data in our rule engin
order: I want to compare the string of A with B and if its same the corispond Value in clumn Fee should be ‘0’

bBR,
Milad

Hi,
so the data is already in a single table? Why don’t you use the rule engine with the expression I gave above?

$A$ = $B$ => 0
TRUE => $Fee$

If A is equal to B, 0 is inserted. For all other cases, the value is retained.
Kind regards
Alexander

Dear @AlexanderFillbrunn,
I got your point and use it in previous process:blush:. but in this satage I reed A from File, and it is not in single tabe.

image

BR,
Milad

Hi,
okay, I see. But then how should KNIME know which row of the Excel Reader table to compare with which row from the Rule Engine? Is it guaranteed that both tables have the same number of rows? If that is the case, you can use the Column Appender node, which is more efficient than a join if you simply want to combine the rows by index.
Kind regards
Alexander

@AlexanderFillbrunn,
Unfortunatly both table have not same row number. so I have 4 option:
1-use join and continue the process.
2-use python code to make comparison between two clumn (python)
3-use java snipp simple to make comparison between two clumn (java)
4- suggest to knime team to develop rule engin node with two input leg :grinning:

what is your suggestion? :grinning:

BR,
Milad

Hi,
I think Java Snippet won’t work because it also has only one input. If you use Python be aware that the data has to be transferred from the KNIME process to the Python process, so a Join might still be faster. What should a rule engine with two input ports do if the tables don’t even have the same number of rows like in your case? I think the only logical solution here is to use a join.
Kind regards
Alexander

2 Likes

@AlexanderFillbrunn
Thanks for your support.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.