Click here to load reader
Upload
stefan-urbanek
View
943
Download
2
Embed Size (px)
Citation preview
Cubes modeling patternsr2, December 2012, Cubes v0.10.1
Schema Model or configuration
1
2
3
4
5
amount
store_id
product_id
sales
name
code
id
productstore
id
code
address
fact table has same name as cube, dimension tables have same names as dimensions
"cubes": [ { "name": "sales", "dimensions": ["product", "store"], "joins": [ {"master":"product_id", "detail":"product.id"}, {"master":"store_id", "detail":"store.id"} ] }],"dimensions": [ { "name": "product", "attributes": ["code", "name"] }, { "name": "store", "attributes": ["code", "address"] }]
amount
year
...
sales
store
... ...
product
dimension represented by only one attribute in fact table
"cubes": [ { ... "dimensions": ["product", "store", "year"], ... }],"dimensions": [ ... { "name": "year" }]
amount
store_id
product_id
ft_sales
name
code
id
dim_productdim_store
id
code
address
all dimension tables have prefix “dim_” and all fact tables have prefix “ft_”
Python:
cubes.create_workspace("sql", url=DATABASE_URL, dimension_prefix="dim_", fact_prefix="fact_")
slicer.ini:
[workspacee]dimension_prefix="dim_"fact_prefix="fact_"
schema: sales_datamart
amount
store_id
product_id
sales
name
code
id
productstore
id
code
address
all tables are stored in other than default database schema
Python:
cubes.create_workspace("sql", url=DATABASE_URL, schema="sales_datamart")
slicer.ini:
[workspacee]schema="sales_datamart"
dimensions facts
amount
store_id
product_id
sales
name
code
id
productstore
id
code
address
all fact tables are stored in one schema, all dimension tables in another
Python:
cubes.create_workspace("sql", url=DATABASE_URL, schema="facts", dimension_schema="dimensions",)
slicer.ini:
[workspacee]schema="facts"dimensions_schema="dimensions"
Cubes – modelling patterns
Schema Model or configuration
6
7
8
total_amount
sales_year
...
sales
store
... ...
product
flat dimension is called “year”, but column is “sales_year”; measure is reported as “amount”, column is named “total_amount”
"cubes": [ { "dimensions": [..., "year"], "measures": ["amount"], "mappings": { "year":"sales_year", ⬅ "amount":"total_amount"] ⬅ } }],"dimensions": [ ... { "name": "year" }]
amount
client_id
supplier_id
ft_sales
address
name
id
dim_organisation
address
name
dim_suppliers
id
id
name
address
dim_clients
clients and suppliers share one table with all organisations and companies
"cubes": [ { "name": "sales" "dimensions": ["supplier", "client"], "measures": ["amount"], "joins": [ { "master":"supplier_id", "detail":"dim_organisation.id", "alias":"dim_supplier" ⬅ }, { "master":"client_id", "detail":"dim_organisation.id", "alias":"dim_client" ⬅ } ] }],"dimensions": [ { "name": "supplier", "attributes": ["id", "name", "address"] } { "name": "client", "attributes": ["id", "name", "address"] }]
amount
...
product_id
sales
name
product
id
category_code
code
category
product
category
product dimension has two levels: product category and product
"cubes": [ { "dimensions": ["product", ...], "measures": ["amount"], "joins": [ {"master":"product_id", "detail":"product.id"} ] }],"dimensions": [ { "name": "product", "levels": [ { "name":"category", "attributes": ["category_code", "category"] }, { "name":"product", "attributes": ["code", "name"] } ] }]
Cubes – modelling patterns
Schema Model or configuration
9
10
11
id
name
price
code
product
Total 500
coffee
milk
Product
200
Amount
250
50
tea
report
∑aggregate or filter
key
label
attribute code to be used for aggregation, filtering or links and attribute name used as labels in user interface tables
"dimensions": [ { "name": "product", "levels": [ { "name": "product", "attributes": ["code", "name", "price"] "key": "code", "label_attribute": "name" } ] }]
Use:
result = browser.aggregate(drilldown=["product"])
for row in result.table_rows("product"): print "%s: %s" % (row.label, row.record["amount_sum"])
id
name
price
code
product
... ...
Product
...
AmountUnit Price
amount
...
product_id
sales
user interface labels for dimensions, dimension attributes and measures
"cubes": [ { "name": "sales", "label": "Product Sales", "dimensions": ["product", ...] }],"dimensions": [ { "name": "product", "label": "Product", "attributes": [ {"name": "code", "label": "Code"}, {"name": "name", "label": "Product"}, {"name": "price", "label": "Unit Price"}, ] }]
weekday
id
dim_date
month_name
month
week
day
quarter
year
year
month
day
year
month
month
year
quarter
day
weekday
year
week
dimension, such as date or geography, has multiple ways of organizing attributes into a hierarchy
(in “dimensions”)
{ "name":"date", "levels": [ { "name": "year", "attributes": ["year"] }, { "name": "quarter", "attributes": ["quarter"] }, { "name": "month", "attributes": ["month", "month_name"] }, { "name": "week", "attributes": ["week"] }, { "name": "weekday", "attributes": ["weekday"] }, { "name": "day", "attributes": ["day"] } ], "hierarchies": [ {"name": "ymd", "levels":["year", "month", "day"]}, {"name": "ym", "levels":["year", "month"]}, {"name": "yqmd", "levels":["year", "quarter", "month", "day"]}, {"name": "ywd", "levels":["year", "week", "weekday"]} ], "default_hierarchy_name": "ymd"}
Cubes – modelling patterns
Schema Model or configuration
12
name_es
id
name_en
name_fr
code
product
dimension attributes have language-specific content (requirement: one column per language, use locale suffix)
"dimensions": [ { "name": "product", "label": "Product", "attributes": [ {"name": "code", "label": "Code"}, { "name": "name", "label": "Product", “locales”: ["en", "fr", "es"] } ] }]
Use:
! browser = workspace.browser(cube, locale=”fr”)
Then browse as usual. Localization is transparent.
Notes:1.only one locale per browser2.refer to dimension attributes as there was no localisation: “product.name”3.if non-existing locale is requested, then default (first in the list) locale is used
Cubes – modelling patterns
Schema Model or configuration
unit_price
id
name_en
name_sk
code
product
... ...
Product
...
AmountUnit Price
... ...
Produkt
...
SumaJednotková cena
amount
...
product_id
sales
dimension attributes have language-specific content; labels in report (including measures) should be displayed according to locale
{ "locale": "en", "cubes": [ { "name": "sales", "label": "Product Sales", "dimensions": ["product"], "measures": [ {"name": "amount", "label": "Amount"} ] } ], "dimensions": [ { "name": "product", "label": "Product", "attributes": [ { "name": "code", "label": "Code" }, { "name": "name", "label": "Product", "locales": ["en", "sk"] }, { "name": "price", "label": "Unit Price" } ] } ]}
Translation dictionary for non-default locale:{ "locale": "sk", "dimensions": { "product”: { "levels": { "product" : { "label" : "Produkt", "attributes" : { "code":{"label": "Kód produktu"}, "name":{"label": "Produkt"}, "price":{"label": "Jednotková cena"} } } } } } “cubes”: { "sales": { "measures": { "amount" : {"label": "Suma"} } } }}
Use:! model_sk = model.localize(translation)
Warning: interface for model localization is not final, might be changed in the future.
Cubes – modelling patterns
Cubes - lightweight Python OLAP
Source https://github.com/Stiivi/cubesDocumentation http://packages.python.org/cubes/
Cubes – modelling patterns