Joins in the SQL API
Views
The best practice is to use views to specify explicit join paths for SQL API queries. While BI tools would see a view as a table, in fact, no materialization is performed until Cube is queried through the SQL API. At the query time, Cube will try to maximize member pushdown, so only required parts of the view are materialized at query time. Cube also solves fan and chasm traps based on the dimensions selected in the query, so if measure aggregation types are properly set up, you will see correct results in BI tools even though cubes and views are seen just as tables. Consider the following data model:CROSS JOIN and __cubeJoinField
The SQL API also supports joins through the __cubeJoinField virtual column, which
allows to control how specific cubes are joined. This is considered an advanced
functionality, and views should be used where possible. Join can also be done through
CROSS JOIN.
Usage of CROSS JOIN or __cubeJoinField instructs Cube to perform join as it’s defined
in a data model while using provided cubes as join hints.
For example, the following query joins the orders and products tables under
the hood on orders.product_id = products.id, exactly the same way as the
REST API query does:
CROSS JOIN:
__cubeJoinField to define joins between cube
tables. In tools that allow defining custom SQL datasets, you can use joined
tables as a dataset SQL. For example:
EXPLAIN plan for this query:
product_description is in the inner selection, it isn’t
evaluated in the final query as it isn’t used in any way.