Cartesian Operator
Overview
The Cartesian operator inputs two arrays and outputs a single array. The two arrays must be structured together as a table with two rows because this operator only has one input node. This new array contains each possible combination of the source arrays’ values. The output displays as a set of ordered pairs. For example, source arrays of ["A", "B"] and [1,2], produce the combinations [["A",1], ["A",2], ["B",1], ["B",2]] using this operator. This function is like a Cross Join, or Cartesian Product, in the coding language SQL.
A common example involves a deck of cards. The standard deck includes an array of 13 different values (two, three, four, and so on) when considering the cards by rank. When considering the cards by suits though, the deck includes an array of four values (clubs, hearts, spades, and diamonds). If you apply the Cartesian operator to these two arrays, the output is a single array of 52 ordered pairs. Each ordered pair represents a card in the deck.
This operator lets you create all possible combinations from rows of data. Let’s say you’re tracking the success of your company's marketing strategies. The Cartesian operator helps track the success of these strategies across different demographics. You can use the Cartesian operator to generate the combinations of that data.
You’ll find the Cartesian operator in the Table group in the menu on the Data Workflow canvas.
What You'll Learn
In this
About the Info Window
Here's what the Cartesian operator looks like, along with its Info window:
And here's a breakdown of each setting in the Info window:
Setting |
Description |
---|---|
Category |
Grayed out and non-adjustable setting indicating the operation type. |
Label |
Sets the label for the operator. The label you enter here appears below the operator in the Data Workflow canvas. This field is optional, but you'll want to set a label if you're using more than one of the operator type. A label can help you identify your operators without having to open any info windows. |
Preserve Argument Type |
When selected, this setting ensures the argument data type is respected when the operator executes. |
Type |
Select an option from the drop-down to determine how data is input. You can select an array or comma-separated list. |
Field Label |
Enter the field/key you want the Cartesian operator to act on. This is the name of the two arrays in your Set operator. |
Adding a Cartesian Operator
To see this operator in action, you'll create a simple module. You'll start with some sample data and then use a Data Workflow and a Cartesian operator to see all of the possible combinations.
NOTE These instructions assume that you have a new module open, saved, and with a title.
The completed use case looks like this in the Module Builder:
This use case works behind the scenes, so nothing displays in the Express View Express View is how your end-user views your application. Express View also lets you preview your applications to test your configuration and view the styling. This is also the view your end-users will see when interacting with your application. After configuring a module, click Preview in the Module Builder to interact with the module in Express View.. Instead, look at the DevTools Console The DevTools Console helps you securely store, build, test, and deploy your software.:
NOTE These instructions assume that you have a new module open, saved, and with a title.
Configure the Data Table Component
Start with a two-column Data Table. Column A holds the values x, y, z and Column B holds the values 1, 2, 3. There are nine ordered pairs after you use a Cartesian operator on this data.
1. | Drag and drop a Data Table component onto your canvas. |
3. | In the data table, enter the following: |
A | B | |
---|---|---|
1 |
x |
1 |
2 |
y |
2 |
3 |
z |
3 |
4. | Click Save & Close. |
Configure your Data Workflow Component
You must input the data stored in your table in order for the Cartesian operator to work. Use an Input operator to bring your data into the Data Workflow. From there, use two Col2Array operators to turn your Data Table into two separate arrays. Then, a Create Table operator and two Set operators bring these arrays into one input for your Cartesian operator. Finally, connect your Cartesian operator to a Console operator to see your final data.
1. | Drag and drop a Data Workflow component onto your canvas, placing it below your Data Table component. |
2. | In the Canvas Label Text and Property Name fields, enter dwfCartesian . |
Configure the Input Operator
Use an Input operator to get your data into the Data Workflow.
1. | Drag and drop an Input operator onto your Data Workflow canvas. |
2. | Configure the Input operator’s Info window as follows: |
Setting | Value |
---|---|
Category |
Input |
Component |
dtSampleData |
Required |
Yes |
Source |
Default |
Configure the First Col2Array Operator
This operator turns Column A from your Data Table into an array.
1. | Drag and drop a Col2Array operator onto your Data Workflow canvas. |
2. | Configure the Col2Array operator’s Info window as follows: |
Setting | Value |
---|---|
Category |
Col2Array |
Label |
Column A |
Drop Empty |
|
Path |
A |
Default Value |
|
3. | Connect the output port (right) of the Input operator to the input port (left) of the Col2Array operator. |
Configure the Second Col2Array Operator
Set up the second Col2Array operator. This operator turns Column B from your Data Table into an array.
1. | Drag and drop another Col2Array operator onto your Data Workflow canvas. |
2. | Configure the Col2Array operator’s Info window as follows: |
Setting | Value |
---|---|
Category |
Col2Array |
Label |
Column B |
Drop Empty |
|
Path |
B |
Default Value |
|
3. | Connect the output port (right) of the Input operator to the input port (left) of the Column B Col2Array operator. |
Configure the Create Table Operator
The Cartesian operator only allows one input, so you must bring your two arrays together. To do that, put both arrays in a table using the Create Table operator and two Set operators.
First, create a blank table with one row using the Create Table operator.
1. | Drag and drop a Create Table operator onto your Data Workflow canvas. |
2. | Configure the Create Table operator’s Info window as follows: |
Setting | Value |
---|---|
Category |
Create Table |
Label |
|
Create Index |
No |
Rows |
1 |
Configure the First Set Operator
You need two Set operators to add your arrays to your empty table. The first Set operator puts the values x, y, and z into the path [0].value. In other words, the array [x,y,z] is the output from the Column A Col2Array. The Set operator sets it as the value of an object at index 0 of the array from your Create Table.
1. | Drag and drop a Set operator onto your Data Workflow canvas. |
2. | Configure the Set operator’s Info window as follows: |
Setting | Value |
---|---|
Category |
Set |
Label |
[0].value |
Path |
[0].value |
Value |
|
Default Value |
|
3. | Connect the output port (right) of the Create Table operator to the upper input port (left) of the Set operator. |
4. | Connect the output port (right) of the Column A Col2Array operator to the bottom input port (left) of the Set operator. |
Configure the Second Set Operator
The second Set operator puts the values 1, 2, and 3 into the path [1].value of the same table. In other words, the array [1,2,3] is the output from the Column B Col2Array. The Set operator sets it as the value of an object at index 1 of the array from your Create Table.
1. | Drag and drop another Set operator onto your Data Workflow canvas. |
2. | Configure the Set operator’s Info window as follows: |
Setting | Value |
---|---|
Category |
Set |
Label |
[1].value |
Path |
[1].value |
Value |
|
Default Value |
|
3. | Connect the output port (right) of the [0].value Set operator to the upper input port (left) of the [1].value Set operator. |
4. | Connect the output port (right) of the Column B Col2Array operator to the bottom input port (left) of the [1].value Set operator. |
Configure the Cartesian Operator
The Cartesian operator now arranges the values into an output of ordered pairs in a single array.
1. | Drag and drop a Cartesian operator onto your Data Workflow canvas. |
2. | Configure the Cartesian operator’s Info window as follows: |
Setting | Value |
---|---|
Category |
Cartesian |
Label |
Value |
Preserve Argument Type |
Unchecked (no) |
Type |
Array |
Field Label |
value |
3. | Connect the output port (right) of the [1].value Set operator to the input port (left) of the Cartesian operator. |
Configure the Console Operator
A Console operator lets you see the Outputs of your module in the DevTools Console. This ensures your Cartesian operator is configured correctly.
1. | Drag and drop a Console operator onto your Data Workflow canvas. |
2. | Configure the Console operator’s Info window as follows: |
Setting | Value |
---|---|
Category |
Console |
Label |
Output |
3. | Connect the output port (right) of the Cartesian operator to the input port (left) of the Console operator. |
4. | Click Save. |
Configure the Initializer Component
Finally, add an Initializer component to trigger the Data Workflow.
1. | Drag and drop an Initializer component onto your canvas, placing it above the Data Table component. |
4. | In the Outputs table, enter the following: |
Property ID |
Type |
Value | |
---|---|---|---|
1 |
dwfCartesian |
Trigger |
GO |
5. | Click Save & Close. |
6. | Save your module. |
Now, test your Data Workflow by previewing your module in Express View Express View is how your end-user views your application. Express View also lets you preview your applications to test your configuration and view the styling. This is also the view your end-users will see when interacting with your application. After configuring a module, click Preview in the Module Builder to interact with the module in Express View. and then opening the DevTools Console The DevTools Console helps you securely store, build, test, and deploy your software.. Your Output Console lists all of the possible combinations of your data.
Resources
-
You can view this complete use case here: https://training.unqork.io/#/form/60e72161f1709f2629c0f41e/edit .
-
Modify the Cartesian operator in the Data Workflow's configuration window.