Extracting a schema subset for dynamic schemas
Article Number: 000001271 - Last Modified: Sep 21, 2011
Sometimes when using a dataset for a dynamic schema source, you may wish to only use a subset of the source schema in the output. This can be accomplished by creating a Custom Data Format to use as a schema source.
1. Create a new workspace. Add a schema reader and point it to your schema source.
2. Create a new Published Parameter with the name TO_KEEP and the prompt "Fields to Keep"
3. Connect the source schema feature to a ParameterFetcher. Set the Parameter Name to TO_KEEP and the Target Attribute to _to_keep.
4. Connect the ParameterFetcher to a PythonCaller. Set the Python symbol to keep_defs and add the following Python source code:
from pyfme import *
def keep_defs(feature):
att_name_list = feature.getListAttribute('attribute{}.name')
att_ntype_list = feature.getListAttribute('attribute{}.native_data_type')
att_ftype_list = feature.getListAttribute('attribute{}.fme_data_type')
keep_values = feature.getStringAttribute('_to_keep')
keep_list = keep_values.split(',')
if att_name_list != None:
feature.removeListAttribute('attribute{}.name')
feature.removeListAttribute('attribute{}.native_data_type')
feature.removeListAttribute('attribute{}.fme_data_type')
count = 0
for i in range(len(att_name_list)):
if (att_name_list[i] in keep_list):
feature.setStringAttribute(('attribute{'+str(count)+'}.name'),att_name_list[i])
feature.setStringAttribute(('attribute{'+str(count)+'}.native_data_type'),att_ntype_list[i])
feature.setStringAttribute(('attribute{'+str(count)+'}.fme_data_type'),att_ftype_list[i])
count = count + 1
if (att_name_list[i] == 'fme_geometry{0}'):
feature.setStringAttribute('fme_geometry{0}',att_ftype_list[i])
5. Connect the PythonCaller to an AttributeRemover and remove the attribute _to_keep.
6. Add an FFS writer and create an output feature called "schema". Connect the AttributeRemover to the schema output and save the workspace as a Custom Format with the name SCHEMASUBSET.
You can now add the format SCHEMASUBSET as a schema source in workspace resources. Only the attributes listed in the Fields to Keep parameter will be used to generate a dynamic schema.
|
Suggested Similar Articles