...
Use an output multiplier to break out a record into multiple output recordsIn this exercise you will
load reference data into your model which lists all the TV channels offered in each package. So far your model has merged data from two files, then grouped and sorted the records. You now have a stream that has the latest data about the TV package that each customer has.
We now want to get a set of records for each channel that the customer has ordered. In this section you are going to add information about which channels are included for each package
. This data is currently in a database table. PhixFlow can look-up this data. To make sure that PhixFlow finds all the channels, you will use an ouptut multiplier
You will use this to break out each customer record, in Latest Package Update
, into a set of records for each channel that the customer has ordered.
Load data from a database table
In this section First, you will load the database table SOURCE_PACKAGE_CHANNELS
into a stream. Your model will then have the full list of channels available in each package.
...
- In the repository browser, expand the list of Datasources.
- Drag the datasource called
Rating and Billing
into your model. - In your model, hover your mouse pointer over
Rating and Billing
and click
. PhixFlow displays a list of the tables available in this database. You can resize the list to make it easier to browse.Insert excerpt _show_tables _show_tables nopanel true - Right-click on
SOURCE_PACKAGE_CHANNELS
and select
. PhixFlow adds a new database collector to the model, and gives it the same name as the source data table,Insert excerpt _create_collector _create_collector nopanel true SOURCE_PACKAGE_CHANNELS
. In the settings → Basic Settings section → Statement Expression, you can see the database query is: select * from SOURCE_PACKAGE_CHANNELS
. - Hover your mouse pointer over the new database collector, and click
. PhixFlow adds a new stream to your model and also gives it the nameInsert excerpt _add_stream_with_attributes _add_stream_with_attributes nopanel true
. In the settings → Attributes section, you can see that data has two attributes (columns): Package and Channel.SOURCE_PACKAGE_CHANNELS
To load the data into the stream, run analysis on this section of the model and check the data has loaded.
Expand title How? - Hover your mouse pointer over the
SOURCE_PACKAGE_CHANNELS
stream , click
then click YES to confirm.Insert excerpt _run_analysis _run_analysis nopanel true - When PhixFlow notifies you that the analysis is finished, hover your mouse pointer over the stream again.
- Click
.Insert excerpt _show_stream_views _show_stream_views nopanel true - In the drop-down list, select
. PhixFlow displays the data.Insert excerpt _default_view _default_view nopanel true
Snapshot 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 a stream ...
Update your model to add a stream. This stream will hold the full channel listtake all the data that we have merged, sorted and grouped in the model so far.
- Hover your mouse pointer over the
Latest Package Update
stream and click
.Insert excerpt _add_stream _add_stream nopanel true - In Basic Settings, set the Name to
Latest Package All Channels
. Drag all the attributes from
Latest Package Update
to the settings forLatest Package All Channels
.Expand title How? - Hover your mouse pointer over the stream
Latest Package Update
. - In the context toolbar, click
. Phixflow lists the data attributes (column titles) for this stream.Insert excerpt _stream_attributes _stream_attributes nopanel true - Select all the attributes and drag them into the
Latest Package All Channels
settings → Attributes section.
- Hover your mouse pointer over the stream
- Click
to save your changes and close the settings tab.Insert excerpt _finish _finish nopanel true - Close the attributes list.
Look up
...
Supplement the stream with look-up data
You now need to add to the data in the Latest Package All Channels
stream with additional data from the database, using a lookup pipe. You will use a look-up pipe to add information about the Package. PhixFlow needs to know how the data in the source stream matches the data in the receiving stream.
- In the model, add a pipe from
SOURCE_PACKAGE_CHANNELS
toLatest Package All Channels
. PhixFlow opens the settings for the new pipe. - In In the Basic Settings section, set:
- Name:
chan
find_channels
- Type: Look-up
- Name:
- In the Order/Index section, click
. PhixFlow opens two lists of attributes: one list for the source stream and another for the receiving stream.Insert excerpt _stream_attributes _stream_attributes nopanel true - From the source stream list
PACKAGE
andCHANNEL
.DragPACKAGE
into the- , on the left, drag
PACKAGE
into the Order/Index grid.
This tells PhixFlow about the key column in the source stream. Notice that PhixFlow has added a line to the Order/Index grid. - From the receiving stream 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 stream. Notice that PhixFlow has now added the Index Expression_outPackage
. However, we do not want PhixFlow to use_outPackage
. because output multipliers are calculated before the output is generated. We need it to use the data on the input.
- In the Order/Index section, then double-click the the new line createdthat PhixFlow has added. PhixFlow opens the settings for the
PACKAGE
attribute. Set:- Basic Settings → Index Expression from
_out.Package
to:in.Package
.
Technical issue: I'm not seeing _out.Package
here. - Click
to save save and close the attribute settings tab.Insert excerpt _finish _finish nopanel true
- Basic Settings → Index Expression from
- Close the attribute list.
- In the pipe settings, click
to save your changes and close the settings tab.Insert excerpt _finish _finish nopanel true - In the model toolbar, click
to save your model.Insert excerpt _save _save nopanel true
At this point, if you run your model (I think) it will find each customer, e.g. C010, and will read that the customer has the News package. It will then look-up the channel for this to find News: Channel 1. But having done one look-up for the customer it will move onto the next customer.
When you run your model, PhixFlow
This means that the lookup will match records in the reference data (SOURCE_PACKAGE_CHANNELS
) where PACKAGE
= Package
from the input pipe in
?????
We must do this, rather than using the value of Package
from the output because we are using GOING TO USE the lookup to drive an output multiplier – and output multipliers are calculated before the output is generated
- Open the configuration form for the stream
Latest Package All Channels
by double clicking it - In the field Output Multiplier, enter the value:
chan.CHANNEL
This means that for each output record processed, PhixFlow will look up the list of channels for the package from the reference stream; it will then work through the list returned, handling each element from the list in turn and generating an output record in the stream for each one
- Add an attribute to the stream with Name
Channel
- Set the Expression of this attribute to
_outputMultiplier
This will print the value of the current element of the output multiplier list to this field
...
On older models in PhixFlow you may see the internal variable _type. This is the old name for _outputMultiplier. Either can be used, and anywhere you see _type you can update it to _outputMultiplier for clarity.
...
Set an output multiplier
What is 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 for each customer 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 pipe
- what data you want to add - the channels.
The stream needs to know about the new column to create for the channel information.
- In the model, double-click
Latest Package All Channels
to open its settings tab. - To create the output multiplier, expand the Multipliers and Filters section and set:
- Output Multiplier:
find_channels.CHANNEL
- Output Multiplier:
- To create a new column for the channel data, expand the Attributes section. Click
to add a new attribute. PhixFlow opens a new attribute settings tab. Set:Insert excerpt _add_object _add_object nopanel true - Name:
Channel
- Expression:
_outputMultiplier
- Name:
- Click
to save and close the settings tab.Insert excerpt _fini _fini nopanel true - In the model toolbar, click
to save your model.Insert excerpt _save _save nopanel true
Now you can run the model and view the stream data.
- Hover your mouse pointer over the
Latest Package All Channels
stream and click
then click YES to confirm.Insert excerpt _run_analysis _run_analysis nopanel true - When PhixFlow notifies you that the analysis is finished, hover your mouse pointer over the
Latest Package All Channels
stream again. - Click
.Insert excerpt _show_stream_views _show_stream_views nopanel true - In the drop-down list, select
. PhixFlow displays the data.Insert excerpt _default_view _default_view nopanel true
What do I do if there is no data.
Something might have gone wrong with something