Filter out columns based on a value of input container block in knime

Dear team,

I have a workflow on Knime Server that outputs a table with 23 rows and 12 columns (1-12 representing months). I am serving it as a REST API. Now I would like to filter my output table based on Columns. The idea is that using a REST API input parameter the user passes the value (1-12) and the table output the data just for that month.

I tried using a Container Input block, that just takes 1 value from the user as an API parameter, but the node “column filter” doesnot take 2 inputs. I want to take the value from “Container input” node (entered by the user via REST API) and based on that value the “column filter” node should filter the output table.
How can I achieve this?
Thanks

You would want to use a flow variable to set the column filter. You can convert the column value with the filter setting to a flow variable using “Table Row to Variable”. Then make a flow variable connection to the Row Filter. Then go into the Row Filter - Flow Variables tab and select the flow variable for “Pattern”.

3 Likes

Thank you so much for the prompt response. I tested it and it works. Another question is that, can I set multiple flow variables?

For eg in the above picture, I can only set one column at one time. For eg 3 and based on the value it filters. However, the column can not always be 3, it could be anything in between 1-12 passed from the flow variable. How can I have multiple columns to test at the same time ?

The easiest way to test multiple values in the same column is to check “regular expression” and separate your values with these characters || You can also utilize wildcards and advanced regex matching tactics with this approach as well.

KNIME_project4.knwf (8.5 KB)

When it comes to checking multiple columns, it depends on the given situation. If you are checking all columns for the same pattern, then the easiest way would be to combine them first and then test using regex. You can combine columns easily via the “Column Combiner”. The value tests will require some regex syntax such as wildcards “*” in order to match correctly and perhaps some safeguards to avoid substring matching (if that is a potential issue in your data).

Alternatively you could loop through the test columns controlling the Column to Test and the Pattern via flow variable if there was more variability to the Column / Patterns.

Welcome to the forum by the way!

Thank you so much. We are new to Knime. This information really helps :slight_smile:

Basically I have to use an a Input container node to pass a flow variable via the REST API. The user can pass value for any of the 12 columns. For Eg. A user can pass:
{“1”:“HR”} where 1 being the column and HR being the value to filter the results
OR
{“2”:“2022”} where 2 being the column and 2022 being the value to filter the results

With the current setting, If I connect the Input Container to the Row filter, then I can select only one “column to test”. But the column to test should not be fixed, it should be dependent on which column and value the user is passing through the Input Container/REST API. Any ideas on how can I achieve this?

Thank You for the warm welcome :slight_smile:

1 Like

In this scenario where an outside user has control of the filter settings and there can be multiple columns / filter values in pairs, I would definitely recommend a loop approach.

I will try to build a simple version next time I have an opening.

1 Like