Joining data from multiple data sources
Use case
Let’s imagine we store information about products and their suppliers in separate databases. We want to aggregate data from these data sources while having decent performance. In the recipe below, we’ll learn how to create a rollup join between two databases to achieve our goal.Configuration
First of all, we should define our database connections with thedataSource
option in the cube.js configuration file:
Data modeling
First, we’ll define rollup pre-aggregations forproducts and suppliers. Note that these
pre-aggregations should contain the dimension on which they’re joined. In this
case, it’s the supplier_id dimension in the products cube, and the id
dimension in the suppliers cube:
rollup_join pre-aggregation in the products cube,
which will enable aggregating data from multiple data sources:
Query
Let’s get the product names and their suppliers’ info, such as company name and email, with the following query:Result
We’ll get the data from two pre-aggregations joined into onerollup_join:
Source code
Please feel free to check out the full source code or run it with thedocker-compose up command. You’ll see the result, including
queried data, in the console.