Skip to main content
Map-Reduce is supported by Tensorlake Applications to support large scale ETL of data. Map is the process of applying a function to each item of a list in parallel. Reduce is the process of aggregating the results of the map phase. The example below visualizes mapping of a list of numbers to their squares and reducing the results by summing the squares: Tensorlake automatically parallelizes function calls across multiple function containers when you map a function to a list. The reducer function is applied to each pair of mapped values sequentially in their original order in the list. Tensorlake runs each reduce function call as soon as its input values are available.

Blocking Map-Reduce

In the following code example, we calculate the square of each number and once we have all the squares, we sum them.

Non-blocking Map-Reduce

In the following code example, we calculate the square of each number and as soon as each square is available, we sum them. This is achieved using futures and tail calls. This reduces the overall duration of the Map-Reduce operation. The reduce function is still called sequentially in the original order of the list.

Inputs

List

Both map and reduce operations accept a list as operation inputs. Each item in the list can be a value, a Future, a Tensorlake coroutine, or an asyncio.Task object. Tensorlake recognizes these Futures/coroutines/asyncio.Task objects, runs them automatically, and uses their results as the input values for the operation.

Future / Coroutine / Task

Map and reduce operations accept a single Future/coroutine/asyncio.Task object as their input. The Future/coroutine/asyncio.Task object has to resolve to a list of items. Tensorlake automatically waits for it to complete and uses the returned list as the operation input. This is useful when the input list is produced by another Tensorlake function.

Tail calls

Map and reduce operation Futures can be returned from functions as tail calls. The returning function completes immediately and frees its container while Tensorlake orchestrates the map-reduce operation. This allows Tensorlake to optimize resource usage and reduce overall application latency.

Async Functions

Learn how to use async functions in Tensorlake applications.

Futures

Use Futures for parallel execution and tail calls.