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 article, you'll learn:

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.

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, y create a simple module. You'll start with some sample data. Then, you'll use a Data Workflow and a Cartesian operator to see all of the possible combinations.

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. Instead, look at the DevTools Console:

What You'll Need

To set up this use case, you’ll need:

  • 1 Data Table component

  • 1 Initializer component

  • 1 Data Workflow component

To set up your Data Workflow, you'll need:

  • 1 Input operator

  • 2 Col2Array operators

  • 1 Create Table operator

  • 2 Set operators

  • 1 Cartesian operator

  • 1 Console operator

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.
2. Enter dtSampleData in the Label and Property Name fields.
3. Enter the following values in the Data Table:
A B

x

1

y

2

z

3

4. Click Save.

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. Place your Data Workflow below the Data Table.
2. Enter dwfCartesian in the Canvas Label Text and Property Name fields.


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

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. 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. Save the Data Workflow.

Configure the Initializer Component

Finally, add an Initializer component to trigger the Data Workflow.

1. Drag and drop an Initializer component onto your canvas. Place the Initializer above the Data Table.
2. Enter initCartesian in the Property ID and Canvas Label Text fields.
3. Select New Submission as the Trigger Type.
4. Enter the following values in the Outputs table:
Property ID Type Value

dwfCartesian

Trigger

GO

5. Click Save.
6. Save your module.

Now, test your Data Workflow. Preview your module in Express View and open the DevTools console. Your Output Console lists all of the possible combinations of your data.

Changing a Cartesian Operator's Settings

You can revisit and make changes to this operator.

1. Click the Data Workflow component.

A 5-button toolbar displays above the component on hover-over.

2. Click the (Settings) button to open the Data Workflow canvas.
3. Click the operator to open its Info Window.
4. Make changes to the operator's settings as needed.
5. Click Save.
6. Save your module.

Copying a Cartesian Operator

You can make a copy of your operator using familiar keyboard settings. You can copy and paste an exact copy of your operator, matching all settings.

1. Hover over the Data Workflow component.

A 5-button toolbar displays above the component on hover-over.

2. Click the (Settings) button to open the Data Workflow canvas.
3. Click the operator you want to duplicate.
4. On your keyboard, press Command + C (Mac OS) or Ctrl + C (Windows/Linux) to copy the operator.

TIP  You can copy more than one operator at a time. Hold Command or Ctrl on your keyboard and click all the operators you want to copy. Follow the rest of the steps as usual.

5. On your keyboard, press Command + V (Mac OS) or Ctrl + V (Windows/Linux) to paste the copied operator(s) to the Data Workflow canvas.
6. Click Save.
7. Save your module.

TIP  Did you know you can copy an operator and paste it into a different Data Workflow? You'll use the same steps outlined above.

Removing a Cartesian Operator

Lastly, you can delete this operator from your Data Workflow canvas. You can also use these same steps to delete a connection between two operators.

1. Hover over the Data Workflow component.

A 5-button toolbar displays above the component on hover-over.

2. Click the (Settings) button to open the Data Workflow canvas.
3. Click the operator you want to delete.
4. On your keyboard, press Delete.

NOTE  Once you delete this operator, make sure to connect your remaining operators. If your Data Workflow path doesn't end with an Output or Console operator, your Data Workflow won't work. So, once you delete an operator, make sure to update any remaining paths to end at an Output or Console operator.

5. Click Save.
6. Save your module.

Lab

You can view this complete use case here: https://training.unqork.io/#/form/60e72161f1709f2629c0f41e/edit