Forum Discussion
This is maybe a little bit difficult, but you can put the following filter after your parser
The expression is: $.entries().filter(v => v[1] != "").length > 0
which will find any instance where all of the values for the given input document are all empty and filter them out.
- darshthakkar3 years agoValued Contributor
@ddellsperger: Voila, it worked! Thank you for your assistance. I will now remove my conventional filter which has the condition of ! = null on each column in the file (it was never a good design but my only resort until we could find a best solution).
Thanks again.
BR,
Darsh- darshthakkar3 years agoValued Contributor
@ddellsperger: Is it a safe assumption that the below solution provided by you is similar to the conventional filter I used (which was putting a NOT NULL condition on each column?) Q-1
I believe my conventional filter would be a lot of overhead on the system + this time, I only had to deal with 10 columns (so 20 conditions, one as !=null and another as !=“”) however if I had to work on 350+ columns (which is my ideal day scenario), conventional filter would have busted.
I want to take this opportunity to learn from an expert like you that what would be the overhead (time & space complexity) while using $.entries().filter(v => v[1] != “”).length > 0? Q-2
Is the above a recommended approach and the ONLY approach to filter out blank rows from a flat file? Q-3
Looking forward to hearing from you.
BR,
Darsh- ddellsperger3 years agoAdmin
A-1
It’s safe to say it’s similar, you could achieve similar with the following filter directly on the object (as a bit of a double verification doing both null and empty string checking):
!$.filter((v, k) => v != null && v != "").isEmpty()
A-2
This space and time complexity is fairly low, you’re talking O(n) when it comes to this validation and verification as it will go through every piece in the input document to check for values, we do a filter and length (creates an array and provides us the length of that) to then check for the size, the other option above is similar in that route.A-3
There are some other ways to potentially do this, but I wouldn’t really call them perfect solutions, your flat file is likely a CSV and as a result, there’s some limitations with the CSV Parser to get those empty rows removed, and I think that’s a place where the snap can potentially be improved (I’ll have a feature request logged internally to see if we can help out in this case). Some of our snaps have better support for this than others, I believe the Excel Parser has some option to exclude empty rows from the output, but that’s using a different way to parse, so it’s slightly skewed in how it operates.
- pmancevski3 years agoNew Contributor III
- darshthakkar3 years agoValued Contributor
Thank you @pmancevski for your suggestion and assistance on this one. I tested with your solution and unfortunately it didn’t work.
- darshthakkar3 years agoValued Contributor
Thank you @ddellsperger, I will definitely give this a try.
Before posting this to community, I tried with$.filter((v,k)=> v != null)
but didn’t get any success.Will keep you posted with my findings. Thanks again.
Regards,
Darsh