You are on page 1of 6

Cubes modelling patterns

Cubes modeling patterns


r2, December 2012, Cubes v0.10.1

Schema Model or conguration

1
"cubes": [
{
store sales product "name": "sales",
id product_id id "dimensions": ["product", "store"],
"joins": [
code store_id code
{"master":"product_id", "detail":"product.id"},
address amount name {"master":"store_id", "detail":"store.id"}
]
}
fact table has same name as cube, ],
"dimensions": [
dimension tables have same names as { "name": "product", "attributes": ["code", "name"] },
{ "name": "store", "attributes": ["code", "address"] }
dimensions ]

"cubes": [
2 sales
{
...
store ... product "dimensions": ["product", "store", "year"],
...
... year ...
}
amount ],
"dimensions": [
...
dimension represented by only one { "name": "year" }
]
attribute in fact table

Python:
3 dim_store ft_sales dim_product cubes.create_workspace("sql",
id product_id id url=DATABASE_URL,
dimension_prefix="dim_",
code store_id code
fact_prefix="fact_")
address amount name
slicer.ini:

all dimension tables have prex dim_ [workspacee]


dimension_prefix="dim_"
and all fact tables have prex ft_ fact_prefix="fact_"

Python:
4 schema: sales_datamart
cubes.create_workspace("sql",
store sales product
url=DATABASE_URL,
id product_id id schema="sales_datamart")
code store_id code
slicer.ini:
address amount name
[workspacee]
all tables are stored in other than default schema="sales_datamart"

database schema

Python:
5 dimensions facts
store sales product cubes.create_workspace("sql",
url=DATABASE_URL,
id product_id id schema="facts",
code store_id code dimension_schema="dimensions",
address amount name )

slicer.ini:

[workspacee]
schema="facts"
all fact tables are stored in one schema, dimensions_schema="dimensions"

all dimension tables in another


Cubes modelling patterns

Schema Model or conguration

6
"cubes": [
{
sales "dimensions": [..., "year"],
store ... product "measures": ["amount"],
"mappings": {
... sales_year ...
"year":"sales_year",
total_amount
"amount":"total_amount"]
}
at dimension is called year, but }
],
column is sales_year; measure is "dimensions": [
...
reported as amount, column is named { "name": "year" }
]
total_amount

"cubes": [
7
dim_suppliers
id dim_organisation {
ft_sales
name id "name": "sales"
supplier_id
address name "dimensions": ["supplier", "client"],
client_id
address "measures": ["amount"],
amount
dim_clients "joins": [
id {
name "master":"supplier_id",
address "detail":"dim_organisation.id",
"alias":"dim_supplier"
clients and suppliers share one table
},
with all organisations and companies {
"master":"client_id",
"detail":"dim_organisation.id",
"alias":"dim_client"
}
]
}
],
"dimensions": [
{
"name": "supplier",
"attributes": ["id", "name", "address"] }
{
"name": "client",
"attributes": ["id", "name", "address"] }
]

"cubes": [
8 {
sales product "dimensions": ["product", ...],
"measures": ["amount"],
product_id id "joins": [
{"master":"product_id", "detail":"product.id"}
... code ]
product
amount name }
],
category_code category "dimensions": [
category {
"name": "product",
"levels": [
{
product dimension has two levels: "name":"category",
"attributes": ["category_code", "category"]
product category and product },
{
"name":"product",
"attributes": ["code", "name"]
}
]
}
]
Cubes modelling patterns

Schema Model or conguration

9
"dimensions": [
aggregate or lter {
product
"name": "product",
id "levels": [
{
key code
report "name": "product",
label name "attributes": ["code", "name", "price"]
"key": "code",
price Product Amount "label_attribute": "name"
}
coee 200 ]
tea 250 }
]
milk 50
Use:
Total 500
attribute code to be used for result = browser.aggregate(drilldown=["product"])

aggregation, ltering or links and for row in result.table_rows("product"):


print "%s: %s" % (row.label, row.record["amount_sum"])
attribute name used as labels in user
interface tables

"cubes": [
10 product {
sales "name": "sales",
id "label": "Product Sales",
product_id
code "dimensions": ["product", ...]
... }
name
amount ],
price "dimensions": [
{
"name": "product",
"label": "Product",
"attributes": [
Product Unit Price Amount {"name": "code", "label": "Code"},
... ... ...
{"name": "name", "label": "Product"},
{"name": "price", "label": "Unit Price"},
user interface labels for dimensions, }
]

dimension attributes and measures ]

(in dimensions)
11 dim_date year year
id quarter month {
year month day "name":"date",
"levels": [
quarter day
{ "name": "year", "attributes": ["year"] },
month { "name": "quarter", "attributes": ["quarter"] },
month_name { "name": "month", "attributes": ["month", "month_name"] },
year { "name": "week", "attributes": ["week"] },
week
year week { "name": "weekday", "attributes": ["weekday"] },
day
month weekday { "name": "day", "attributes": ["day"] }
weekday ],
"hierarchies": [
{"name": "ymd", "levels":["year", "month", "day"]},
dimension, such as date or geography, {"name": "ym", "levels":["year", "month"]},
{"name": "yqmd", "levels":["year", "quarter", "month", "day"]},
has multiple ways of organizing {"name": "ywd", "levels":["year", "week", "weekday"]}
attributes into a hierarchy ],
"default_hierarchy_name": "ymd"
}
Cubes modelling patterns

Schema Model or conguration

12
"dimensions": [
{
product "name": "product",
"label": "Product",
id "attributes": [
{"name": "code", "label": "Code"},
code {
"name": "name",
name_en "label": "Product",
locales: ["en", "fr", "es"]
name_fr }
]
name_es }
]

dimension attributes have language- Use:


specic content (requirement: one ! browser = workspace.browser(cube, locale=fr)

column per language, use locale sux)


Then browse as usual. Localization is transparent.

Notes:
1.only one locale per browser
2.refer to dimension attributes as there was no localisation:
product.name
3.if non-existing locale is requested, then default (rst in the list)
locale is used
Cubes modelling patterns

Schema Model or conguration


{
sales
"locale": "en",
"cubes": [
product_id
{
...
"name": "sales",
amount "label": "Product Sales",
"dimensions": ["product"],
"measures": [
product
Product Unit Price Amount
{"name": "amount", "label": "Amount"}
id
]
code ... ... ...
}
name_en ],
name_sk Produkt Jednotkov cena Suma "dimensions": [
unit_price ... ... ... {
"name": "product",
"label": "Product",
dimension attributes have language- "attributes": [
{
specic content; labels in report "name": "code",
(including measures) should be },
"label": "Code"

displayed according to locale {


"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": "Kd 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 nal, might be


changed in the future.
Cubes modelling patterns

Cubes - lightweight Python OLAP

Source https://github.com/Stiivi/cubes
Documentation http://packages.python.org/cubes/

You might also like