โ09-23-2022 01:03 PM
Hi Team,
Is it possible to function a list of values in the filter
snap?
Letโs assume, I want to filter IDs whose values are 100, 110, 300, etc., how can I put this in Filter snap without using || function?
I was planning to use $ID IN (100, 110, 300, etc.) but this one doesnโt seem to work so I have been using a conventional way as below:
$ID == "100" || $ID =="110" || $ID =="300"
Thanking in advance for your suggestions.
Regards,
Darsh
Solved! Go to Solution.
โ09-23-2022 01:57 PM
It depends. If your $ID are numbers, you can change the expression to
[100, 110, 300].indexOf($ID) != -1
I donโt understand your last question about Mapper. Since you mentioned using the Filter snap, this is for the Filter expression setting.
โ01-03-2024 02:27 AM - edited โ01-03-2024 04:29 AM
I used the dummy data below to create a working solution.
Input:
[
{"txt":"abc"},
{"txt":"efg"},
{"txt":"c - abc"},
{"txt":"c - xyz"}
]
JSON.parse(_filterValues).map(x => $txt.contains(x)).filter(y => y == true).length == 1โ
โ01-03-2024 04:57 AM
@darshthakkar - My solution is pretty similar to what @Abhishek_Soni37 provided.
I would recommend that you not use JSON.parse() for every record. It can be fairly taxing on your CPU depending on data volume. If you want to remove the hardcoded reference to the array of values to search for, I recommend you look at Expression Libraries.
Hope this helps!
โ01-03-2024 06:20 AM
@koryknick - If I use 2 filter snaps would that be more effective than using ["abc", "xyz"].filter(x=> $txt.contains(x)).length >=1?
โ01-04-2024 09:06 AM
@koryknick - CPU memory consumption as well as time taken to validate/execute the pipeline is pretty much the same with "abc", "xyz"].filter(x=> $txt.contains(x)).length >=1 as well as using 2 filter snaps.
There have been instances where using 2 filter snaps is faster than using the expression detailed above however if we have to scale the solution and there is a need to use 10 filter snaps that needs to filters out strings then the solution provided by @koryknick would be helpful.
Tried using expression library too however everytime the string needs to be updated, expression library needs to be updated and putting them into a filter snap instead is easier and convenient approach.
Thank you for your help @koryknick and @Abhishek_Soni37, closing this thread now.
โ01-03-2024 06:15 AM
Thank you @koryknick and @Abhishek_Soni37 for your insights, I will try both of them and thank you @koryknick for the additional insights. I will definitely test this out using expression library.
Regards,
Darsh