By the end of this chapter you will be able to:
- Combine data sets (a union) with a calculate stream
- Record the source for each record in a stream
- Use the internal variable _pipeName
In this exercise you will produce a single list of updates to customers' Cable TV packages. Customers can update their packages both through a customer care system and in shops. You will bring all these updates together into a single list.
Read in Data Sets from Files
For this exercise you need two files from the zip file you downloaded in 2 Using Excel Templates, step 5. The files contain updates from the two sources: the customer care service and the shop.
- <path>\train\inputData\ChannelPackages\CustomerCareUpdates\CustomerCareUpdates.txt
- <path>\train\inputData\ChannelPackages\ShopUpdates\ShopUpdates.txt
- Create a new model with the Name
Channel Package Check
. - Add a file collector to your model and load the data.
- PhixFlow displays a form for the new file collector. Set the Name to
Customer Care Updates
. - In the model, hover over the
Channel Package Check
file collector to display the context toolbar. - Click Upload Managed File.
- Navigate to the directory <path>\train\inputData\ChannelPackages\CustomerCareUpdates.
- Select the file CustomerCareUpdates.txt. and clickUpload.
- PhixFlow adds a new stream to the model, called
CustomerCareUpdates
. - In the model, hover over the new
CustomerCareUpdates
stream and click Run Analysis. - Check the data is loaded. There should be 8 lines of data, with columns for Customer Ref, Sales Date and Package.
- PhixFlow displays a form for the new file collector. Set the Name to
- Add another file collector to your model and repeat the process described in step 2. This time:
- Set the file collector Name to
Shop Updates
. - Upload <path>\train\inputData\ChannelPackages\ShopUpdates\ShopUpdates.txt.
- PhixFlow loads 7 rows of data to this stream.
- Set the file collector Name to
Snapshot of the Channel Package Check
model so far:
Combine Data Sets
- Create a new stream in your model and populate its attributes.
- Hover over
CustomerCareUpdates
and click Add a new Stream. - In the form, set the Name to
Combined Updates
. - In the model, show the stream attributes for
CustomerCareUpdates
. - Select all the attributes and drag them into the form for the
Combined Updates
stream. Drop them into the Attributes section.
- Hover over
- Save your model layout.
- Connect the
ShopUpdates
stream to theCombined Updates
stream.- Hover over
ShopUpdates
and click Add a new Connector. Click
Combined Updates
to link the pipe to the stream.When PhixFlow adds data to a stream via a pipe, it automatically adds a reference to the input pipe expression. To merge the data sucessfully you must update the attribute expressions to remove the
in.
prefix.
- Hover over
- Fix all the attribute expressions.
- Double-click on
Combined Updates
to open its configuration form. For each attribute: - In the Attributes section, double-click on an attribute to open its form.
- In the form for the attribute, in the Basic Settings section, edit the Expression to remove
in.
and press .
- Double-click on
- In the
Combined Updates
stream form, press to save the changes. - Run analysis on
Combined Updates
. - Check that you have the correct number of records in this stream when the analysis is complete.
- Check the data set you generated to make sure that every field in every output record has been populated.
Record the Source for Each Update
You will now update your configuration to record the source for each update, in the set of combined updates. To do this:
- Update the name of the pipe from the stream
CustomerCareUpdates
.- Double-click on the pipe to open its configuration form.
- Update the Name to
CC
. - Press to save your changes.
- Update the name of the pipe from
ShopUpdates
toshop
. - Double-click the stream
Combined Updates
to open its configuration form. - In the Attributes section, add a new attribute and set:
- Name:
Source
. Expression :
if (_pipeName == "CC", "Customer Care" , "Shop" )
- Name:
- To make
Source
the first attribute in the stream, drag it to the top of the attributes list. - Press in the main stream configuration form.
- Run analysis on
Combined Updates
. - Check the output data set and make sure that the source has been recorded on each record correctly.