Remove Attribute to Write Null

Some data formats - typically databases distinguish null value and empty string, and null value could be important sometimes. But FME 2013 doesn't support null value.
When we need to write a null value into the destination dataset, should remove the attribute beforehand. The writer will treat the value of a missing (removed) attribute as null.
2012-12-23 The NullAttributeMapper transformer has been added in FME 2014.
It can be used to convert between non-null and <null> effectively.
> Null in FME 2014: Converting Null to Non-Null

In general, the AttributeRemover can be used to remove attributes. And also the TclCaller or the PythonCaller could be effective in certain cases.
For example, the following scripts remove every empty attribute.

TclCaller Script Example
proc removeEmptyAttributes {} {
  foreach name [FME_AttributeNames] {
    if {[string compare [FME_GetAttribute $name] ""] == 0} {
      FME_UnsetAttributes $name

PythonCaller Script Example
import fmeobjects

def removeEmptyAttributes(feature):
    for name in feature.getAllAttributeNames():
        if str(feature.getAttribute(name)) == '':
Note: When an attribute can hold a unicode object, the str function in the Python script might throw an error saying <UnicodeEncodeError>. See here how to avoid it:
FME stores all attributes as character strings: Part 2

FME 2014 will support null value. I'm looking forward to it.
FMEpedia > How does FME handle null attribute values?
Community > NULL and empty strings in FME 2013

No comments:

Post a Comment