Skip to main content
Question

Get Schema into attribute from SQLExecutor


mferwerda1111
Participant
Forum|alt.badge.img+2

Is there a way to get a list of exposed attributes/schema from a SQLExecutor into an attribute value or as a list? I know I can write out a record with a featurewriter and sue a schema reader to get at it, but that is a convoluted way to go. I guessing ti can be done with python, but my python skills are limited

6 replies

ebygomm
Influencer
Forum|alt.badge.img+38
  • Influencer
  • August 24, 2018

The python to get a comma separated list of attribute names is fairly straightforward, just send one of the features to a pythoncaller with the code

def processFeature(feature):
    attrNames = ','.join(feature.getAllAttributeNames())
    feature.setAttribute('attrNames', attrNames)

stalknecht
Contributor
Forum|alt.badge.img+19
  • Contributor
  • August 24, 2018

The SchemaSetter will create a list of all attributes.


takashi
Influencer
  • August 24, 2018

Why not use the FeatureReader to read both Schema feature and Data features, rather than using the SQLExecutor?


mferwerda1111
Participant
Forum|alt.badge.img+2
  • Author
  • Participant
  • August 24, 2018

Thanks, I'll try these out, I am using SQL just because it allows me to combine multiple tables together and also use subqueries to deal with a complex data source.


takashi
Influencer
  • August 25, 2018
mferwerda1111 wrote:

Thanks, I'll try these out, I am using SQL just because it allows me to combine multiple tables together and also use subqueries to deal with a complex data source.  

Just an idea. If the database user has the privilege to create a view in the database, possibly you could create a view from the SELECT statement with the SQLExecutor and read schema feature and data features from the view with the FeatureReader. Finally you could drop the view with another SQLExecutor.

 

This may not work as expected depending on database format, but at least worked fine with a PostgreSQL database in my test.

 

0684Q00000ArM6lQAF.png

SQL Statement parameter in the first SQLExecutor (Example)

 

FME_SQL_DELIMITER ;

-drop view $(TEMP_VIEW);

create view $(TEMP_VIEW) as
select a.*, b.value
from table1 as a inner join table2 as b
on b.id = a.id; 

mferwerda1111
Participant
Forum|alt.badge.img+2
  • Author
  • Participant
  • August 29, 2018

Thanks all, I used the python solution, worked great, the days of typical user having any privs on the database to create stuff are long gone. In case anyone is interested, I am doing this to create a source to target column mapping, I get the column names into the flow, then run therm through an AttributeValueMapper to crosswalk them to the source table.column_name, and query the Oracle All_tab_columns table to get the column comments, so I get a source table name.column_name, target column_name and an attribute definition as a result in an xls, along with the real output in a personal geodatabase


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