Skip to main content
Solved

Is there a way to read schema or create schema features attribute from a single feature?

  • September 4, 2018
  • 3 replies
  • 95 views

Forum|alt.badge.img

I am trying to read the results for a SQLExecutor. The transformer does not have the possibility to expose schema features. And I would need it (rather than reading the table from the DB with a FeatureReader)

following the advice from the answers for this question:

I am using Python to read the feature name and types and create a schema feature with the format

attribute{n}.fme_data_type

attribute{n}.name

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):
    feature_attr_names = feature.getAllAttributeNames()
    i = 0
    for feature_attr_name in feature_attr_names:
        feature.setAttribute('attribute{0}.fme_data_type'.format(i), feature.getAttributeType(feature_attr_name))
        feature.setAttribute('attribute{0}.name'.format(i), feature_attr_name)
        i+=1
    pass

When it comes to expose the attributes I create FME does not seem to be able to iterate the creation and I have to insert manually the numbers for every "n". If I do this the resulting schema attribute is created but with round brackets and not curly brackets, and fme_data_type is an number (that is the corresponding variable for FME_data_type as described here.

Has anyone ever managed to accomplish what I am trying to do and could help me?

Best answer by david_r

The easiest by far is probably to use the SchemaSetter from the FME Hub, it will do exactly this.

You can also look at the Python code inside to see how it's done.

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.

3 replies

david_r
Celebrity
  • 8394 replies
  • Best Answer
  • September 4, 2018

The easiest by far is probably to use the SchemaSetter from the FME Hub, it will do exactly this.

You can also look at the Python code inside to see how it's done.


david_r
Celebrity
  • 8394 replies
  • September 4, 2018

Here's a hint. This code:

'attribute{0}.fme_data_type'.format(5)

will return

'attribute5.fme_data_type'

But you need to preserve the {} brackets, like this:

'attribute{5}.fme_data_type'

So you need to use a triple bracket in the format string, like this:

'attribute{{{0}}}.fme_data_type'.format(5)

Forum|alt.badge.img
  • Author
  • 14 replies
  • September 4, 2018

Here's a hint. This code:

'attribute{0}.fme_data_type'.format(5)

will return

'attribute5.fme_data_type'

But you need to preserve the {} brackets, like this:

'attribute{5}.fme_data_type'

So you need to use a triple bracket in the format string, like this:

'attribute{{{0}}}.fme_data_type'.format(5)
Yes investigating the issue I realised I needed three braces and also that the SchemaSetter already does what I am looking for, it has an internal dictionary to map the integers to types. Thanks