Dimensions, Hierarchies, Levels
Some more definitions:
A member is a point within a dimension determined by a particular set of attribute values. The gender hierarchy has the two members 'M' and 'F'. 'San Francisco', 'California' and 'USA' are all members of the store hierarchy.
A hierarchy is a set of members organized into a structure for convenient analysis. For example, the store hierarchy consists of the store name, city, state, and nation. The hierarchy allows you form intermediate sub-totals: the sub-total for a state is the sum of the sub-totals of all of the cities in that state, each of which is the sum of the sub-totals of the stores in that city.
A level is a collection of members which have the same distance from the root of the hierarchy.
A dimension is a collection of hierarchies which discriminate on the same fact table attribute (say, the day that a sale occurred).
For reasons of uniformity, measures are treated as members of a special dimension, called 'Measures'.
An example
Let's look at a simple dimension.
<
Dimension name="Gender" foreignKey="customer_id">
<
Hierarchy hasAll="true" primaryKey="customer_id">
<
Table name="customer"/>
<
Level name="Gender" column="gender" uniqueMembers="true"/>
--
这里uniqueMenbers为true我想是因为Gender就两个值,一个M一个
F
,所以它可以设置为唯一。
</
Hierarchy>
</
Dimension>
This dimension consists of a single hierarchy, which consists of a single level called Gender
. (As we shall see later, there is also a special level called[(All)]
containing a grand total.)
The values for the dimension come from the gender
column in the customer
table. The "gender" column contains two values, 'F' and 'M', so the Gender dimension contains the members [Gender].[F]
and [Gender].[M]
.
For any given sale, the gender dimension is the gender of the customer who made that purchase. This is expressed by joining from the fact table "sales_fact_1997.customer_id" to the dimension table "customer.customer_id".
Mapping dimensions and hierarchies onto tables
A dimension is joined to a cube by means of a pair of columns, one in the fact table, the other in the dimension table. The <Dimension> element has a foreignKey attribute, which is the name of a column in the fact table; the <Hierarchy> element has primaryKey attribute.
If the hierarchy has more than one table, you can disambiguate using the primaryKeyTable attribute.
The uniqueMembers attribute is used to optimize SQL generation. If you know that the values of a given level column in the dimension table are unique across all the other values in that column across the parent levels, then set uniqueMembers="true", otherwise, set to "false". For example, a time dimension like [Year].[Month]
will have uniqueMembers="false" at the Month level, as the same month appears in different years. On the other hand, if you had a [Product Class].[Product Name] hierarchy, and you were sure that [Product Name] was unique, then you can set uniqueMembers="true". If you are not sure, then always set uniqueMembers="false". At the top level, this will always be uniqueMembers="true", as there is no parent level.