# Pro SQL Server 2008 Analysis Services- P2

Chia sẻ: Thanh Cong | Ngày: | Loại File: PDF | Số trang:50

0
69
lượt xem
8

## Pro SQL Server 2008 Analysis Services- P2

Mô tả tài liệu
Download Vui lòng tải xuống để xem tài liệu đầy đủ

Tham khảo tài liệu 'pro sql server 2008 analysis services- p2', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả

Chủ đề:

Bình luận(0)

Lưu

## Nội dung Text: Pro SQL Server 2008 Analysis Services- P2

1. CHAPTER 2 CUBES, DIMENSIONS, AND MEASURES Figure 2-16. Selecting a different set of dimension members To further analyze the results, we may drill into the date hierarchy to see how the numbers compare by quarter or month. We could also compare these sales results to the sales of other products or number of customers. Maybe we’d like to look at repeat customers in each area (is France outperforming Italy on attracting new customers, bringing back existing customers, or both?). All these questions can be answered by leveraging various aspects of this cube. Incidentally, selection of various members is accomplished with a query language referred to as Multidimensional Expressions, or more commonly MDX. You’ll be looking at MDX in depth in Chapter 9. A question that may have come to mind by now: “Are measure values always added?” Although measures are generally added together as they are aggregated, that is not always the case. If you had a cube full of temperature data, you wouldn’t add the temperatures as you grouped readings. You would want the minimum, maximum, average, or some other manner of aggregating the data. In a similar vein, data consisting of maximum values may not be appropriate to average together, because the averages would not be representative of the underlying data. Types of Aggregation OLAP offers several ways of aggregating the numerical measures in our cube. But first we want to designate how to aggregate the data—either additive, nonadditive, or semiadditive measures. 31
3. CHAPTER 2 CUBES, DIMENSIONS, AND MEASURES Figure 2-17. A calendar dimension We have two choices. In our design, we can create a dimension that drills down to only the quarter level. Then the calendar quarters are the leaf level of the dimension, the bottom-most level, and the value for the quarter is just written into the cell for that quarter. Alternatively, some OLAP engines will allow the DBA to configure a dimension for spreading; when the engine writes back to the cube, it distributes the edited value to the child elements. The easiest (and usually default) option is to divide the new value by the number of children and divide it equally. An alternative that may be available if the analyst is editing a value is to distribute the new value proportionally to the old value. Writeback in general, and spreading in particular, are both very processor- and memory-intensive processes, so be judicious about when you implement them. You’ll look at writeback in Analysis Services in Chapter 11. Calculated Measures Often you’ll need to calculate a value, either from values in the measure (for example, extended price calculated by multiplying the unit cost by the number of items), or from underlying data, such as an average. Calculating averages is tricky; you can’t simply average the averages together. Consider the data in Table 2-1, showing three classes and their average grades. Table 2-1. Averaging Averages Classroom Number of Students Average Score Classroom A 20 100% Classroom B 40 80% Classroom C 80 75% 33
4. CHAPTER 2 CUBES, DIMENSIONS, AND MEASURES You can’t simply add 100, 80, and 75 then divide by 3 to get an average of 85. You need to go back to the original scores, sum them all together, and divide by the 140 students, giving an answer of 80 percent. This is another area where OLAP really pays off, because the OLAP engine is designed to run these calculations as necessary, meaning that all the user has to worry about is selecting the analysis they want to do instead of how it’s calculated. Actions Generally, an OLAP solution is the first-layer approach to analysis—it’s where you start. After you find something of interest, you generally want additional information. One method of getting amplifying data for something you find in an analysis is to drill through to the underlying data. Some analysis tools provide a way of doing this directly, at least to the fact table; others don’t. A more general way of gaining contextual insight into the data that you are looking at is to create a structure called an action. This enables an end user to easily view amplifying data for a given dimension member or measure. You can provide reports, drill-through data sets, web pages (Figure 2-18), or even executable actions. Figure 2-18. Using an action to open a map based on the member of the dimension Actions are attached to objects in the cube—a specific dimension, hierarchy or hierarchy level, measure, or a member of any of those. If the object will have several potential targets (as a dimension has multiple members), you will have to set up a way to link the member to the target (parsing a URL, creating a SQL script, passing a parameter to a report). For example, Listing 2-1 shows code used to assemble a URL from the members selected in an action that opens a web-based map. 34
5. CHAPTER 2 CUBES, DIMENSIONS, AND MEASURES Listing 2-1. Creating a URL from Dimension Members // URL for linking to MSN Maps "http://maps.msn.com/home.aspx?plce1=" + // Retreive the name of the current city [Geography].[City].CurrentMember.Name + "," + // Append state-province name [Geography].[State-Province].CurrentMember.Name + "," + // Append country name [Geography].[Country].CurrentMember.Name + // Append region parameter "&regn1=" + // Determine correct region parameter value Case When [Geography].[Country].CurrentMember Is [Geography].[Country].&[Australia] Then "3" When [Geography].[Country].CurrentMember Is [Geography].[Country].&[Canada] Or [Geography].[Country].CurrentMember Is [Geography].[Country].&[United States] Then "0" Else "1" End This code will take the members of the hierarchy from the dimension member you select to assemble the URL (the syntax is MDX, which you’ll take a quick look at in a few pages and dig into in depth in Chapter 9). This URL is passed to the client that requested it, and the client will launch the URL by using whatever mechanism is in place. Other actions operate the same way: they assemble some kind of script or query based on the members selected and then send it to the client. Actions that provide a drill-through will create a data set of some form and pass that to the client. All these connections are generally via XMLA. XMLA XML for Analysis (XMLA) was introduced by Microsoft in 2000 as a standard transport for querying OLAP engines. In 2001, Microsoft and Hyperion joined together to form the XMLA Council to maintain the standard. Today more than 25 companies follow the XMLA standard. XMLA is a SOAP-based API (because it doesn’t necessarily travel over HTTP, it’s not a web service). Fundamentally, XMLA consists of just two methods: discover and execute. All results are returned in XML. Queries are sent via the execute method; the query language is not defined by the XMLA standard. 35
6. CHAPTER 2 CUBES, DIMENSIONS, AND MEASURES That’s really all you need to know about XMLA. Just be aware of the transport mechanism and that it’s nearly a universal standard. It’s not necessary to dig deeper unless you discover a need to. Note For more information about XMLA, see http://msdn.microsoft.com/en-us/library/ms977626.aspx. Multidimensional Expressions (MDX) XMLA is the transport, so how do we express queries from OLAP engines? There were a number of query syntaxes before Microsoft introduced MDX with OLAP Services in 1997. MDX is designed to work in terms of measures, dimensions, and cubes, and returns structured data sets representing the dimensional nature of the cube. In working with OLAP solutions, you’ll work with both MDX queries and MDX statements. An MDX query is a full query, designed to return a set of dimensional data. MDX statements are parts of an MDX query, used for defining a set of dimensional data (for use in client tools, defining aspects of cube design, and so forth). A basic MDX query looks like this: SELECT [measures] ON COLUMNS, [dimension members] ON ROWS FROM [cube] WHERE [condition] Listing 2-2 shows a more advanced query, and Figure 2-19 shows the results from a grid in Excel. Listing 2-2. A More Advanced MDX Query SELECT {DrilldownLevel({[Date].[Calendar Year].[All Periods]})} ON COLUMNS, {DrilldownLevel({[Geography].[Geography].[All Geographies]})} ON ROWS FROM ( SELECT {[Geography].[Geography].[Country].&[United States], [Geography].[Geography].[Country].&[Germany], [Geography].[Geography].[Country].&[France]} ON COLUMNS FROM [Adventure Works] ) WHERE ([Product].[Product Categories].[Category].&[1],[Measures].[Reseller Sales Amount]) 36
8. CHAPTER 2 CUBES, DIMENSIONS, AND MEASURES Data warehouses will always have to maintain a significant amount of data. So storage configuration becomes a high-level concern. Storage Occasionally, you’ll have to deal with configuring storage for an OLAP solution. One issue that arises is the amount of space that calculating every possibility can take. Consider a sales cube: 365 days; 1,500 products; 100 sales people; 50 sales districts. For that one year, the engine would have to calculate 365 × 1,500 × 100 × 50 = 2,737,500,000 values. Each year. And we haven’t figured in the hierarchies (product categories, months and quarters, and so forth). Another issue here is that not every intersection is going to have a value; not every product is bought in every district every day. The result is that OLAP is generally considered a sparse storage problem (for every cell that could be calculated, most will be empty). This has implications both in designing storage for the cube as well as optimizing design and queries for response time. Staging Databases When designing an OLAP solution, you will generally be drawing data from multiple data sources. Although some engines have the capability to read directly from those data sources, you will often have issues unifying the data in those underlying systems. For example, one system may index product data by catalog number, another may do so by unique ID, and a third may use the nomenclature as a key. And of course every system will have different nomenclature for red ten-speed bicycle. If you have to clean data, either to get everyone on the same page or perhaps to deal with human error in manually entered records (where is Missisippi?), you will generally start by aggregating the records in a staging database. This is simply a relational store designed as the location where you unify data from other systems before building a cube on top. The staging database generally will have a design that is more cube-friendly than your average relational system—tables arranged in a more fact/dimension manner instead of the normalized transactional mode of capturing individual records, for example. Note Moving data from one transactional system into another is best accomplished with an extract-transform- load, or ETL, engine. SQL Server Integration Services is a great ETL engine that is part of SQL Server licensing. Storage Modes The next few sections cover storage of relational data; they are referring to caching data from the data source, not this staging database. It’s possible to worry entirely too much about whether to use MOLAP, ROLAP, or HOLAP—don’t. For 99 percent of your analysis solutions, your analysts will be using data from last month, last quarter, or last year. They won’t be deeply concerned about keeping up with the data as it changes, because it’s all committed and “put to bed.” As a result, MOLAP will be just fine in all these cases. ROLAP really becomes an issue only when you need continually updated data (for example, running analysis on assembly line equipment for the current month). Although it’s important when it’s needed, it’s generally not an issue. Let’s take a look at what each of these mean. 38
9. CHAPTER 2 CUBES, DIMENSIONS, AND MEASURES MOLAP Multidimensional OLAP (MOLAP) is probably what you’ve been thinking of to this point—the underlying data is cached to the OLAP server, and the aggregations are precalculated and stored in the OLAP server as well. This approach optimizes response time for queries, but because of the precalculated aggregations, it does require a lot of storage space. ROLAP Relational OLAP (ROLAP) keeps the underlying data in the relational data system. In addition, the aggregations are calculated and stored in the relational data system. The benefit of ROLAP is that because it is linked directly to the underlying source data, there is no latency between changes in the source data and the analytic results. Some OLAP systems may take advantage of server caching to speed up response times, but in general the disadvantage of ROLAP aggregations is that because you’re not leveraging the OLAP engine for precalculation and aggregation of results, analysis is much slower. HOLAP Hybrid OLAP (HOLAP) mixes MOLAP and ROLAP. Aggregations are stored in the OLAP storage, but the source data is kept in the relational data store. Queries that depend on the preaggregated data will be as responsive as MOLAP cubes, while queries that require reading the source data (aggregations that haven’t been precalculated, or drilled down to the source data) will be slower, akin to the response times of ROLAP. We’ll review Analysis Services storage design in Chapter 12. Summary That’s our whirlwind tour of OLAP in general. Now that you have a rough grasp of what cubes are and why we care about them, let’s take a look at the platform we’ll be using to build them—SQL Server Analysis Services. 39
10. CHAPTER 3 SQL Server Analysis Services Now that you have a fundamental understanding of OLAP and multidimensional analysis, let’s start to dig into the reason you bought this book: to find out how these OLAP technologies are implemented in SQL Server, specifically SQL Server Analysis Services (SSAS). SSAS really came into its own in SQL Server 2005, which was a massive overhaul of the entire data platform from SQL Server 2000. SQL Server 2008 Analysis Services is more evolutionary than revolutionary, but still has significant improvements and additions from the 2005 edition. I wrote this chapter from the perspective of SSAS in the 2008 version (formerly code-named Katmai). If you’re familiar with the 2005 version of SQL Server Analysis Services (formerly code-named Yukon), you may just want to skip to the last section, where I call out the specific improvements in SQL Server 2008 Analysis Services. Requirements Before I dive into the “all about SQL Server Analysis Services” stuff, you may want to install it. For a detailed overview and instructions regarding installation of SQL Server 2008 and SSAS, see the SQL Server 2008 Books Online topic “Initial Installation” at http://msdn.microsoft.com/en-us/ library/bb500469.aspx. I’ll cover some of the high points here. Hardware I get a lot of questions about what kind of hardware to use for an Analysis Services installation. The answer is, “It depends.” It depends on these factors: • How many users you plan to support (and how quickly) • What types of users you need to support (lightweight read-only reporting, or heavy analysis?) • How much data you have • How fast you expect the data to grow Generally, the hardware decision boils down to one of three scenarios: New business intelligence initiative: Smallish amount of data, pilot group of users (fewer than ten). Business intelligence initiative to satisfy large demand: For example, the current user base is using Excel spreadsheets or an outdated software package against a fairly large existing body of data. So 41