Skip to main content
Question

How can I convert an attribute of type string (but all digits) to type integer?

  • April 7, 2018
  • 6 replies
  • 998 views

Forum|alt.badge.img

I keep getting an error in my translation because one of the reader attributes is a string (utf-16) and I'm trying to read it into an integer attribute in the writer. But I can't seem to find a way to convert it. I'm sure I've accomplished this in the past but can't remember how and am not seeing anything in the docs about how to do this specifically.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

6 replies

takashi
Celebrity
  • 7843 replies
  • April 7, 2018

Hi @ieukcoca, generally FME implicitly converts data type of an attribute value if necessary, according to the destination schema you have configured. A string representing digits should be written into an integer type attribute in a destination feature type without any explicit type conversion.

If it's a case where the automatic conversion won't be performed, there could be a kind of bug. Could you please elaborate the situation, including answers to these questions?
  • What error message appeared?
  • What format reader/writer are you using?
  • What version, build number of FME are you using?

david_r
Celebrity
  • 8394 replies
  • April 9, 2018

Consider inserting an AttributeValidator somewhere to check that the string attribute indeed contains a valid integer, e.g.

You could direct the "Failed" port of the AttributeValidator to an Inspector to check what's going on.

Depending on the output format / FME version it might also be necessary to use a NullAttributeMapper to map any empty strings to proper NULL values before the writer:


Forum|alt.badge.img
  • Author
  • 12 replies
  • April 9, 2018

@david_r When I use an attribute validator, I get Attribute 'apn' with value '3862110200' fails check for Type is 'INT'

    attributevalidationmessage.png

    @takashi

    • The error I get is: 2018-04-09 09:04:44| 2.7| 0.0|ERROR |The invalid value '3870900800' was supplied to the field 'apn' for the table/feature class 'sde.account_to_apn_match'
    • version FME(R) 2017.1.0.0 (20170731 - Build 17539 - WIN32)
    • The reader is SWORLDSWAF; the writer is GEODATABASE_SDE

    takashi
    Celebrity
    • 7843 replies
    • April 9, 2018
    Hi @ieukcoca, the value 3862110200 is greater than the upper limit of 32-bit integer = 2147483647. 'integer' type in the Geodatabase SDE format represents 32-bit integer. Probably it's the reason why the writer rejected writing the value. If so, it's a limitation according to the format specifications, not a defect or a bug of FME.

     

    Try changing data type setting in the writer feature type to one which has enough valid range to save 3862110200. e.g. integer(n) (n=10), double, or double(n, m) (n=10+, m=0)

     


    takashi
    Celebrity
    • 7843 replies
    • April 9, 2018

    @david_r When I use an attribute validator, I get Attribute 'apn' with value '3862110200' fails check for Type is 'INT'

      attributevalidationmessage.png

      @takashi

      • The error I get is: 2018-04-09 09:04:44| 2.7| 0.0|ERROR |The invalid value '3870900800' was supplied to the field 'apn' for the table/feature class 'sde.account_to_apn_match'
      • version FME(R) 2017.1.0.0 (20170731 - Build 17539 - WIN32)
      • The reader is SWORLDSWAF; the writer is GEODATABASE_SDE
      Hi @ieukcoca, the value 3862110200 is greater than the upper limit of 32-bit integer = 2147483647. 'integer' type in the Geodatabase SDE format represents 32-bit integer. Probably it's the reason why the writer rejected writing the value. If so, it's a limitation according to the format specifications, not a defect or a bug of FME.

       

      Try changing data type setting in the writer feature type to one which has enough valid range to save 3862110200. e.g. integer(n) (n=10), double, or double(n, m) (n=10+, m=0)

       


      Forum|alt.badge.img
      • Author
      • 12 replies
      • April 10, 2018
      Hi @ieukcoca, the value 3862110200 is greater than the upper limit of 32-bit integer = 2147483647. 'integer' type in the Geodatabase SDE format represents 32-bit integer. Probably it's the reason why the writer rejected writing the value. If so, it's a limitation according to the format specifications, not a defect or a bug of FME.

       

      Try changing data type setting in the writer feature type to one which has enough valid range to save 3862110200. e.g. integer(n) (n=10), double, or double(n, m) (n=10+, m=0)

       

      Thanks @takashi That makes total sense!