Exercise 3.1 Adding a Transformer
Data 3-1-1 case location details (XLS hosted on FTP)
Overall Goal Add a transformer to filter out missing values
Calculate a new attribute
Demonstrates Adding a transformer
Setting transformer parameters
Filtering
Start Workspace C:\FMEData2018\Workspaces\IntroToDesktop\Ex3.1-Begin.fmw
End Workspace C:\FMEData2018\Workspaces\IntroToDesktop\Ex3.1-Complete.fmw

Video covering adding transformers. This video will be updated to match this exercise for the FME 2019.0 release.

We know from the last unit that we have missing values in our data. We can use a filtering transformer to remove features with missing values.

[Could do the Tester after the AM to have it require fewer attributes to filter out?]

1) Start Workbench

Start Workbench (if necessary) and open the workspace from Exercise 2.3. Alternatively you can open C:\FMEData2018\Workspaces\IntroToDesktop\Ex3.1-Begin.fmw.

2) Add Tester Transformer

Click on the feature connection between the reader feature type and the AttributeManager:

Start to type the phrase "Tester." When the list is short enough for you to see the Tester, select it from the dialog (double-click on it):

Doing so will place an Tester transformer:

Notice that the Passed output port is the one connected by default.

3) Set Parameters

Inspect the parameters for the Tester transformer (either its dialog or in the Parameter Editor window). Click in the Left Value field and from there click the down arrow and choose Attribute Value > Local_Area:

For the Operator field click the cell and select "Attribute Has a Value." We do not need to fill in the Right Value field for this operator. Your Test Clauses table should look like this:

There might be missing values in other attributes, but we are only concerned with cases where Local_Area is missing, so we will only fill in one test clause.

Click OK to accept the values and close the dialog.

4) Run the Workspace using Feature Caching

Now that you know how to use feature caching, we can use it to test our new transformer. Select the Tester transformer. Then click the "Run To This" icon (note that the objects that will run are highlighted in green):

Your workspace will read the data and run the Tester. If you set up the Tester properly, it should do so without errors. If you pay attention while the translation is running, you can see the feature counts increasing as features flow through the workspace. By the time the translation is complete, 4,122 features will be filtered out to the Tester's Failed port. These features did not have values for Local_Area and are removed from the rest of the translation.

5) Explore the Text Editor

We added a Date attribute to the writer feature type, but it currently does not have a value. We could use several different transformers to accomplish this; again, there are often many solutions to a problem in FME. For example, we could use the ExpressionEvaluator or StringConcatenator. In this case, let's keep our workspace efficient by creating the attribute within the AttributeManager.

Open the AttributeManager Parameters by double-clicking it or clicking the cogwheel icon. Go to the bottom of the Attribute Actions table and notice the last row is empty except for the text "". Click this text and type in Date. You might see it appears as an option in the drop-down menu; FME will look ahead to your writer schema to help you find attributes. After you type in or select Date, the Action cell changes to "Set Value":

You can enter in the value for our Date attribute in the Attribute Value column. If you were to type in "January 1st, 2000," all of the features would receive that value as a constant. However, what we want to do is create a date attribute that combines (or "concatenates") our existing date-time fields: Year, Month, Day, Hour, and Minute.

We can do that using FME's Text Editor, which allows us to construct an expression to generate the value for our attribute. To open it, click the Attribute Value cell, and then click the drop-down arrow that appears. You will see "Open Text Editor" and "Open Arithmetic Editor" as options. Click "Open Text Editor":

The text editor - as you would expect - allows you to construct a text value. It includes all the usual string-handling functionality you would need, such as concatenation, trimming, padding, and case changing.

The text editor looks like this:

Here the user is constructing an address string by concatenating various existing attributes with some fixed characters (the commas).

Notice the menu on the left-hand side. Existing attributes are listed here and were added into the string by double-clicking them. Also, notice the other menu options. The essential functions for text are the String Functions:

The Arithmetic Editor contains similar functions, as well as mathematical operators to calculate values for attributes.

6) Create a Date Attribute

Let's combine existing attributes to create a Date attribute. In the left-hand panel under "FME Feature Attributes," you will see all the incoming attributes listed. Double-click the attribute Year. Doing so adds @Value(Year) to the Text Editor window. When the translation runs, this code will take the value of Year for each feature. We can combine multiple attribute values to construct the date. In this case, we will create a basic year/month/day attribute, but you could use the Text Editor to format your date however you like.

Type in a forward-slash / and then double-click the attribute Month, type in another /, and then double-click the attribute Day. You can also just copy and paste this text into the Editor if you prefer:

@Value(Year)/@Value(Month)/@Value(Day)

You should see this in the Text Editor:

Click OK and OK again. Save your workspace. Then, use Run to This on the AttributeManager.


TIP
Many FME Text and Arithmetic Editor functions come from the Tcl programming language. If you do not want to type out code, most results can also be accomplished using transformers. For more information, refer to the Documentation.

7) Inspect the Data

Inspect the AttributeManager feature cache and examine the Table View window. You can see that the underscores have been removed from attribute names and the Date attribute now correctly displays the concatenated date:


Advanced Exercise

If you want to use a more realistic - but also more complicated - example, you can generate a standard FME date/time stamp. To do so, copy and paste the following code into the Text Editor:
@TimeZoneSet(@Format(%04d,@Value(Year))@Format(%02d,@Value(Month))@Format(%02d,@Value(Day))@Format(<%02d>,@Value(Hour))@Format(%02d,@Value(Minute))00, local)

Here we are using the @TimeZoneSet function to add a UTC offset to each date/time stamp. We are forming the date/time stamp by combining the attributes from our source data into a string matching FME date/time format: yyyymmddhhss-UTC. Our original data had single digit months, days, hours, and minutes missing the leading zero, so we use the @Format function to ensure leading zeros are added. This new attribute will be easier to use in FME workflows.


CONGRATULATIONS
By completing this exercise, you have learned how to:
  • Filter data using the Tester transformer
  • Use transformer parameters to create attributes that match the writer schema
  • Construct an attribute value using the Text Editor

results matching ""

    No results matching ""