forked from wwasilak/northwind_test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path25Days.malloy
107 lines (89 loc) · 3.74 KB
/
25Days.malloy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
source: CategoriesBase is duckdb.table('../northwind_test/parquet/categories.parquet') extend {
primary_key: categoryID
}
source: SuppliersBase is duckdb.table('../northwind_test/parquet/suppliers.parquet') extend {
primary_key: supplierID
}
source: ProductsBase is duckdb.table('../northwind_test/parquet/products.parquet') extend {
primary_key: supplierID
measure:
product_count is count()
total_price is unitPrice.sum()
# format="#.##"
avg_price is unitPrice.avg()
}
source: OrderDetailsBase is duckdb.table('../northwind_test/parquet/order_details.parquet') extend {
dimension:
revenue is unitPrice * quantity
measure:
total_quantity is quantity.sum()
total_discount is discount.sum()
total_revenue is revenue.sum()
item_count is count()
}
-- ok so i have one 'branch' of the model. Now i need to do the same with second Orders branch. Starting with edge tables:
source: RegionsBase is duckdb.table('../northwind_test/parquet/regions.parquet') extend {
primary_key: regionID
}
--now i will join Regions to Territories
source: TerritoriesBase is duckdb.table('../northwind_test/parquet/territories.parquet') extend {
primary_key: territoryID
}
source: EmployeeTerritoriesBase is duckdb.table('../northwind_test/parquet/employee_territories.parquet') {}
source: EmployeeTerritories is duckdb.table('../northwind_test/parquet/employee_territories.parquet') extend {
join_one: Territories is TerritoriesBase with territoryID
}
source: EmployeesBase is duckdb.table('../northwind_test/parquet/employees.parquet') extend {
primary_key: employeeID
}
source: CustomersBase is duckdb.table('../northwind_test/parquet/customers.parquet') extend {
primary_key: customerID
}
source: ShippersBase is duckdb.table('../northwind_test/parquet/shippers.parquet') extend {
primary_key: shipperID
}
source: OrdersBase is duckdb.table('../northwind_test/parquet/orders.parquet') extend {
primary_key: orderID
dimension:
order_date is orderDate::date
order_year is year(orderDate)
order_is_open is shippedDate = null
measure:
order_count is count()
}
-- now i will join Customers, Shippers and two 'branches': Employees and OrderDetails, to Orders:
source: Orders is OrdersBase extend {
join_one: Customers is CustomersBase with customerID
join_one: Shippers is ShippersBase on Shippers.shipperID = shipVia
join_one: Employees is EmployeesBase extend {
join_many: EmployeeTerritories is EmployeeTerritoriesBase extend {
join_one: Territories is TerritoriesBase extend {
join_one: Regions is RegionsBase with regionID
} with territoryID
} on EmployeeTerritories.employeeID = employeeID
}
join_many: OrderDetails is OrderDetailsBase extend {
join_one: Products is ProductsBase extend {
join_one: Categories is CategoriesBase with categoryID
join_one: Suppliers is SuppliersBase with supplierID
} with productID
} on orderID = OrderDetails.orderID
}
source: Customers is CustomersBase extend {
join_many: Orders is OrdersBase extend {
join_one: Shippers is ShippersBase on Shippers.shipperID = shipVia
join_one: Employees is EmployeesBase extend {
join_many: EmployeeTerritories is EmployeeTerritoriesBase extend {
join_one: Territories is TerritoriesBase extend {
join_one: Regions is RegionsBase with regionID
} with territoryID
} on EmployeeTerritories.employeeID = employeeID
}
join_many: OrderDetails is OrderDetailsBase extend {
join_one: Products is ProductsBase extend {
join_one: Categories is CategoriesBase with categoryID
join_one: Suppliers is SuppliersBase with supplierID
} with productID
} on orderID = OrderDetails.orderID
} on Orders.customerID=customerID
}