5 Breaking-out into multiple output records
- Chris Welford
- Zoe Baldwin
- Anthony George
- Fiona Sargeant (Unlicensed)
By the end of this chapter you will be able to:
So far your model has merged data from two files, then grouped and sorted the records. You now have a table that has the latest data about the TV Package that each Customer has.
You now want all the channels that the customer has ordered. You will look up the data about the channels provided by each package from a database table. To make sure that PhixFlow finds all the channels, you will use an output multiplier.
Load data from a database table
First, load the database table SOURCE_PACKAGE_CHANNELS
into a table as described below. Your model will then have the list of channels available in each package:
Remember, the Introduction to Modelling course explains about loading data from databases; see section 3 Creating Datasources and Database Collectors.
- In the repository, expand the list of Datasources.
- Drag the datasource called
Rating and Billing
into your model.- In the Properties (on the right), in the Datasource Instances section, double-click Default
- Update the fields URL, Username and Password with those provided in your training email.
- Save your changes.
- In your model, hover your mouse pointer over
Rating and Billing
and click Show Tables. PhixFlow displays a list of the tables available in this database. You can resize the list to make it easier to browse. - Right-click on
SOURCE_PACKAGE_CHANNELS
and select Create a collector. PhixFlow adds a new Database Collector to the model, and gives it the same name as the source data table,SOURCE_PACKAGE_CHANNELS
. In the Properties (on the right) → Basic Settings section → Statement Expression, you can see the database query is:select * from SOURCE_PACKAGE_CHANNELS
. - Hover your mouse pointer over the new
SOURCE_PACKAGE_CHANNELS
database collector, and click Create Table Using Attributes. PhixFlow adds a new table to your model and also gives it the name
. In the Properties → Attributes section, you can see that the data has two attributes (columns): Package and Channel.SOURCE_PACKAGE_CHANNELS
To load the data into the table, run analysis on this section of the model and check the data has loaded.
How?- Hover your mouse pointer over the
SOURCE_PACKAGE_CHANNELS
table, click Run Analysis then click YES to confirm. - When PhixFlow notifies you that the analysis is finished, hover your mouse pointer over the table again.
- Click Show view.
- In the drop-down list, select Default View. PhixFlow displays the data.
Screenshot of your model and the data you have loaded:
- Hover your mouse pointer over the
Take a moment to look at this data. For each package, there are multiple channels included. For example, the News package includes Channel 1, Channel 2, Science 2 and NewsExtra.
Add another table
Update your model to add a table. This table will take all the data that we have merged, sorted and grouped in the model so far:
- Hover your mouse pointer over the
Latest Package Update
table and click Create New Table. - In Basic Settings, set the Name to
Latest Package All Channels
. Drag all the Attributes from
Latest Package Update
to the property tab forLatest Package All Channels
.How?- Hover your mouse pointer over the table
Latest Package Update
. - In the context toolbar, click Attributes. Phixflow lists the data attributes (column titles) for this table.
- Select all the attributes and drag them into the
Latest Package All Channels
property tab
→ Attributes section.
- Hover your mouse pointer over the table
- Click Apply and Close to save and close the Properties.
- Close the attributes list.
Supplement the table with look-up data
You now need to add to the data in the Latest Package All Channels
table. You will use a look-up pipe to add the channels provided by a package. PhixFlow needs to know how the data in the source table matches the data in the receiving table.
- In the model, add a pipe from
SOURCE_PACKAGE_CHANNELS
toLatest Package All Channels
. PhixFlow opens the Properties for the new pipe. - In the Basic Settings section, set:
- Name:
find_channels
- Type: Look-up
- Name:
- Click Apply to register the change of pipe.
- In the Order/Index section, click Attributes. PhixFlow opens two lists of attributes: one list for the source table and another for the receiving table.
- From the source table list, on the left, drag
PACKAGE
into the Order/Index grid. - This tells PhixFlow about the key column in the source table. Notice that PhixFlow has added a line to the Order/Index grid.
- From the source table list, on the left, drag
- From the receiving table list, on the right, drag
Package
over the top of the line in the Order/Index grid.
This tells PhixFlow about the matching key column in the receiving table. Notice that PhixFlow has now added the Index Expression_out.Package
. However, we do not want PhixFlow to use_out.Package
because output multipliers are calculated before the output values is generated (see PhixFlow Timing Cycle). We need it to use the data wherePACKAGE
=Package
is from the input pipein.
We must do this, rather than using the value ofPackage
from the output, because we are going to use the lookup to drive an output multiplier – and output multipliers are calculated before the output is generated. - In the Order/Index section, double-click the new line that PhixFlow has added. PhixFlow opens the property tab for the
PACKAGE
attribute. Set:- In the Basic Settings → Index Expression change from
_out.Package
toin.Package
. - Click Apply and Close to save and close the property tab.
- In the Basic Settings → Index Expression change from
- Close the attribute list.
- In the pipe property tab, click Apply and Close to save and close.
- In the model toolbar, click Save to save your model, which should look like this:
At this point, if you run your model it will find each customer, e.g. C010, and will read that the customer has the News
package.
Set an output multiplier
An output multiplier tells PhixFlow to process the same record multiple times, each time producing a new record. This is called breaking-out a record. In this case we want PhixFlow to keep processing the same customer record until it has found all the channels. This means our single input record:
C010 | News |
becomes multiple output records, like this:
C010 | News | Channel 1 |
C010 | News | Channel 2 |
C010 | News | Channel 3 |
C010 | News | NewsExtra |
The output multiplier needs to know:
- which pipe it will use -
find_channels
. - what data you want to add - the channels.
The table also needs to create the new column for the channel information.
- In the model, double-click
Latest Package All Channels
to open its Properties. - To create the output multiplier, expand the Analysis Options section and set:
- Output Multiplier:
find_channels.CHANNEL
- Output Multiplier:
- To create a new column for the channel data, expand the Attributes section. Click Create New to add a new attribute. PhixFlow opens a new attribute property tab. Set:
- Name:
Channel
- Expression:
_outputMultiplier
- Name:
- Click Apply and Close on both the New Table Attribute Properties and the Latest Package All Channels Properties.
- Run the model and view the table data.
- Hover your mouse pointer over the
Latest Package All Channels
table and click Run Analysis then click YES to confirm. - When PhixFlow notifies you that the analysis is finished, hover your mouse pointer over the
Latest Package All Channels
table again. - Click Show view.
- In the drop-down list, select Default View. PhixFlow displays the data.
- Select More Options on the View and Toggle Paging Bar to show the number of records.
There should be 33 records, similar to the below image:
Notice that there are now multiple records for each customer. In the model toolbar, click Save to save your model.