Skip to main content

View

Overview

In a Relational Database Management System (RDBMS), a view is a virtual table that presents data from one or more tables without storing the data itself. It simplifies complex queries, provides data abstraction, and enhances security by controlling access to the data. Views can present subsets of data, join tables, perform data transformations, and simplify queries. They're useful for security, simplifying queries, and presenting data in a meaningful way.

Wren Engine also provides the view for user to organize their data. You’re allowed to invoke any dataset defined in your Modeling Definition Language (MDL).

Define View

In MDL, we can define a list of views like:

[
{
"name": "useModel",
"statement": "select * from Orders"
},
{
"name": "useMetric",
"statement": "select * from Revenue"
},
{
"name": "useUseMetric",
"statement": "select * from useMetric"
}
]

It's easy to understand that a view can access anything in your MDL, such as a model, metric, or another view. The order of views doesn’t matter. You’re free to place your view anywhere you want. For example:

[
{
"name": "Revenue201306",
"statement": "select * from Revenue2013 where date_trunc('month', orderdate) = '2013-06-01'"
},
{
"name": "Revenue2013",
"statement": "select * from Revenue where date_trunc('year', orderdate) = '2013-01-01'"
}
]

The view useMetric is used by useUseMetric. However, it can be placed behind useMetric.

Query View

Just like Query Model. We can query the view like

SELECT * FROM useUseMetric

Limitation

  • The dependency of views can't be cycling. The case below is not permitted.
[
{
"name": "viewA",
"statement": "select * from viewB"
},
{
"name": "viewB",
"statement": "select * from viewA"
}
]
  • Wren Engine doesn’t recursive view. The case below is not permitted.
[
{
"name": "viewA",
"statement": "select * from viewA"
}
]