The AttributeValidator fails nulls when validating for various types. Most of the time I would like it to pass nulls. The obvious work-around is using the NullAttributeMapper to map nulls to some acceptable value for the validation but: a) this is a pain because you have to do it for all attributes you want to check b) you have to change these values back to null afterwards so as to not send spurious data to the writer
Any more elegant way to do this? Perhaps a custom transformer to do the work-around and the AttributeValidator within? Or should this be an “Idea” for the AttributeValidator, i.e. Option: pass nulls?
Page 1 / 1
I’ve run into this problem in the past, I think i ended up doing some processing of the failures in python, so that those that only had null validation failures joined up with the passed features. I do think it should be an option to allow nulls when checking for type
I you create an Idea you’ll get my vote.
import fme import fmeobjects import re
def processFeature(feature): validation = feature.getAttribute('_fme_validation_message_list{}') for v in validation: a = re.search('(?<=\').*?(?=\')',v) isNull, Missing, type = feature.getAttributeNullMissingAndType(a.group(0)) if isNull: validation.remove(v) feature.removeAttribute('_fme_validation_message_list{}') feature.removeAttribute('_fme_validation_message') feature.setAttribute("numbererrors",len(validation)) if len(validation)>0:
Dug out the example (my python skills are fairly basic so no doubt this could be better). The main thing for my use case was I had to distinguish between nulls which were valid and empty or missing attributes which were not. In the validation message null, empty and missing are all displayed as ‘’ and can’t be distinguished from each other.
Simply upvote this idea:
Interesting…
A string that is <null> or <missing> is a valid string.
But a number that is <null> or <missing> is not a valid number.
Thanks a lot @ebygomm I will definitely borrow that python code! And no your python skill are not “fairly basic” - I’ve “borrowed” some of your other code from here before and it has been very helpful (something about creating lists if I recall) .
And yes good point @geomancer, indeed composite tests would solve this. In fact I keep expecting to see composite tests in the AttributeValidator transformer but alas no . I upvoted the idea.