Question

AttributeValidator - setting all invalid attributes to Null

  • 29 March 2023
  • 4 replies
  • 11 views

Userlevel 1
Badge +21

Is there a straightforward FME way to set all attributes exiting the failed port of an AttributeValidator and listed in the validation message list to null? I have a very straightforward bit of python to do it, but my brain is failing me this afternoon on an FME method

def FeatureProcessor(feature):
    for i in feature.getAttribute('_fme_validation_message_list{}'):
        attrname = re.search(r"(?<=Attribute \')\w+",i)
        feature.setAttributeNullWithType(attrname.group(0),fmeobjects.FME_ATTR_UNDEFINED)

 


4 replies

Userlevel 4
Badge +17

AttributeManager can set attributes to null:

imageYou can put this behind the Failed port of your AttributeValidator. You can also use the Conditional Value option if you want to only map specific attribute values to null.

Hope this helps

Userlevel 1
Badge +21

AttributeManager can set attributes to null:

imageYou can put this behind the Failed port of your AttributeValidator. You can also use the Conditional Value option if you want to only map specific attribute values to null.

Hope this helps

That doesn't allow you to map only invalid attributes to null

Badge

fmeobjects commands i use: fmeobjects.FMEFeature.getAllAttributeNames, and fmeobjects.FMEFeature.setAttributeNullWithType

 

Which would get all attributes tied to that feature and then you could just filter out the ones you need based on the valid list and then set the rest to NULL. So like:

import fme
import fmeobjects
# Template Function interface:
# When using this function, make sure its name is set as the value of
# the 'Class or Function to Process Features' transformer parameter
def processFeature(feature):
    for a in <valid attr list>:
        if not a in feature.getAllAttributeNames():
             feature.setAttributeNullWithType(a,fmeobjects.FME_ATTR_UNDEFINED)
    
    pass

 

Another way I have done this is to have a private parameter python script setup beforehand that looks for only "the approved fields to use" and then everything else is set to NULL. This approach would work best if you know your schema ahead of time. So your private parameter would have a bunch of these return statements:

if FME_MacroValues['FEATURE_TYPES'] == "arc_sample_feature":
    return "SRC_TYPE,COORD_SRC2,DEF_FET_TYPE,DEF_FET2,ACCURACY_FT,ST,OlID"

and then I made a python caller Python_Null_Attribute_Manager which does the same as above pretty much:

import fme
import fmeobjects
# Template Function interface:
# When using this function, make sure its name is set as the value of
# the 'Class or Function to Process Features' transformer parameter
def processFeature(feature):
    for a in FME_MacroValues['Main_AttrComma'].split(","):
        if not a in feature.getAllAttributeNames():
             feature.setAttributeNullWithType(a,fmeobjects.FME_ATTR_UNDEFINED)
    
    pass

 

Userlevel 1
Badge +21

fmeobjects commands i use: fmeobjects.FMEFeature.getAllAttributeNames, and fmeobjects.FMEFeature.setAttributeNullWithType

 

Which would get all attributes tied to that feature and then you could just filter out the ones you need based on the valid list and then set the rest to NULL. So like:

import fme
import fmeobjects
# Template Function interface:
# When using this function, make sure its name is set as the value of
# the 'Class or Function to Process Features' transformer parameter
def processFeature(feature):
    for a in <valid attr list>:
        if not a in feature.getAllAttributeNames():
             feature.setAttributeNullWithType(a,fmeobjects.FME_ATTR_UNDEFINED)
    
    pass

 

Another way I have done this is to have a private parameter python script setup beforehand that looks for only "the approved fields to use" and then everything else is set to NULL. This approach would work best if you know your schema ahead of time. So your private parameter would have a bunch of these return statements:

if FME_MacroValues['FEATURE_TYPES'] == "arc_sample_feature":
    return "SRC_TYPE,COORD_SRC2,DEF_FET_TYPE,DEF_FET2,ACCURACY_FT,ST,OlID"

and then I made a python caller Python_Null_Attribute_Manager which does the same as above pretty much:

import fme
import fmeobjects
# Template Function interface:
# When using this function, make sure its name is set as the value of
# the 'Class or Function to Process Features' transformer parameter
def processFeature(feature):
    for a in FME_MacroValues['Main_AttrComma'].split(","):
        if not a in feature.getAllAttributeNames():
             feature.setAttributeNullWithType(a,fmeobjects.FME_ATTR_UNDEFINED)
    
    pass

 

I was looking for something that works on the validation list that the AttributeValidator generates in FME, that is doing various bits of validation. I'm validating the values of the attributes not the names/schema. The python I posted grabs the attribute names that appear in the invalid list and sets those attributes to null. I just wondered if i was missing an FME way

Reply