cartesian-product

When applying a cartesian product to two worksheets A and B, this directive pairs every row in worksheet B with every row in worksheet A.

When applying the cartesian product directive to two worksheets A and B, this directive pairs every row in worksheet B with every row in worksheet A. The resulting row set would have as many rows as the total number of rows in worksheet A multiplied by the total number of rows in worksheet B.

Download Example

Consider the following worksheets Customers and Discounts.

Here is the Customers worksheet. It has 3 rows.

Customer IDBalance
c045
c13
c20

Here is the Discounts worksheet. It has 2 rows.

Discount IDPercentage
d00.5
d10.1

Here is the comment snippet that will direct Pebble Stream to apply the cartesian product to the Customers and Discounts worksheets. Notice the use of the "from" directive to identify the first worksheet in the cartesian product as Customers.

pebblestream:from(Customers)
pebblestream:cartesian-product(Discounts)

Resulting in the final worksheet with 6 (2 x 3) rows.

Customer IDBalanceDiscount IDPercentage
c045d00.5
c045d10.1
c13d00.5
c13d10.1
c20d00.5
c20d10.1

❗️

Performance Tip

Be careful with cartesian products. The number of rows it produces can grow quite quickly!

👍

Use Case Tip

Cartesian products are great for applying multiple discounts to a customer's basket of items. Whenever you have a group of percentages that you need to apply to every item using a cartesian product is a good bet.