Skip to main content
Question

Attribute renaming using attribute values


Forum|alt.badge.img
I think this is an easy one, however i am stumped.

 

 

I have a set of data with 3 columns.  Fieldname, Fieldval, RecordGroup.  I simply want to aggregate by recordgroup and then rename attribute names to the value that is stored in the Fieldname.

 

 

Where i am stumbling is how to rename the fields to the values in the input field.

 

 

Thanks in advance.

 

 

 

13 replies

Forum|alt.badge.img
  • July 11, 2013
The simplest way I know is to create the attributes by a python caller:

 

 

import fmeobjects def processFeature(feature):     name = feature.getAttribute('FieldName')     value = feature.getAttribute('FieldValue')     feature.setAttribute(name, value)

 

If you know all possible field names, then you can create them in advance to be able to use them in subsequent transformers.

takashi
Contributor
Forum|alt.badge.img+23
  • Contributor
  • July 11, 2013
Hi,

 

 

The RecordBuilder custom transformer might be available. And also a similar question is here.

 

 

Takashi

fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • July 12, 2013
The BulkAttributeRenamer can do this (called AttributeExpressionRenamer in earlier versions of FME)

 

 

Select the attribute you want to rename, select "Regular Expression Replace" and enter .* if you want to replace the whole name.

 

Then for the "String" setting select the attribute containing the value you want to use as the name which I guess is Fieldname

takashi
Contributor
Forum|alt.badge.img+23
  • Contributor
  • July 12, 2013
Hi Ken,

 

 

I didn't know that usage of the BulkAttributeRenamer. After renaming, we can transform input rows to new records using the AttributeAccumulator (Group By: RecordGroup). Thank you for the information.

 

 

Takashi

gpt_geoinfo
Contributor
Forum|alt.badge.img+2
  • Contributor
  • April 8, 2014
Hi Takashi,

 

Hi Ken,

 

 

it's great to have a working community like this!

 

This topic helped me very much with my issues.

 

Now, is it possible to save these auto-generated attribute-names in a writer?

 

In my case i am using FME 2014. The writer is SQLite.

 

 

Thanks in advance.

 

 

-Maria

ridleyj
Contributor
Forum|alt.badge.img+5
  • Contributor
  • May 8, 2022
fmelizard wrote:
The BulkAttributeRenamer can do this (called AttributeExpressionRenamer in earlier versions of FME)

 

 

Select the attribute you want to rename, select "Regular Expression Replace" and enter .* if you want to replace the whole name.

 

Then for the "String" setting select the attribute containing the value you want to use as the name which I guess is Fieldname

Hey Safe Team, Takashi

I tried this method and am finding the regex replace is not working when using the attribute value method. The output retains the same names as input, but the value of the "renamed " target field is now "missing". An explicit replacement string works, but that is not useful for the intended automation - is this a known issue with the current bulkAttributeRenamer I wonder?


kailinatsafe
Safer
Forum|alt.badge.img+21
ridleyj wrote:

Hey Safe Team, Takashi

I tried this method and am finding the regex replace is not working when using the attribute value method. The output retains the same names as input, but the value of the "renamed " target field is now "missing". An explicit replacement string works, but that is not useful for the intended automation - is this a known issue with the current bulkAttributeRenamer I wonder?

Hello @ridleyj​ , would you be able to demonstrate your issue with screenshots perhaps? Just having a bit of a hard time visualizing the issue from your description, apologies! Also, what version of FME are you currently using? Best, Kailin.


ridleyj
Contributor
Forum|alt.badge.img+5
  • Contributor
  • May 10, 2022
ridleyj wrote:

Hey Safe Team, Takashi

I tried this method and am finding the regex replace is not working when using the attribute value method. The output retains the same names as input, but the value of the "renamed " target field is now "missing". An explicit replacement string works, but that is not useful for the intended automation - is this a known issue with the current bulkAttributeRenamer I wonder?

Hi @kailinatsafe​ 

Thank you for looking into my enquiry.

The data, pulled from exposing specific columns in a spreadsheet, then split into two field chunks [testFilter], looks like this:

imageBulkAttributeNamer is then employed to (attempt to) take the value of attr_Name_Label and rename the attr_Value field with it:

imageThe output by those settings is identical to the input (no change of field name), but I mixed the REGEX up a little to see if I could get any result and thereby got this:

imageThe workflow is intended to take the new named attribute then pass the chunk through to a recombination procedure to compile it with the other chunks including their renamed attr_Value fields. Overall, it's an inefficient pivot type transformation, but works for the data as supplied!

 

 

FME version info:

Edition: FME Desktop Oracle Edition (floating)

Version: FME(R) 2021.0.0.0 (20210305 - Build 21302 - WIN64)

Locale: en_AU

Codepage: windows-1252

Registration Key:

Registration: Licensed (Floating: )

Serial Number:

Customer Number:

Home Folder: C:\\Program Files\\FME\\

Operating System: Microsoft Windows 10 64-bit (Build 19041)


kailinatsafe
Safer
Forum|alt.badge.img+21
ridleyj wrote:

Hey Safe Team, Takashi

I tried this method and am finding the regex replace is not working when using the attribute value method. The output retains the same names as input, but the value of the "renamed " target field is now "missing". An explicit replacement string works, but that is not useful for the intended automation - is this a known issue with the current bulkAttributeRenamer I wonder?

Hello @ridleyj​, if you go to the visual preview window and on the far right beside "Table Name", you should see a "Columns..." button, open this and do you see the appropriate column there?

 

BulkAttributeRenamerColumns 

Alternatively, if you add an AttributeExposer after the BulkAttributeRenamer, are you able to expose the newly named column? Let me know, Kailin.


kailinatsafe
Safer
Forum|alt.badge.img+21
ridleyj wrote:

Hey Safe Team, Takashi

I tried this method and am finding the regex replace is not working when using the attribute value method.  The output retains the same names as input, but the value of the "renamed " target field is now "missing". An explicit replacement string works, but that is not useful for the intended automation - is this a known issue with the current bulkAttributeRenamer I wonder?

Hello @ridleyj​ , ahh I think we uncovered the issue. Would you please try using this regex expression:

^.*

This should work for you now, but you may have to expose it afterwards still! For some reason ".*" isn't doing whats expected currently. I'll make a ticket to have this fixed. Thanks for bringing this to our attention. Let me know if you still have issues after changing the regex expression. Best, Kailin.


ridleyj
Contributor
Forum|alt.badge.img+5
  • Contributor
  • May 10, 2022
ridleyj wrote:

Hey Safe Team, Takashi

I tried this method and am finding the regex replace is not working when using the attribute value method. The output retains the same names as input, but the value of the "renamed " target field is now "missing". An explicit replacement string works, but that is not useful for the intended automation - is this a known issue with the current bulkAttributeRenamer I wonder?

Thanks for the update @kailinatsafe . I'll give that a try and advise you of the result. Thanks again for looking into this.

Cheers.

Jason.​


ridleyj
Contributor
Forum|alt.badge.img+5
  • Contributor
  • May 10, 2022
ridleyj wrote:

Hey Safe Team, Takashi

I tried this method and am finding the regex replace is not working when using the attribute value method. The output retains the same names as input, but the value of the "renamed " target field is now "missing". An explicit replacement string works, but that is not useful for the intended automation - is this a known issue with the current bulkAttributeRenamer I wonder?

Hi @kailinatsafe​ 

I have run that test as instructed, and can confirm that the "^.*" regex is working as indicated; the result does need to be exposed. Great news, thanks for the workaround.

J.


kailinatsafe
Safer
Forum|alt.badge.img+21
ridleyj wrote:

Hey Safe Team, Takashi

I tried this method and am finding the regex replace is not working when using the attribute value method. The output retains the same names as input, but the value of the "renamed " target field is now "missing". An explicit replacement string works, but that is not useful for the intended automation - is this a known issue with the current bulkAttributeRenamer I wonder?

@ridleyj Thanks for confirming! FMEDESKTOP-​12830.


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