You are on page 1of 6

Cubes – modelling patterns

Cubes modeling patterns

r2, December 2012, Cubes v0.10.1

 

Schema

 

Model or conguration

 
sales product_id store_id amount
sales
product_id
store_id
amount
store id
store
id
sales product_id store_id amount store id code address product id code name fact table has same
sales product_id store_id amount store id code address product id code name fact table has same
code address
code
address
sales product_id store_id amount store id code address product id code name fact table has same
product
product
id
id
code name
code
name

fact table has same name as cube,

 

"cubes": [

1

],

{

}

"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"] }

dimension tables have same names as dimensions

]

 
sales store product year amount
sales
store
product
year
amount
sales store product year amount
sales store product year amount
sales store product year amount
sales store product year amount
 

"cubes": [

2

{

"dimensions": ["product", "store", "year"],

}

],

"dimensions": [

dimension represented by only one attribute in fact table

]

{

"name": "year" }

3

dim_store ft_sales dim_product id product_id id code store_id code address amount name
dim_store
ft_sales
dim_product
id
product_id
id
code
store_id
code
address
amount
name
dim_store ft_sales dim_product id product_id id code store_id code address amount name
dim_store ft_sales dim_product id product_id id code store_id code address amount name
dim_store ft_sales dim_product id product_id id code store_id code address amount name
dim_store ft_sales dim_product id product_id id code store_id code address amount name
dim_store ft_sales dim_product id product_id id code store_id code address amount name
dim_store ft_sales dim_product id product_id id code store_id code address amount name
dim_store ft_sales dim_product id product_id id code store_id code address amount name
dim_store ft_sales dim_product id product_id id code store_id code address amount name

Python:

cubes.create_workspace("sql",

slicer.ini:

[workspacee]

url=DATABASE_URL,

dimension_prefix="dim_",

fact_prefix="fact_")

all dimension tables have prex “dim_” and all fact tables have prex “ft_”

dimension_prefix="dim_"

fact_prefix="fact_"

4

schema: sales_datamart store sales product id product_id id code store_id code address amount name
schema: sales_datamart
store
sales
product
id
product_id
id
code
store_id
code
address
amount
name

Python:

 

cubes.create_workspace("sql",

   

url=DATABASE_URL,

schema="sales_datamart")

slicer.ini:

[workspacee]

all tables are stored in other than default database schema

schema="sales_datamart"

 
dimensions facts store sales product id product_id id code store_id code address amount name
dimensions
facts
store
sales
product
id
product_id
id
code
store_id
code
address
amount
name

Python:

 

5

cubes.create_workspace("sql",

 

url=DATABASE_URL,

schema="facts",

dimension_schema="dimensions",

)

 

slicer.ini:

[workspacee]

schema="facts"

all fact tables are stored in one schema, all dimension tables in another

dimensions_schema="dimensions"

Cubes – modelling patterns

6 7 8 Schema sales store product sales_year total_amount fl at dimension is called “year”,

6

7

8

Schema

sales store product sales_year total_amount
sales
store
product
sales_year
total_amount

at dimension is called “year”, but column is “sales_year”; measure is reported as “amount”, column is named “total_amount”

dim_suppliers id ft_sales name supplier_id address client_id amount dim_clients id
dim_suppliers
id
ft_sales
name
supplier_id
address
client_id
amount
dim_clients
id

name

address

dim_organisation id name address
dim_organisation
id
name
address

clients and suppliers share one table with all organisations and companies

sales product product_id id code amount name category_code category
sales
product
product_id
id
code
amount
name
category_code
category
product_id id code amount name category_code category product category product dimension has two levels: product
product_id id code amount name category_code category product category product dimension has two levels: product

product

category

product dimension has two levels:

product category and product

Model or conguration

"cubes": [ { , "measures": ["amount"], "mappings": {
"cubes": [
{
,
"measures": ["amount"],
"mappings": {
"year":"sales_year", ⇦
"dimensions": [
"year"],
"amount":"total_amount"] ⇦
}
}
],
"dimensions": [
{ "name": "year" }
]

"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"] }

]

"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

9 10 11 Schema key label aggregate or filter product id code report name price

9

10

11

Schema

key label aggregate or filter product id code report name price Product ∑ Amount co

key

label

aggregate or filter product id code report name price Product
aggregate or filter
product
id
code
report
name
price
Product

Amount

coee

tea

milk

200

250

50

Total

500

attribute code to be used for aggregation, ltering or links and attribute name used as labels in user interface tables

product sales id product_id code name amount price
product
sales
id
product_id
code
name
amount
price
product sales id product_id code name amount price Product Unit Price Amount user interface labels for
product sales id product_id code name amount price Product Unit Price Amount user interface labels for

Product

Unit Price

Amount

user interface labels for dimensions, dimension attributes and measures

dim_date year year id quarter month year month day quarter day month month_name year week
dim_date
year
year
id
quarter
month
year
month
day
quarter
day
month
month_name
year
week
year
week
day
month
weekday
weekday

dimension, such as date or geography , has multiple ways of organizing attributes into a hierarchy

Model or conguration

"dimensions": [ { "name": "product", "levels": [ { "name": "product",
"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"])

"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"},

]

 

}

]

(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 "dimensions": [ 12 { product "name": "product",
Schema
Model or configuration
"dimensions": [
12
{
product
"name": "product",
"label": "Product",
id
"attributes": [
{"name": "code", "label": "Code"},
code
{
name_en
"name": "name",
"label": "Product",
“locales”: ["en", "fr", "es"]
name_fr
}
]
name_es
}
]
Use:
dimension attributes have language-
speci fic content (requirement: one
column per language, use locale suffi x)
!
browser = workspace.browser(cube, locale=”fr”)
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 ( first in the list)
locale is used

Cubes – modelling patterns

Schema sales product_id amount product id code name_en name_sk unit_price Product Unit Price Amount
Schema sales product_id amount product id code name_en name_sk unit_price Product Unit Price Amount

Schema

sales product_id amount product id code name_en name_sk unit_price
sales
product_id
amount
product
id
code
name_en
name_sk
unit_price
amount product id code name_en name_sk unit_price Product Unit Price Amount Produkt Jednotková cena

Product

Unit Price

Amount

name_en name_sk unit_price Product Unit Price Amount Produkt Jednotková cena Suma dimension attributes

Produkt

Jednotková cena

Suma

dimension attributes have language- speci c content; labels in report (including measures) should be displayed according to locale

(including measures) should be displayed according to locale Model or con fi guration {   "

Model or conguration

{

 

"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"
{
"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 nal, might be changed in the future.

= model.localize(translation) Warning: interface for model localization is not fi nal, might be changed in the

Cubes - lightweight Python OLAP

Source

Documentation

Cubes – modelling patterns