# Schemas

{% hint style="info" %}

#### Schema Versions

A schema defines a multi-dimensional Star / Snowflake database. It contains a logical model, consisting of cubes, hierarchies, and members, and a mapping of this model onto a physical model.&#x20;

The logical model consists of the constructs used to write queries in MDX language: cubes, dimensions, hierarchies, levels, and members.

The physical model is the source of the data which is presented through the logical model. It is typically a star schema, which is a set of tables in a relational database.&#x20;
{% endhint %}

<figure><img src="https://1484061793-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdXTGZYWCBVihMNYi24vO%2Fuploads%2FkM8zd2uWeuc89h13EMwP%2Fimage.png?alt=media&#x26;token=8270d2a8-3e61-4722-87df-cfdae79ccdf3" alt=""><figcaption><p>Mondrian 3 Schema</p></figcaption></figure>

{% embed url="<https://mondrian.pentaho.com/documentation/schema.php>" %}

***

1. Select Model canvas > Model Structure.

<figure><img src="https://1484061793-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdXTGZYWCBVihMNYi24vO%2Fuploads%2Fh98MnpQ1HcG00dIAdJKw%2Fimage.png?alt=media&#x26;token=4a4aa9fc-0d5c-4aa2-a7a7-57f6cb37712f" alt=""><figcaption><p>View Model Structure</p></figcaption></figure>

Explore the Schema constructs:

{% tabs %}
{% tab title="Schema" %}
{% hint style="info" %}

#### Schema Element

The Schema element is the root container of a Mondrian schema file. Think of it as the outer wrapper that holds everything else. Every Mondrian schema XML file has exactly one Schema element.

Every schema needs a name attribute, though Mondrian doesn't use it for critical operations. It's recommended that you also add a description attribute to explain what the schema does in human-readable terms.

You should also specify metamodelVersion="3.14" as this helps track which version of the schema format you're using.

The Schema element contains all the building blocks of your data model. It always requires a PhysicalSchema element, which defines the actual database tables and columns.

Typically, a schema includes one or more Cube elements that define the multidimensional data structures. It may also contain Dimension elements for shared dimensions that multiple cubes can use, and Role elements for access control and security settings.

An analyst typically creates the Schema first as the outer container, then fills it with the components needed to answer business questions, such as dimensions and cubes.

Think of it like a filing cabinet: the Schema is the cabinet itself, and you fill the drawers with organized folders (cubes, dimensions) that help answer specific business questions.

Does this help clarify the concept?
{% endhint %}

```xml
<Schema name="SteelWheels"
caption="Steel Wheels"
description="Optimizing the Sales process at Steel Wheels Inc"
metamodelVersion="3.14" measuresCaption="Metrics"
defaultRole="Associate" missingLink="warning">
```

1. Select \</> Advanced tab to view the XML

<figure><img src="https://1484061793-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdXTGZYWCBVihMNYi24vO%2Fuploads%2FjZvCqcxDyant5tv28DLc%2Fimage.png?alt=media&#x26;token=a3551867-720b-433c-9f80-66df4cccefc0" alt=""><figcaption><p>View XML</p></figcaption></figure>

{% hint style="info" %}
In Mondrian v3 the schema parser was extremely sensitive about the order of child elements. If you\
get child elements in the wrong order (for example, a cube after a role..), Mondrian will ignore the\
cube.
{% endhint %}
{% endtab %}

{% tab title="Cube" %}
{% hint style="info" %}

#### Cube Element

A cube, defined by a Cube XML element, is the context for a report or interactive analysis session. It\
represents a collection of events, describing the occurrences of a business process over the lifetime of\
the data mart.

Cubes tend to be a complete set of Dimensions, Hierarchies, Levels and Measures for doing an analysis on the set of events. For instance, if you’re interested in sales by customer, you might want to look at sales amounts (Measures) by customer (Dimension) geography (Level).

A cube collects these things into one place, ready for analysis and querying.
{% endhint %}

```xml
<Cube name="Sales 2003 to 2005">
<Table name=”ORDERFACT” />

<Dimension>
...
</Dimension>
<Measure>
...
</Measure> 
</Cube> 
```

1. Click on the 3 dots > Edit option for the Sales\_2003\_2005 cube.

<figure><img src="https://1484061793-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdXTGZYWCBVihMNYi24vO%2Fuploads%2FJc5WcjGnxPGaKdw8dCoe%2Fimage.png?alt=media&#x26;token=714ff867-1637-400a-bcd5-444c8756cf78" alt=""><figcaption><p>Edit Cube settings</p></figcaption></figure>

2. The Cube Editor enables you to edit and apply any changes.

<figure><img src="https://1484061793-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdXTGZYWCBVihMNYi24vO%2Fuploads%2Fbdmt87P9HzR6JaBYIbPy%2Fimage.png?alt=media&#x26;token=bf38aa9f-a714-40f1-8686-c4e708300b32" alt=""><figcaption><p>Cube Editor</p></figcaption></figure>

{% hint style="info" %}
Recall that a cube is a collection of Dimensions, Hierarchies, Levels (attributes Mondrian v4) and\
Measures. The Measures quantitatively describe events or collections of events, and the Levels\
represent the context in which the events occurred.

Each combination of Levels and Measures is effectively a new report that can be created in seconds.
{% endhint %}

| Attribute                | Description                                                                                                       |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------- |
| **Mandatory**            |                                                                                                                   |
| Cube name                | Cube name !                                                                                                       |
| **Optional Information** |                                                                                                                   |
| Default Measure          |                                                                                                                   |
| Cache                    | Should the Fact table data for this Cube be cached by Mondrian or not. The default action is to cache the data.   |
| Visible                  | Whether this cube is visible in the user-interface.                                                               |
| Enabled                  | Whether element is enabled - if true, then the Cube is realized otherwise it is ignored.                          |
| **Describe Cube**        |                                                                                                                   |
| Caption                  | A string being displayed instead of the cube's name. Can be localized from Properties file using #{propertyname}. |
| Description              | Description of this cube. Can be localized from Properties file using #{propertyname}.                            |

x
{% endtab %}

{% tab title="Dimension" %}
{% hint style="info" %}

#### Dimension

A Dimension is a structural attribute of a Cube that is a list of related names – known as Members – all of which belong to a similar category in the user’s perception of a data. For example, months and quarters may make up a Months dimension; likewise, all cities, regions and countries may make up a Region dimension.&#x20;

A Dimension acts an index for identifying values within a multidimensional array and offers a\
very concise, intuitive way of organizing and selecting data for retrieval, exploration and analysis.\
Dimensions are the business parameters normally seen in the rows and columns of a report. A\
Dimension is a collection of logically related attributes, equivalent to a table.
{% endhint %}

1. Click on the 3 dots > Edit option for MARKETS dimension.

<figure><img src="https://1484061793-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdXTGZYWCBVihMNYi24vO%2Fuploads%2F3DFEafqvFdp7UQ2GQNEp%2Fimage.png?alt=media&#x26;token=063d4211-2a0c-4ffb-8f20-19ab2d018888" alt=""><figcaption><p>Edit MARKETS Dimension</p></figcaption></figure>

2. The Dimension Editor enables you to edit and apply any changes.

<figure><img src="https://1484061793-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdXTGZYWCBVihMNYi24vO%2Fuploads%2FPaWabj2I1xltnhp2pjcP%2Fimage.png?alt=media&#x26;token=1f5eb6ff-c178-43b1-a736-0f6ffd9ae947" alt=""><figcaption><p>Dimension Editor</p></figcaption></figure>

<table><thead><tr><th width="152">Attribute</th><th>Description</th></tr></thead><tbody><tr><td><strong>Mandatory</strong></td><td></td></tr><tr><td>Dimension Name</td><td>Dimension name</td></tr><tr><td><strong>Connect to the Fact Table</strong></td><td></td></tr><tr><td>Fact Table Column</td><td>The name of the column in the fact table.</td></tr><tr><td><strong>Dimension Type</strong></td><td></td></tr><tr><td>Type</td><td>The dimension's type may be one of "Standard" or "Time". A time<br>dimension will allow the use of the MDX time functions (WTD, YTD,<br>QTD, etc.). Use a standard dimension if the dimension is not a timerelated dimension.<br>The default value is "Standard".</td></tr><tr><td><strong>Optional Information</strong></td><td></td></tr><tr><td>Visible</td><td>Whether this dimension is visible in the user-interface. Default<br>true.</td></tr><tr><td>Usage prefix</td><td>Adds a text prefix to a dimension's column names in aggregate tables to prevent naming conflicts when multiple dimensions use similar column names.. This should only be set for private dimensions.</td></tr><tr><td><strong>Describe Dimension</strong></td><td></td></tr><tr><td>Caption</td><td>A string being displayed instead of the dimensions’ name. Can be<br>localized from Properties file using #{propertyname}.</td></tr><tr><td>Description</td><td>Description of this dimension. Can be localized from Properties fileusing #{propertyname}.</td></tr></tbody></table>
{% endtab %}

{% tab title="Hierarchy" %}
{% hint style="info" %}

#### Hierarchy

Hierarchies allow for a better experience in the user interface. A hierarchy is a way to organize data at\
different levels of aggregation. In viewing data, analysts use dimension hierarchies to recognize trends at one level, drill down to lower levels to identify reasons for these trends and roll up to higher levels to see what affect these trends have on a larger sector of the business.
{% endhint %}

1. Click on the Markets Hierarchy.
2. The Dimension Editor enables you to edit and apply any changes.

<figure><img src="https://1484061793-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdXTGZYWCBVihMNYi24vO%2Fuploads%2FYZDddOobvz9D2GYIXLdQ%2Fimage.png?alt=media&#x26;token=7e503b20-3034-4a98-81e7-36be35bcfab7" alt=""><figcaption><p>Hierarchy</p></figcaption></figure>

{% hint style="info" %}
The Level in each hierarchy must have a strict one-to-many relationship with the next level. In the\
\[Markets] hierarchy, each Country belongs to only one Territory, and each City belongs to only one State Province. The net effect is that each level down has more members than the last.
{% endhint %}

<table><thead><tr><th width="192">Attribute</th><th>Decription</th></tr></thead><tbody><tr><td><strong>Hierarchy Name</strong></td><td></td></tr><tr><td>Name</td><td>Name of the hierarchy. If this is not specified, the hierarchy has the same name as its dimension.</td></tr><tr><td><strong>Mandatory Data</strong></td><td></td></tr><tr><td>Source Table</td><td>The name of the table which contains primaryKey. If<br>the hierarchy has only one table, defaults to that; it is<br>required.</td></tr><tr><td>Alias</td><td></td></tr><tr><td>Hierarchy Key</td><td>The name of the column which identifies members,<br>and which is referenced by rows in the fact table. If not<br>specified, the key of the lowest level is used. See also<br>CubeDimension.foreignKey.</td></tr><tr><td>Has All</td><td>Whether this hierarchy has an 'all' member.</td></tr><tr><td><strong>Optional Information</strong></td><td></td></tr><tr><td>visible</td><td>Whether this hierarchy is visible in the user-interface.<br>Default true.</td></tr><tr><td>All Member Name</td><td>Name of the 'all' member. If this attribute is not<br>specified, the all member is named 'All hierarchyName',<br>for example, 'All Store'.</td></tr><tr><td>All Member Caption</td><td>A string being displayed instead as the all member's<br>name. Can be localized from Properties file using<br>#{propertyname}.</td></tr><tr><td>All Level Name</td><td>Name of the 'all' level. If this attribute is not specified,<br>the all member is named '(All)'. Can be localized from<br>Properties file using #{propertyname}.</td></tr><tr><td>Default Member</td><td>Default member value</td></tr><tr><td>Member Reader Class</td><td>Name of the custom member reader class. Must<br>implement the mondrian.rolap.MemberReader<br>interface.</td></tr><tr><td>Origin</td><td></td></tr><tr><td>Display Folder</td><td>String value to specify the folder in which to list the hierarchy for users in <strong>Pentaho Analyzer</strong>.</td></tr><tr><td>Unique Key Level Name</td><td></td></tr><tr><td><strong>Describe Hierarchy</strong></td><td></td></tr><tr><td>Caption</td><td>A string to be displayed in the user interface. If not<br>specified, the hierarchy's name is used. Can be<br>localized from Properties file using #{propertyname}.</td></tr><tr><td>Description</td><td>Description of this hierarchy. Can be localized from<br>Properties file using #{propertyname}.</td></tr></tbody></table>

{% hint style="info" %}
By default, every hierarchy contains a top level called '(All)', which contains a single member called '(All {hierarchyName})'. This member is parent of all other members of the hierarchy, and thus represents a grand total.

The all member is also the default member of the hierarchy; that is, the member that is used for calculating cell values when the hierarchy is not included on an axis or in the slicer. Various attributes allow you to control the all level and member. The element's allMemberName and allLevelName attributes override the default names of the all level and all member.

If the element has hasAll="false", the 'all' level is suppressed. The default member of that dimension will now be the first member of the first level; for example, in a Time hierarchy, it will be the first year in the hierarchy. Changing the default member can be confusing, so you should generally use hasAll="true".

You can also set the default member of a hierarchy explicitly. The defaultMember attribute should be\
the fully-qualified name of the default member.
{% endhint %}

```xml
<Hierarchy name="Yearly" hasAll="false"  defaultMember="[Time].[1997].[Q1].[1]">
    ...
    </Hierarchy> 
```

{% hint style="info" %}
When specified in this way, the default member can even be a calculated member.
{% endhint %}
{% endtab %}

{% tab title="Level" %}
{% hint style="info" %}

#### Level

The Level Element can be thought of as representing a column in a table. It’s a collection of Members\
that are the same distance from the root of the hierarchy.
{% endhint %}

1. Click on the Territory Level.
2. The Dimension Editor enables you to edit and apply any changes.

<figure><img src="https://1484061793-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdXTGZYWCBVihMNYi24vO%2Fuploads%2F2ESICmN0jXlJsicHHu0C%2Fimage.png?alt=media&#x26;token=26926edf-8c9b-4295-9ebe-7bdc3d585ada" alt=""><figcaption><p>Level</p></figcaption></figure>

<table><thead><tr><th width="182">Attribute</th><th>Description</th></tr></thead><tbody><tr><td><strong>Level Name</strong></td><td></td></tr><tr><td>Name</td><td>Name of the Level.</td></tr><tr><td><strong>Level Source</strong></td><td></td></tr><tr><td>Source Table</td><td>The name of the table that the column comes from. If this<br>hierarchy is based upon just one table, defaults to the name<br>of that table; otherwise, it is required. Can be localized from<br>Properties file using #{propertyname}.</td></tr><tr><td>Column</td><td>The name of the column which holds the unique identifier of<br>this level.</td></tr><tr><td><strong>Relevant Information</strong></td><td></td></tr><tr><td>Name Column</td><td>The name of the column which holds the user identifier of<br>this level.</td></tr><tr><td>Ordinal Column</td><td>The name of the column which holds member ordinals. If<br>this column is not specified, the key column is used for<br>ordering.</td></tr><tr><td><strong>Optional Information</strong></td><td></td></tr><tr><td>Visible</td><td></td></tr><tr><td>Aapprox Row Count</td><td>The estimated number of rows in this aggregation table. Setting this property improves the performance of the aggregation optimizer and prevents it from issuing a 'select count(*)' query over the aggregation table.</td></tr><tr><td>Null Parent Value</td><td>Value which identifies null parents in a parent-child<br>hierarchy. Typical values are 'NULL' and '0'.</td></tr><tr><td>Key Column Type</td><td>Indicates the type of this level's key column: String, Numeric,<br>Integer, Boolean, Date, Time or Timestamp. When<br>generating SQL statements, Mondrian encloses values for<br>String columns in quotation marks, but leaves values for<br>Integer and Numeric columns un-quoted.<br>Date, Time, and Timestamp values are quoted according to<br>the SQL dialect. For a SQL-compliant dialect, the values<br>appear prefixed by their typename, for example, "DATE<br>'2006-06-01'".</td></tr><tr><td>Internal Type</td><td>Indicates the Java type that Mondrian uses to store this<br>level's key column. It also determines the JDBC method that<br>Mondrian will call to retrieve the column; for example, if the<br>Java type is 'int', Mondrian will call 'ResultSet.getInt(int)'.<br>Usually this attribute is not needed, because Mondrian can<br>choose a sensible type based on the type of the database<br>column.<br>Allowable values are: 'int', 'long', 'Object', 'String'.</td></tr><tr><td>Unique Members</td><td>Whether members are unique across all parents. For<br>example, zipcodes are unique across all states. The first<br>level's members are always unique.</td></tr><tr><td>Level Type</td><td>Whether this is a regular or a time-related level. The value<br>makes a difference to time-related functions such as YTD<br>(year-to-date).<br>The "TimeHalfYear" value is deprecated and will be removed in mondrian-4.0; use "TimeHalfYears" instead.</td></tr><tr><td>Hide Member Iif</td><td>Condition which determines whether a member of this level<br>is hidden. If a hierarchy has one or more levels with hidden<br>members, then it is possible that not all leaf members are<br>the same distance from the root, and it is termed a ragged<br>hierarchy.<br>Allowable values are: Never (a member always appears; the<br>default); IfBlankName (a member doesn't appear if its name<br>is null, empty or all whitespace); and IfParentsName (a<br>member appears unless its name matches the parent's.</td></tr><tr><td>Formatter Class</td><td><p>Name of a formatter class for the member labels being displayed. The class must implement the mondrian.spi.MemberFormatter interface.<br>This attribute is deprecated. </p><p>Please use a nested MemberFormatter element.</p></td></tr><tr><td>Caption Column</td><td>The name of the column which holds the caption for<br>members.</td></tr><tr><td>Parent Column</td><td>The name of the column which references the parent<br>member in a parent-child hierarchy.</td></tr><tr><td><strong>Describe Level</strong></td><td></td></tr><tr><td>Caption</td><td>A string being displayed instead of the level's name. Can be<br>localized from Properties file using #{propertyname}.</td></tr><tr><td>Description</td><td>Description of this Level. Can be localized from<br>Properties file using #{propertyname}.</td></tr></tbody></table>
{% endtab %}

{% tab title="Properties" %}
{% hint style="info" %}

#### Properties

Many dimensions, such as Customer, are large, and it is useful to subset them for viewing purposes\
even before you create a query. You might want to subset information by customer first / last name,\
address, income level, educational background, or marital status before you begin to drill down into a\
data set, stratifying the population.
{% endhint %}

{% hint style="warning" %}
To add Properties & Annotations you will have to manually edit the XML.
{% endhint %}

1. Select the Advanced tab.
2. Scroll to the MARKETS Dimension to see how Annotations are applied & CUSTOMERS for Properties.

<figure><img src="https://1484061793-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdXTGZYWCBVihMNYi24vO%2Fuploads%2FR8cJDNeXrn39CI5AlPFA%2Fimage.png?alt=media&#x26;token=88686455-5678-4340-84f9-cfbb8f90a907" alt=""><figcaption><p>Annotations &#x26; Properties</p></figcaption></figure>

<table><thead><tr><th width="203">Attribute</th><th>Value</th></tr></thead><tbody><tr><td>name</td><td>The name of the Property.</td></tr><tr><td>description</td><td>Description of this member property. Can be localized<br>from Properties file using #{propertyname}.</td></tr><tr><td>column</td><td>The data column that will determine this subcategory's content</td></tr><tr><td>type</td><td>Data type of this property: String, Numeric, Integer,<br>Boolean, Date, Time or Timestamp.</td></tr><tr><td>formatter</td><td>Name of a formatter class for the appropriate property value being displayed.<br>The class must implement the mondrian.spi.PropertyFormatter interface.<br>This attribute is deprecated. Please use a nested PropertyFormatter element.</td></tr><tr><td>caption</td><td>A string being displayed instead of the name. Can be<br>localized from Properties file using #{propertyname}.</td></tr><tr><td>dependsOnLevelValue</td><td>Should be set too true if the value of the property is functionally dependent on the level value. This  permits the associated property column to be omitted from the GROUP BY clause (if the database permits columns in the SELECT that are not in the GROUP BY).<br>This can be a significant performance enhancement on some databases, such as MySQL.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}
