Skip to main content
Solved

Automatically remove unused attributes


pflegpet
Contributor
Forum|alt.badge.img+8

According to several solved questions in this forum, there are two recommended ways to automatically remove attributes that only conatain NULL or empty values: using a small python script or using the NullAttributeMapper. Unfortunately both suggestions do not work for me (FME Desktop/Form 2022.2). Both the PythonCaller and the NullAttributeMapper keep the Null-Attributes and they are present when I write to Excel (see attached workspace). Is there something wrong in my workflow or is there an updated solution? Thanks for any suggestions!

Best answer by pflegpet

Hi @hkingsbury​ , thank you! Your modified Python code now removes all unused attributes. I also found out, that you could also use the SchemaScanner to achieve the same result (also using a dynamic writer). You just have to set it to "Ignore empty attributes" and exclude the schema attributes starting with fme_ (which is basically what you did in your script). I attached both solutions in case anyone needs this as a reference in the future.

View original
Did this help you find an answer to your question?

6 replies

hkingsbury
Celebrity
Forum|alt.badge.img+51
  • Celebrity
  • April 13, 2023

As you're looking to dynamically change the schema (ie the schema is dependent/defined by the data) your going to need to follow a dynamic workflow where you make use of schema attributes and dynamic writers

https://community.safe.com/s/article/dynamic-workflow-tutorial-introduction

 

To achieve what your looking for, i've made a minor addition to the Python in the SchemaSetter custom transformer - https://hub.safe.com/publishers/safe-lab/transformers/schemasetter

 

In the uploaded workbench, you can see the changes i've made on lines 84-86. All my change does is that if the attribute does not have a value, it will exclude it from the schema creation. It then flows into a dynamic writer that uses the schema list on the attribute to define the excel sheets output fields

 

 

 


pflegpet
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • Best Answer
  • April 14, 2023

Hi @hkingsbury​ , thank you! Your modified Python code now removes all unused attributes. I also found out, that you could also use the SchemaScanner to achieve the same result (also using a dynamic writer). You just have to set it to "Ignore empty attributes" and exclude the schema attributes starting with fme_ (which is basically what you did in your script). I attached both solutions in case anyone needs this as a reference in the future.


hkingsbury
Celebrity
Forum|alt.badge.img+51
  • Celebrity
  • April 16, 2023
pflegpet wrote:

Hi @hkingsbury​ , thank you! Your modified Python code now removes all unused attributes. I also found out, that you could also use the SchemaScanner to achieve the same result (also using a dynamic writer). You just have to set it to "Ignore empty attributes" and exclude the schema attributes starting with fme_ (which is basically what you did in your script). I attached both solutions in case anyone needs this as a reference in the future.

Good to know re the SchemaScanner, I don't deal with dynamic processes all that much and haven't had the chance to use that yet, but will investigate it further :)


tisjadaggers
Contributor
Forum|alt.badge.img+1
  • Contributor
  • August 1, 2024

@pflegpet Where can the attachments be found?


redgeographics
Celebrity
Forum|alt.badge.img+49

@hkingsbury it appears the attachment did not survive the community migration, do you still have it by any chance?


hkingsbury
Celebrity
Forum|alt.badge.img+51
  • Celebrity
  • September 3, 2024
redgeographics wrote:

@hkingsbury it appears the attachment did not survive the community migration, do you still have it by any chance?

Hmmm, I don’t sorry. But looking at the custom transformer, around those lines:

 

I imagine I was checking the value of att and only passing it through if it wasn’t none/null/empty

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings