Modelado Dimensional 4 Etapas


Published on

  • Be the first to comment

Modelado Dimensional 4 Etapas

  1. 1. Retail Sales Kimball & Ross, Chapter 2
  2. 2. Overview <ul><li>Four-step dimensional design process </li></ul><ul><li>Transaction-level fact tables </li></ul><ul><li>Additive and non-additive facts </li></ul><ul><li>Sample dimension table attributes </li></ul><ul><li>Causal dimensions </li></ul><ul><li>Degenerate dimensions </li></ul><ul><li>Extending an existing dimension model </li></ul><ul><li>Snowflaking dimension attributes </li></ul><ul><li>Avoiding the “too many dimensions” trap </li></ul><ul><li>Surrogate keys </li></ul>
  3. 3. Four-Step Dimensional Design Process <ul><li>Select the business process to model. </li></ul><ul><ul><li>not business department or function </li></ul></ul><ul><ul><li>E.g., purchasing, ordering, shipping, invoicing, inventorying </li></ul></ul><ul><li>Declare the grain of the business process. </li></ul><ul><ul><li>Specifies individual fact table row </li></ul></ul><ul><ul><li>E.g., individual line item on sales ticket, daily snapshot of the inventory levels for a product </li></ul></ul>
  4. 4. Four-Step Dimensional Design Process <ul><li>Choose the dimensions that apply for each fact table row. </li></ul><ul><ul><li>Q: How do business people describe the data that results from the business process? </li></ul></ul><ul><ul><li>E.g., date, product, store, customer, transaction type </li></ul></ul><ul><li>Identify the numeric (measured) facts that will populate each fact table row. </li></ul><ul><ul><li>Q: What are we measuring? </li></ul></ul><ul><ul><li>Typical facts are numeric additive figures </li></ul></ul><ul><ul><li>E.g., quantity ordered, dollar cost amount </li></ul></ul><ul><li>In making decisions regarding the 4 steps, consider both the user requirements as well as the realities of the source data </li></ul>
  5. 5. Retail Case Study <ul><li>Large grocery chain: 100 grocery stores over 5 regions </li></ul><ul><li>Each store: </li></ul><ul><ul><li>Departments: grocery, frozen foods, dairy, meat, produce, bakery, floral, health/beauty aids, etc. </li></ul></ul><ul><ul><li>60,000 products (SKUs = stock keeping units) on shelves </li></ul></ul><ul><ul><li>55,000 SKUs with UPCs </li></ul></ul><ul><ul><li>5,000 SKUs without UPCs but with assigned SKU numbers </li></ul></ul><ul><li>Data is collected: </li></ul><ul><ul><li>from cash registers into a point-of-sale (POS) system </li></ul></ul><ul><ul><li>at back door where vendors make deliveries </li></ul></ul>
  6. 6. Retail Case Study – Cont’d <ul><li>Management concerns </li></ul><ul><ul><li>Logistics of ordering, stocking, and selling products </li></ul></ul><ul><ul><li>Maximizing profit </li></ul></ul><ul><ul><li>Product pricing </li></ul></ul><ul><ul><li>Lowering cost of acquisition and overhead </li></ul></ul><ul><ul><li>Use of promotions to increase sales </li></ul></ul><ul><ul><ul><li>temporary price reductions </li></ul></ul></ul><ul><ul><ul><li>newspaper ads </li></ul></ul></ul><ul><ul><ul><li>grocery store displays </li></ul></ul></ul><ul><ul><ul><li>coupons </li></ul></ul></ul>
  7. 7. Step 1. Select the Business Process <ul><li>Decide what business process to model, by combining an understanding of the business requirements with an understanding of data realities. </li></ul><ul><li>The first dimensional model built should be the one </li></ul><ul><ul><li>with the most impact, </li></ul></ul><ul><ul><li>that answers the most pressing business questions, </li></ul></ul><ul><ul><li>is readily accessible for data extraction. </li></ul></ul><ul><li>In retail case study: POS retail sales </li></ul><ul><li>Business Question: What products are selling in which stores on what days and under what promotional conditions? </li></ul>
  8. 8. Step 2. Declare the Grain <ul><li>What level of data detail should be made available in the dimensional model? </li></ul><ul><li>Choose the most atomic information captured by the business process. </li></ul><ul><ul><li>Atomic data </li></ul></ul><ul><ul><ul><li>Most detailed, cannot be subdivided </li></ul></ul></ul><ul><ul><ul><li>Facilitates ad hoc, unexpected usage and ability to drill down to details </li></ul></ul></ul><ul><li>Case study grain: individual line item on a POS transaction </li></ul>
  9. 9. Step 3. Choose the Dimensions <ul><li>A careful grain statement determines the primary dimensions. </li></ul><ul><li>It is then usually possible to add additional dimensions. </li></ul><ul><li>If an additional desired dimension violates the grain by causing additional fact rows to be generated, then the grain statement must be revised to accommodate this dimension. </li></ul><ul><li>Case study dimensions: date, product, store, promotion </li></ul>
  10. 10. Preliminary Retail Sales Schema <ul><li>POS Sales Transaction Fact </li></ul><ul><ul><li>Date Key (FK) </li></ul></ul><ul><ul><li>Product Key (FK) </li></ul></ul><ul><ul><li>Store Key (FK) </li></ul></ul><ul><ul><li>Promotion Key (FK) </li></ul></ul><ul><ul><li>POS Transaction Number </li></ul></ul><ul><ul><li>Other facts TBD </li></ul></ul><ul><li>Product Dimension </li></ul><ul><ul><li>Product Key (PK) </li></ul></ul><ul><ul><li>Product attributes TBD </li></ul></ul><ul><li>Promotion Dimension </li></ul><ul><ul><li>Promotion Key (PK) </li></ul></ul><ul><ul><li>Promotion attributes TBD </li></ul></ul><ul><li>Date Dimension </li></ul><ul><ul><li>Date Key (PK) </li></ul></ul><ul><ul><li>Date attributes TBD </li></ul></ul><ul><li>Store Dimension </li></ul><ul><ul><li>Store Key (PK) </li></ul></ul><ul><ul><li>Store attributes TBD </li></ul></ul>
  11. 11. Step 4. Identify the Facts <ul><li>Picking the business measurements for the fact table: true to the grain. </li></ul><ul><li>Case study - Facts collected by POS system: </li></ul><ul><ul><li>Sales quantity, sales price/unit, sales $ amount, standard cost $ amount </li></ul></ul><ul><ul><li>Gross Profit = cost – sales </li></ul></ul><ul><ul><ul><li>Recommendation: Include in fact table even though it can be calculated. Eliminates the possibility of user error. </li></ul></ul></ul><ul><li>For non-additive measurements such as percentages and ratios (e.g., gross margin) store the numerator (gross profit) and denominator ($ revenue) in the fact table. The ratio can be calculated in a data access tool for any slice of the fact table. Caution : Calculate the ratio of the sums, not the sum of the ratios </li></ul>
  12. 12. Date Dimension <ul><li>Ubiquitous in every data mart </li></ul><ul><li>See Figure 2.4, p. 39 </li></ul><ul><li>Use verbose, self-explanatory values rather than coded values. They are used as column headers in reports. By decoding in the database, we ensure consistency across different application environments. </li></ul><ul><ul><li>E.g., Holiday Indicator – use values: Holiday, Nonholiday; as opposed to Y/N </li></ul></ul><ul><li>Date Key should be an integer rather than a date data type </li></ul><ul><li>Data warehouses need an explicit date dimension table to describe fiscal periods, seasons, holidays, weekends, and other calendar calculations that are not supported by the SQL date function. </li></ul><ul><li>If transaction time is of interest, we may need a separate Time Dimension table </li></ul>
  13. 13. Product Dimension <ul><li>Describes every SKU in the store </li></ul><ul><li>Fill this dimension with as many descriptive attributes as possible. </li></ul><ul><li>“ Robust dimension attributes deliver robust analytic slicing and dicing capabilities.” </li></ul><ul><li>Hierarchies = groups of attributes </li></ul><ul><li>Merchandise hierarchy </li></ul><ul><ul><li>SKUs roll up to brands to categories to departments. </li></ul></ul><ul><ul><li>Each is a many-to-one relationship </li></ul></ul><ul><li>Although there will be redundancy, no need to normalize. Given the relative size of the dimension (as compared to the fact table) space saving is minimal. </li></ul>
  14. 14. Store Dimension <ul><li>The store dimension: Store Key (PK), Store Name, Store Number (Natural Key), Store Address, … </li></ul><ul><li>Possible to represent multiple hierarchies in a dimension table </li></ul><ul><ul><li>Store to any geographic attribute (e.g., ZIP, county, state) </li></ul></ul><ul><ul><li>Store to store district to region </li></ul></ul>
  15. 15. Promotion Dimension <ul><li>Describes the promotion conditions under which a product is sold </li></ul><ul><li>Called a “causal dimension” – describes factors thought to cause a change in product sales (price reductions, ads, displays, coupons) </li></ul><ul><li>Could keep all 4 causal mechanisms in a single dimension </li></ul><ul><ul><li>They are highly correlated, so not much difference in space requirements </li></ul></ul><ul><ul><li>More efficient browsing for finding out how various promotions are used together </li></ul></ul><ul><li>… or split into 4 separate dimensions </li></ul><ul><ul><li>May be more understandable to business </li></ul></ul><ul><ul><li>Administration may be more straightforward </li></ul></ul><ul><li>To avoid null keys in the fact table (violation of referential integrity), for line items not being promoted include a row in the promotion dimension to indicate “No Promotion in Effect” </li></ul>
  16. 16. Factless Fact Table <ul><li>Q: Which products were under promotion but did not sell? </li></ul><ul><li>Cannot answer yet. POS sales fact table has only products that were sold </li></ul><ul><li>Answer: Create Promotion Coverage Factless Fact Table </li></ul><ul><ul><li>Factless Fact Table = has no measurement metrics </li></ul></ul><ul><ul><li>Contains date, product, store, and promotion keys </li></ul></ul><ul><li>Two-step process to answer Q: </li></ul><ul><ul><li>Query Promotion Coverage table: products under promotion on given date </li></ul></ul><ul><ul><li>From POS Sales Fact table: products sold </li></ul></ul><ul><ul><li>Answer is the set difference of above </li></ul></ul>
  17. 17. Degenerate Dimension (DD) <ul><li>Dimension keys used in fact table without corresponding dimension tables </li></ul><ul><li>In case study: POS Transaction # </li></ul><ul><li>Still useful for grouping by transaction </li></ul><ul><li>Common DDs: order numbers, invoice numbers </li></ul><ul><li>Fact table primary key: Product Key and POS Transaction Number </li></ul>
  18. 18. Retail Schema Extensibility <ul><li>Original schema extends gracefully because POS transaction data was modeled at its most granular level. </li></ul><ul><li>Premature aggregation limits ability to extend if new dimensions do not apply to higher grain </li></ul><ul><li>Case study new dimensions: </li></ul><ul><ul><li>Frequent Shopper </li></ul></ul><ul><ul><li>Clerk </li></ul></ul><ul><ul><li>Time of Day </li></ul></ul>
  19. 19. Schema Extensibility <ul><li>Dimensional models can handle extensions without invalidating existing applications: </li></ul><ul><ul><li>New dimension attributes – simply add columns to dimension table. If new attribute is only available after point in time, populate old dimension records with something like “Not Available” </li></ul></ul><ul><ul><li>New dimensions – add foreign field keys to fact table </li></ul></ul><ul><ul><li>New measured facts – add to fact table. If not at the same grain, then need separate fact table </li></ul></ul><ul><ul><li>Dimension becoming more granular – create new dimension. May imply more granular fact table, in which case, may have to rebuild the fact table. </li></ul></ul><ul><ul><li>Addition of a completely new data source involving existing and new dimensions – usually needs new fact table </li></ul></ul>
  20. 20. Resisting Dimension Normalization <ul><li>Snowflaking = Dimension table normalization </li></ul><ul><ul><li>Redundant attributes are removed from the denormalized dimension table and are placed in normalized secondary dimension tables </li></ul></ul><ul><ul><li>Fully snowflaked schema = 3NF ER diagram </li></ul></ul><ul><li>The dimension tables must not be normalized, and should remain as flat tables. </li></ul><ul><li>Numerous tables and joins usually translate into slower query performance. </li></ul><ul><li>Efforts to normalize any of the tables in a dimensional database solely in order to save disk space are a waste of time. Disk space savings gained by normalizing the dimension tables are typically less than one percent of the total disk space needed for the overall schema. </li></ul><ul><li>Normalized dimension tables destroy the ability to browse within a dimension or across dimensions (e.g., list package types for each brand in a category). SQL needed becomes too complex. </li></ul><ul><li>The fact table is naturally normalized. </li></ul>
  21. 21. Too Many Dimensions <ul><li>Too many dimensions increase space requirements for the fact table. </li></ul><ul><li>A very large number of dimensions typically means that several dimensions are not completely independent and should be combined. </li></ul><ul><li>A single hierarchy should not be captured in separate dimensions. </li></ul>
  22. 22. Surrogate Keys <ul><li>Surrogate keys are integers assigned sequentially as needed to populate a dimension. They serve to join dimension tables to the fact table. </li></ul><ul><li>Avoid embedding intelligence in the data warehouse keys. </li></ul><ul><li>Benefits: </li></ul><ul><ul><li>Surrogate keys buffer the DW environment from operational changes. What happens when operations decide to recycle account numbers after some period of inactivity? Fine for operational systems, but problematic for DW if it is using account numbers as a PK. </li></ul></ul><ul><ul><li>Can more easily integrate data from multiple operational systems, even if they lack consistent source keys. </li></ul></ul><ul><ul><li>Performance advantages because small size of surrogate keys leads to smaller fact tables </li></ul></ul><ul><ul><li>Surrogate keys are used to support one of the primary techniques for handling changes in dimension table attributes (Chapter 4). </li></ul></ul>
  23. 23. Acknowledgements <ul><li>Ralph Kimball & Margy Ross </li></ul>