Adobe Flex 3 Help

Creating an OLAP schema

An OLAP schema defines the representation of your flat data in an OLAP cube, and defines how to aggregate your data for an OLAP query. You typically define your schema in MXML. While you can construct a schema programmatically in ActionScript, that method requires much more coding than MXML.

The following table describes the classes and interfaces that you use to define an OLAP schema:

Class

Interface

Description

OLAPSchema

IOLAPSchema

The schema instance.

OLAPCube

IOLAPCube

The OLAP cube created by the schema.

OLAPDimension

IOLAPDimension

A dimension of the schema.

OLAPAttribute

IOLAPAttribute

An attribute of a dimension

OLAPHierarchy

IOLAPHierarchy

A hierarchy of a dimension.

OLAPLevel

IOLAPLevel

A level of a hierarchy.

OLAPMeasure

IOLAPMeasure

A measure of a dimension.

General form of a schema definition

In MXML, you can define an OLAP schema as part of the definition of an OLAPCube instance. Typically, you set any properties of the OLAPCube instance as tag attributes, and set the OLAPCube.dimensions and OLAPCube.measures properties as child tags, as the following example shows:

<mx:OLAPCube name="FlatSchemaCube" 
    dataProvider="{flatData}" 
    id="myMXMLCube"
    complete="runQuery(event);">

    <!-- Define dimensions. -->
    <mx:OLAPDimension ... />

    <mx:OLAPDimension ... />        
    ...

    <!-- Define measures. -->
    <mx:OLAPMeasure ... />
    ...
</mx:OLAPCube>

The order of the OLAPDimension and OLAPMeasure definitions is not important, but you should not place OLAPMeasure definitions between OLAPDimension definitions.

Specifying the aggregation method for a measure

As part of creating an OLAP schema, you specify the data field that provides the value of the measure for each point in the cube. The measure corresponds to the data value at that point in the OLAP cube. For example, if you define a schema for sales information, you might specify as a measure of the cube the revenue for a product, and the aggregation type as SUM.

A schema can define one or more measures for a single point in the OLAP cube. The first measure in the schema is called the default measure, and is the measure returned by an OLAP query when you do not explicitly specify the measure to return. For more information on selecting a specific measure, see Creating a query using a nondefault measure.

The following example shows a section of an MXML schema definition that specifies two measures for the schema:

<mx:OLAPMeasure name="Revenue" dataField="revenue" aggregator="SUM"/>
<mx:OLAPMeasure name="Cost" dataField="cost" aggregator="SUM"/>

When creating a schema, you specify the name of the measure, the data field in the input flat data that contains the data for the measure, and an aggregation method of the measure. In this example, the aggregation method is SUM. That means when you create an OLAP query for a measure, the query sums all revenue fields to generate the values displayed by the OLAPDataGrid control. You could use this schema to define a cube so that you can total sales and cost information for products, regions, and other characteristics of your data.

To aggregate the revenue data using a different aggregation method, such as average or maximum, create another schema to define a second OLAP cube. The following example shows a section of another MXML schema definition that specifies the aggregation method as MAX for the sales data and MIN for the cost data:

<mx:OLAPMeasure name="Revenue" dataField="revenue" aggregator="MAX"/>
<mx:OLAPMeasure name="Cost" dataField="cost" aggregator="MIN"/>

You should take care in how you define your schema because it can limit the types of queries that you can run on it, or the level of detail at which you can create aggregations.

Creating a schema dimension

An OLAPSchema instance can define any number of dimensions, limited only by your input data. A dimension can be a simple dimension with a single level, or it can be a complex dimension with multiple levels. The dimension of a schema always has the same basic form:

<mx:OLAPDimension name="QuarterDim">
    <mx:OLAPAttribute name="Quarter" dataField="quarter"/>
    ...
    <mx:OLAPHierarchy name="QuarterHier" hasAll="true">
        <mx:OLAPLevel attributeName="Quarter"/>
        ...
    </mx:OLAPHierarchy> 
</mx:OLAPDimension>

Notice that in this schema:

  • The dimension first uses OLAPAttribute class to specify the data fields of the input data set used to populate the members of the dimension.

The dimension defines an instance of the OLAPHierarchy class. Therefore, a dimension is always assumed to contain a hierarchy of levels, even if that hierarchy contains only a single level.

  • The dimension specifies one or more instances of the OLAPLevel class to associate a field of the input with the dimension.

Defining a dimension that contains a single level

To create a simple dimension (a dimension that contains a single level), you define a dimension hierarchy, as the following example shows:

<mx:OLAPDimension name="CustomerDim">
    <mx:OLAPAttribute name="Customer" dataField="customer"/>
    <mx:OLAPHierarchy name="CustomerHier" hasAll="true">
        <mx:OLAPLevel attributeName="Customer"/>
    </mx:OLAPHierarchy>
</mx:OLAPDimension>

In this example, the customer field of the input data defines the entire measure of the dimension.

Defining a dimension that contains multiple levels

Instead of creating a separate dimension for each field of your data, you can choose to group related data fields along a single dimension. For example, your data might contain several fields related to the time of a transaction, such as month, quarter, and year. Or your data might contain multiple fields associated with the geographical area of a transaction, such as region, state, province, or country.

The TimeDim dimension in the following example defines hierarchical dimensions that contain two levels, one for year and one for quarter:

<mx:OLAPCube name="FlatSchemaCube" 
    dataProvider="{flatData}" 
    id="myMXMLCube">
 
    <mx:OLAPDimension name="TimeDim">
        <mx:OLAPAttribute name="Year" dataField="year"/>
        <mx:OLAPAttribute name="Quarter" dataField="quarter"/>
        <mx:OLAPHierarchy name="Time-PeriodHier" hasAll="true">
            <mx:OLAPLevel attributeName="Year"/>
            <mx:OLAPLevel attributeName="Quarter"/>
        </mx:OLAPHierarchy> 
    </mx:OLAPDimension>

    <mx:OLAPMeasure name="Revenue"dataField="revenue" aggregator="SUM"/>
</mx:OLAPCube>

With this schema definition, you can aggregate data for all time, for individual years, for individual quarters, or for individual quarters of a specific year.

Notice that the TimeDim dimension contains a Year level, the most general level, and a Quarter level, the more detailed level. The first level in the hierarchy typically defines the most general level, and each subsequent level provides a greater level of detail.

If your data contained a month field with the month of the year for a transaction, you can add the Month level to the TimeDim dimension. Since month is a more detailed measure of time than quarter, add the Month level after the Quarter level, as the following example shows:

<mx:OLAPDimension name="TimeDim">
    <mx:OLAPAttribute name="Year" dataField="year"/>
    <mx:OLAPAttribute name="Quarter" dataField="quarter"/>
    <mx:OLAPAttribute name="Month" dataField="month"/>
    <mx:OLAPHierarchy name="Time-PeriodHier" hasAll="true">
        <mx:OLAPLevel attributeName="Year"/>
        <mx:OLAPLevel attributeName="Quarter"/>
        <mx:OLAPLevel attributeName="Month"/>
    </mx:OLAPHierarchy> 
</mx:OLAPDimension>

The advantage of creating a hierarchical schema is that you can write queries to extract top-level data aggregations or to drill down into the data to extract more granular data. For the previous schema definition, you can write an OLAP query to aggregate data by the most general field, such as year, or drill down to obtain more granular results by aggregating your data by quarter in each year, by month in each quarter, or by month in each year.

Creating a default member in a schema

Most of the OLAP schemas shown so far have been defined in the following form:

<mx:OLAPDimension name="TimeDim">
    <mx:OLAPAttribute name="Year" dataField="year"/>
    <mx:OLAPAttribute name="Quarter" dataField="quarter"/>
    <mx:OLAPHierarchy name="Time-PeriodHier" hasAll="true">
        <mx:OLAPLevel attributeName="Year"/>
        <mx:OLAPLevel attributeName="Quarter"/>
    </mx:OLAPHierarchy> 
</mx:OLAPDimension>

In this schema, the hierarchy sets the OLAPHierarchy.hasAll property to true to create a default member for the hierarchy. The default member is created automatically for the hierarchy and contains an aggregation of all levels in the hierarchy. In the previous schema, the default member contains an aggregation of the measure of the schema for all years and all quarters.

The default member is used by OLAP queries when you do not specify any criteria to aggregate the dimension. For example, your OLAP schema contains a ProductDim, TimeDim, and CustomerDim dimension. You then write a query to extract data by product and customer, but omit any specification in the query for time. The OLAP query automatically uses the default member of the dimension to aggregate the information for the TimeDim dimension.

The default value of the OLAPHierarchy.hasAll property is true. If you set it to false, the OLAP query uses the first level in the hierarchy to aggregate the dimension. The following schema sets the hasAll property to false:

<mx:OLAPDimension name="TimeDim">
    <mx:OLAPAttribute name="Year" dataField="year"/>
    <mx:OLAPAttribute name="Quarter" dataField="quarter"/>
    <mx:OLAPHierarchy name="Time-PeriodHier" hasAll="false">
        <mx:OLAPLevel attributeName="Year"/>
        <mx:OLAPLevel attributeName="Quarter"/>
    </mx:OLAPHierarchy> 
</mx:OLAPDimension>

Because the hasAll property is false, an OLAP query automatically aggregates the data in the dimension by the Year level when you omit the TimeDim dimension from the query.

Modified 4/23/08: Change allLevelName to allMemberName.

By default, the OLAP cube adds a member to the dimension named (All)to represent the default member. You can use the OLAPHierarchy.allMemberName property to specify a different name, as the following example shows:

<mx:OLAPDimension name="TimeDim">
    <mx:OLAPAttribute name="Year" dataField="year" allMemberName="AllTime"/>
    <mx:OLAPAttribute name="Quarter" dataField="quarter"/>
    <mx:OLAPHierarchy name="Time-PeriodHier" hasAll="true">
        <mx:OLAPLevel attributeName="Year"/>
        <mx:OLAPLevel attributeName="Quarter"/>
    </mx:OLAPHierarchy> 
</mx:OLAPDimension>

When you execute an OLAP query, you choose whether or not to include the default member in the query results. For more information, see Using the default member in a query.