7 Enriching data directly from database tables
- Chris Welford
- Zoe Baldwin
- Anthony George
Owned by Chris Welford
By the end of this chapter you will be able to:
- Enrich a data set using a lookup pipe directly from a database collector
- Use the attribute function countElements()
In this exercise you will compare the table you created in the previous exercise, listing all channels for each customer, with a list of assigned channels stored in an inventory database. To do this, you will create a lookup directly from a database collector:
- Open the model
Channel Package Check
- Add a new table to your model from
Latest Package All Channels
, calledChannel List Reconciliation
- Drag all the attributes from
Latest Package All Channels
intoChannel List Reconciliation
- Create a database collector, using the datasource CRM, to read all records from the table
SOURCE_ALL_CHANNELS_LIST
How?- Click Datasource in the toolbar to show the list of available Datasources in the Repository
- Drag the Datasource CRM onto the model
- Hover over the CRM Datasource and click Database Collector in the pop up menu
- Name the new Database Collector,
SOURCE_ALL_CHANNELS_LIST
- Add a lookup pipe from the database collector
SOURCE_ALL_CHANNELS_LIST
to the tableChannel List Reconciliation
- Call the pipe
inv
- Change the Type to Look-up
- Then Applythe pipe Properties
- Go to the Order/Index section
- Press Show Attributes
- Drag the attribute
CustomerRef
from the left-hand box into the list of Order/Index attributes. - Drag the attribute
CustomerRef
from the right-hand box into the list of Order/Index attributes again – on top of the matching attributeCustomerRef
you created above – this will populate the right-hand part of the matching attribute. - Drag the attribute
Channel
from the left-hand box into the list of Order/Index attributes. - Drag the attribute
Channel
from the right-hand box into the list of Order/Index attributes - on top of the matching attributeChannel
you created above.
- Call the pipe
This lookup will find values in the external database table which match the output records on CustomerRef
and Channel:
- Press Apply and Close in the pipe Properties to save your changes
- Click on the table
Channel List Reconciliation
to open the Properties - Add an attribute with Name
InvoiceCheck.
- In this attribute, you will record whether you returned the channel from the database. To do this, you will count the records returned from the lookup; if this is 1, you will record that the reconciliation check was successful:
Set the Expression of the attribute to:
if (countElements(inv) == 1, "YES" , // ELSE "NO" )
- Save your changes to the table.
- Run analysis on
Channel List Reconciliation
- Review the results, and see which channels reconciled against the list from the database, and which did not.
- You can open the data in the database by hovering over the datasource and selecting Show Tables to verify the results.
- In the model window, click Save.