activewarehouse 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +62 -17
- data/Rakefile +17 -0
- data/generators/bridge/USAGE +1 -0
- data/generators/bridge/bridge_generator.rb +46 -0
- data/generators/bridge/templates/fixture.yml +5 -0
- data/generators/bridge/templates/migration.rb +20 -0
- data/generators/bridge/templates/model.rb +3 -0
- data/generators/dimension/templates/unit_test.rb +0 -2
- data/generators/dimension_view/USAGE +1 -0
- data/generators/dimension_view/dimension_view_generator.rb +62 -0
- data/generators/dimension_view/templates/migration.rb +11 -0
- data/generators/dimension_view/templates/model.rb +3 -0
- data/generators/dimension_view/templates/unit_test.rb +10 -0
- data/init.rb +1 -0
- data/lib/active_warehouse.rb +24 -9
- data/lib/active_warehouse/{model/aggregate.rb → aggregate.rb} +29 -13
- data/lib/active_warehouse/builder/date_dimension_builder.rb +21 -6
- data/lib/active_warehouse/builder/random_data_builder.rb +204 -3
- data/lib/active_warehouse/compat/compat.rb +49 -0
- data/lib/active_warehouse/{model/cube.rb → cube.rb} +47 -17
- data/lib/active_warehouse/dimension.rb +296 -0
- data/lib/active_warehouse/dimension/bridge.rb +15 -0
- data/lib/active_warehouse/dimension/dimension_view.rb +11 -0
- data/lib/active_warehouse/dimension/hierarchical_dimension.rb +60 -0
- data/lib/active_warehouse/dimension/slowly_changing_dimension.rb +137 -0
- data/lib/active_warehouse/{model/fact.rb → fact.rb} +45 -10
- data/lib/active_warehouse/migrations.rb +1 -2
- data/lib/active_warehouse/report.rb +3 -0
- data/lib/active_warehouse/{model/report → report}/abstract_report.rb +0 -0
- data/lib/active_warehouse/{model/report → report}/chart_report.rb +0 -0
- data/lib/active_warehouse/{model/report → report}/table_report.rb +0 -0
- data/lib/active_warehouse/version.rb +2 -2
- data/lib/active_warehouse/view/report_helper.rb +2 -1
- data/tasks/active_warehouse_tasks.rake +54 -0
- metadata +43 -21
- data/doc/agg_queries.txt +0 -26
- data/doc/agg_queries_results.txt +0 -150
- data/doc/queries.txt +0 -35
- data/lib/active_warehouse/model.rb +0 -5
- data/lib/active_warehouse/model/dimension.rb +0 -3
- data/lib/active_warehouse/model/dimension/bridge.rb +0 -32
- data/lib/active_warehouse/model/dimension/dimension.rb +0 -152
- data/lib/active_warehouse/model/dimension/hierarchical_dimension.rb +0 -35
- data/lib/active_warehouse/model/report.rb +0 -3
data/doc/agg_queries.txt
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
Aggregate 1:
|
2
|
-
|
3
|
-
select d1.calendar_year, d2.store_state,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d2.store_state;
|
4
|
-
select d1.calendar_year, d2.store_state, d2.store_county,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d2.store_state, d2.store_county;
|
5
|
-
select d1.calendar_year, d2.store_state, d2.store_county, d2.store_city,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d2.store_state, d2.store_county, d2.store_city;
|
6
|
-
select d1.calendar_year, d1.calendar_month_name, d2.store_state,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d2.store_state;
|
7
|
-
select d1.calendar_year, d1.calendar_month_name, d2.store_state, d2.store_county,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d2.store_state, d2.store_county;
|
8
|
-
select d1.calendar_year, d1.calendar_month_name, d2.store_state, d2.store_county, d2.store_city,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d2.store_state, d2.store_county, d2.store_city;
|
9
|
-
select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_state,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_state;
|
10
|
-
select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_state, d2.store_county,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_state, d2.store_county;
|
11
|
-
select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_state, d2.store_county, d2.store_city,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_state, d2.store_county, d2.store_city;
|
12
|
-
select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_state,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_state;
|
13
|
-
select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_state, d2.store_county,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_state, d2.store_county;
|
14
|
-
select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_state, d2.store_county, d2.store_city,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_state, d2.store_county, d2.store_city;
|
15
|
-
|
16
|
-
|
17
|
-
Aggregate 2:
|
18
|
-
|
19
|
-
select d1.calendar_year, d2.store_region,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d2.store_region;
|
20
|
-
select d1.calendar_year, d2.store_region, d2.store_district,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d2.store_region, d2.store_district;
|
21
|
-
select d1.calendar_year, d1.calendar_month_name, d2.store_region,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d2.store_region;
|
22
|
-
select d1.calendar_year, d1.calendar_month_name, d2.store_region, d2.store_district,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d2.store_region, d2.store_district;
|
23
|
-
select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_region,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_region;
|
24
|
-
select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_region, d2.store_district,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_region, d2.store_district;
|
25
|
-
select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_region,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_region;
|
26
|
-
select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_region, d2.store_district,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_region, d2.store_district;
|
data/doc/agg_queries_results.txt
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
mysql> select d1.calendar_year, d2.store_state,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d2.store_state;
|
2
|
-
+---------------+-------------+----------------+---------------------+
|
3
|
-
| calendar_year | store_state | sales_quantity | sales_dollar_amount |
|
4
|
-
+---------------+-------------+----------------+---------------------+
|
5
|
-
| 2001 | Florida | 6 | 6.90000009536743 |
|
6
|
-
| 2002 | Florida | 2 | 2.6800000667572 |
|
7
|
-
| 2003 | Florida | 4 | 5.3600001335144 |
|
8
|
-
| 2006 | Florida | 5 | 6.30000013113022 |
|
9
|
-
+---------------+-------------+----------------+---------------------+
|
10
|
-
4 rows in set (0.00 sec)
|
11
|
-
|
12
|
-
mysql> select d1.calendar_year, d2.store_state, d2.store_county,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d2.store_state, d2.store_county;
|
13
|
-
+---------------+-------------+--------------+----------------+---------------------+
|
14
|
-
| calendar_year | store_state | store_county | sales_quantity | sales_dollar_amount |
|
15
|
-
+---------------+-------------+--------------+----------------+---------------------+
|
16
|
-
| 2001 | Florida | Miami-Dade | 6 | 6.90000009536743 |
|
17
|
-
| 2002 | Florida | Miami-Dade | 2 | 2.6800000667572 |
|
18
|
-
| 2003 | Florida | Miami-Dade | 4 | 5.3600001335144 |
|
19
|
-
| 2006 | Florida | Miami-Dade | 5 | 6.30000013113022 |
|
20
|
-
+---------------+-------------+--------------+----------------+---------------------+
|
21
|
-
4 rows in set (0.00 sec)
|
22
|
-
|
23
|
-
mysql> select d1.calendar_year, d2.store_state, d2.store_county, d2.store_city,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d2.store_state, d2.store_county, d2.store_city;
|
24
|
-
+---------------+-------------+--------------+-------------+----------------+---------------------+
|
25
|
-
| calendar_year | store_state | store_county | store_city | sales_quantity | sales_dollar_amount |
|
26
|
-
+---------------+-------------+--------------+-------------+----------------+---------------------+
|
27
|
-
| 2001 | Florida | Miami-Dade | Miami | 3 | 3.45000004768372 |
|
28
|
-
| 2001 | Florida | Miami-Dade | South Miami | 3 | 3.45000004768372 |
|
29
|
-
| 2002 | Florida | Miami-Dade | Miami | 1 | 1.3400000333786 |
|
30
|
-
| 2002 | Florida | Miami-Dade | South Miami | 1 | 1.3400000333786 |
|
31
|
-
| 2003 | Florida | Miami-Dade | Miami | 2 | 2.6800000667572 |
|
32
|
-
| 2003 | Florida | Miami-Dade | South Miami | 2 | 2.6800000667572 |
|
33
|
-
| 2006 | Florida | Miami-Dade | Miami | 4 | 4.96000009775162 |
|
34
|
-
| 2006 | Florida | Miami-Dade | South Miami | 1 | 1.3400000333786 |
|
35
|
-
+---------------+-------------+--------------+-------------+----------------+---------------------+
|
36
|
-
8 rows in set (0.00 sec)
|
37
|
-
|
38
|
-
mysql> select d1.calendar_year, d1.calendar_month_name, d2.store_state,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d2.store_state;
|
39
|
-
+---------------+---------------------+-------------+----------------+---------------------+
|
40
|
-
| calendar_year | calendar_month_name | store_state | sales_quantity | sales_dollar_amount |
|
41
|
-
+---------------+---------------------+-------------+----------------+---------------------+
|
42
|
-
| 2001 | November | Florida | 6 | 6.90000009536743 |
|
43
|
-
| 2002 | September | Florida | 2 | 2.6800000667572 |
|
44
|
-
| 2003 | June | Florida | 4 | 5.3600001335144 |
|
45
|
-
| 2006 | October | Florida | 5 | 6.30000013113022 |
|
46
|
-
+---------------+---------------------+-------------+----------------+---------------------+
|
47
|
-
4 rows in set (0.01 sec)
|
48
|
-
|
49
|
-
mysql> select d1.calendar_year, d1.calendar_month_name, d2.store_state, d2.store_county,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d2.store_state, d2.store_county;
|
50
|
-
+---------------+---------------------+-------------+--------------+----------------+---------------------+
|
51
|
-
| calendar_year | calendar_month_name | store_state | store_county | sales_quantity | sales_dollar_amount |
|
52
|
-
+---------------+---------------------+-------------+--------------+----------------+---------------------+
|
53
|
-
| 2001 | November | Florida | Miami-Dade | 6 | 6.90000009536743 |
|
54
|
-
| 2002 | September | Florida | Miami-Dade | 2 | 2.6800000667572 |
|
55
|
-
| 2003 | June | Florida | Miami-Dade | 4 | 5.3600001335144 |
|
56
|
-
| 2006 | October | Florida | Miami-Dade | 5 | 6.30000013113022 |
|
57
|
-
+---------------+---------------------+-------------+--------------+----------------+---------------------+
|
58
|
-
4 rows in set (0.04 sec)
|
59
|
-
|
60
|
-
mysql> select d1.calendar_year, d1.calendar_month_name, d2.store_state, d2.store_county, d2.store_city,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d2.store_state, d2.store_county, d2.store_city;
|
61
|
-
+---------------+---------------------+-------------+--------------+-------------+----------------+---------------------+
|
62
|
-
| calendar_year | calendar_month_name | store_state | store_county | store_city | sales_quantity | sales_dollar_amount |
|
63
|
-
+---------------+---------------------+-------------+--------------+-------------+----------------+---------------------+
|
64
|
-
| 2001 | November | Florida | Miami-Dade | Miami | 3 | 3.45000004768372 |
|
65
|
-
| 2001 | November | Florida | Miami-Dade | South Miami | 3 | 3.45000004768372 |
|
66
|
-
| 2002 | September | Florida | Miami-Dade | Miami | 1 | 1.3400000333786 |
|
67
|
-
| 2002 | September | Florida | Miami-Dade | South Miami | 1 | 1.3400000333786 |
|
68
|
-
| 2003 | June | Florida | Miami-Dade | Miami | 2 | 2.6800000667572 |
|
69
|
-
| 2003 | June | Florida | Miami-Dade | South Miami | 2 | 2.6800000667572 |
|
70
|
-
| 2006 | October | Florida | Miami-Dade | Miami | 4 | 4.96000009775162 |
|
71
|
-
| 2006 | October | Florida | Miami-Dade | South Miami | 1 | 1.3400000333786 |
|
72
|
-
+---------------+---------------------+-------------+--------------+-------------+----------------+---------------------+
|
73
|
-
8 rows in set (0.00 sec)
|
74
|
-
|
75
|
-
mysql> select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_state,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_state;
|
76
|
-
+---------------+---------------------+---------------+-------------+----------------+---------------------+
|
77
|
-
| calendar_year | calendar_month_name | calendar_week | store_state | sales_quantity | sales_dollar_amount |
|
78
|
-
+---------------+---------------------+---------------+-------------+----------------+---------------------+
|
79
|
-
| 2001 | November | Week 45 | Florida | 6 | 6.90000009536743 |
|
80
|
-
| 2002 | September | Week 36 | Florida | 2 | 2.6800000667572 |
|
81
|
-
| 2003 | June | Week 26 | Florida | 4 | 5.3600001335144 |
|
82
|
-
| 2006 | October | Week 41 | Florida | 5 | 6.30000013113022 |
|
83
|
-
+---------------+---------------------+---------------+-------------+----------------+---------------------+
|
84
|
-
4 rows in set (0.00 sec)
|
85
|
-
|
86
|
-
mysql> select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_state, d2.store_county,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_state, d2.store_county;
|
87
|
-
+---------------+---------------------+---------------+-------------+--------------+----------------+---------------------+
|
88
|
-
| calendar_year | calendar_month_name | calendar_week | store_state | store_county | sales_quantity | sales_dollar_amount |
|
89
|
-
+---------------+---------------------+---------------+-------------+--------------+----------------+---------------------+
|
90
|
-
| 2001 | November | Week 45 | Florida | Miami-Dade | 6 | 6.90000009536743 |
|
91
|
-
| 2002 | September | Week 36 | Florida | Miami-Dade | 2 | 2.6800000667572 |
|
92
|
-
| 2003 | June | Week 26 | Florida | Miami-Dade | 4 | 5.3600001335144 |
|
93
|
-
| 2006 | October | Week 41 | Florida | Miami-Dade | 5 | 6.30000013113022 |
|
94
|
-
+---------------+---------------------+---------------+-------------+--------------+----------------+---------------------+
|
95
|
-
4 rows in set (0.01 sec)
|
96
|
-
|
97
|
-
mysql> select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_state, d2.store_county, d2.store_city,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d2.store_state, d2.store_county, d2.store_city;
|
98
|
-
+---------------+---------------------+---------------+-------------+--------------+-------------+----------------+---------------------+
|
99
|
-
| calendar_year | calendar_month_name | calendar_week | store_state | store_county | store_city | sales_quantity | sales_dollar_amount |
|
100
|
-
+---------------+---------------------+---------------+-------------+--------------+-------------+----------------+---------------------+
|
101
|
-
| 2001 | November | Week 45 | Florida | Miami-Dade | Miami | 3 | 3.45000004768372 |
|
102
|
-
| 2001 | November | Week 45 | Florida | Miami-Dade | South Miami | 3 | 3.45000004768372 |
|
103
|
-
| 2002 | September | Week 36 | Florida | Miami-Dade | Miami | 1 | 1.3400000333786 |
|
104
|
-
| 2002 | September | Week 36 | Florida | Miami-Dade | South Miami | 1 | 1.3400000333786 |
|
105
|
-
| 2003 | June | Week 26 | Florida | Miami-Dade | Miami | 2 | 2.6800000667572 |
|
106
|
-
| 2003 | June | Week 26 | Florida | Miami-Dade | South Miami | 2 | 2.6800000667572 |
|
107
|
-
| 2006 | October | Week 41 | Florida | Miami-Dade | Miami | 4 | 4.96000009775162 |
|
108
|
-
| 2006 | October | Week 41 | Florida | Miami-Dade | South Miami | 1 | 1.3400000333786 |
|
109
|
-
+---------------+---------------------+---------------+-------------+--------------+-------------+----------------+---------------------+
|
110
|
-
8 rows in set (0.04 sec)
|
111
|
-
|
112
|
-
mysql> select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_state,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_state;
|
113
|
-
+---------------+---------------------+---------------+------------------------------+-------------+----------------+---------------------+
|
114
|
-
| calendar_year | calendar_month_name | calendar_week | day_number_in_calendar_month | store_state | sales_quantity | sales_dollar_amount |
|
115
|
-
+---------------+---------------------+---------------+------------------------------+-------------+----------------+---------------------+
|
116
|
-
| 2001 | November | Week 45 | 8 | Florida | 6 | 6.90000009536743 |
|
117
|
-
| 2002 | September | Week 36 | 3 | Florida | 2 | 2.6800000667572 |
|
118
|
-
| 2003 | June | Week 26 | 30 | Florida | 4 | 5.3600001335144 |
|
119
|
-
| 2006 | October | Week 41 | 12 | Florida | 3 | 3.62000006437302 |
|
120
|
-
| 2006 | October | Week 41 | 13 | Florida | 2 | 2.6800000667572 |
|
121
|
-
+---------------+---------------------+---------------+------------------------------+-------------+----------------+---------------------+
|
122
|
-
5 rows in set (0.01 sec)
|
123
|
-
|
124
|
-
mysql> select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_state, d2.store_county,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_state, d2.store_county;
|
125
|
-
+---------------+---------------------+---------------+------------------------------+-------------+--------------+----------------+---------------------+
|
126
|
-
| calendar_year | calendar_month_name | calendar_week | day_number_in_calendar_month | store_state | store_county | sales_quantity | sales_dollar_amount |
|
127
|
-
+---------------+---------------------+---------------+------------------------------+-------------+--------------+----------------+---------------------+
|
128
|
-
| 2001 | November | Week 45 | 8 | Florida | Miami-Dade | 6 | 6.90000009536743 |
|
129
|
-
| 2002 | September | Week 36 | 3 | Florida | Miami-Dade | 2 | 2.6800000667572 |
|
130
|
-
| 2003 | June | Week 26 | 30 | Florida | Miami-Dade | 4 | 5.3600001335144 |
|
131
|
-
| 2006 | October | Week 41 | 12 | Florida | Miami-Dade | 3 | 3.62000006437302 |
|
132
|
-
| 2006 | October | Week 41 | 13 | Florida | Miami-Dade | 2 | 2.6800000667572 |
|
133
|
-
+---------------+---------------------+---------------+------------------------------+-------------+--------------+----------------+---------------------+
|
134
|
-
5 rows in set (0.01 sec)
|
135
|
-
|
136
|
-
mysql> select d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_state, d2.store_county, d2.store_city,sum(f.sales_quantity) as sales_quantity,sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_state, d2.store_county, d2.store_city;
|
137
|
-
+---------------+---------------------+---------------+------------------------------+-------------+--------------+-------------+----------------+---------------------+
|
138
|
-
| calendar_year | calendar_month_name | calendar_week | day_number_in_calendar_month | store_state | store_county | store_city | sales_quantity | sales_dollar_amount |
|
139
|
-
+---------------+---------------------+---------------+------------------------------+-------------+--------------+-------------+----------------+---------------------+
|
140
|
-
| 2001 | November | Week 45 | 8 | Florida | Miami-Dade | Miami | 3 | 3.45000004768372 |
|
141
|
-
| 2001 | November | Week 45 | 8 | Florida | Miami-Dade | South Miami | 3 | 3.45000004768372 |
|
142
|
-
| 2002 | September | Week 36 | 3 | Florida | Miami-Dade | Miami | 1 | 1.3400000333786 |
|
143
|
-
| 2002 | September | Week 36 | 3 | Florida | Miami-Dade | South Miami | 1 | 1.3400000333786 |
|
144
|
-
| 2003 | June | Week 26 | 30 | Florida | Miami-Dade | Miami | 2 | 2.6800000667572 |
|
145
|
-
| 2003 | June | Week 26 | 30 | Florida | Miami-Dade | South Miami | 2 | 2.6800000667572 |
|
146
|
-
| 2006 | October | Week 41 | 12 | Florida | Miami-Dade | Miami | 2 | 2.28000003099442 |
|
147
|
-
| 2006 | October | Week 41 | 12 | Florida | Miami-Dade | South Miami | 1 | 1.3400000333786 |
|
148
|
-
| 2006 | October | Week 41 | 13 | Florida | Miami-Dade | Miami | 2 | 2.6800000667572 |
|
149
|
-
+---------------+---------------------+---------------+------------------------------+-------------+--------------+-------------+----------------+---------------------+
|
150
|
-
9 rows in set (0.00 sec)
|
data/doc/queries.txt
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# This will sum sales quantity and group by calendar year
|
2
|
-
select d1.calendar_year, sum(f.sales_quantity) from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id group by d1.calendar_year;
|
3
|
-
|
4
|
-
# This will sum sales quantity and group by store name
|
5
|
-
select d2.store_name, sum(f.sales_quantity) from pos_retail_sales_transaction_facts f join store_dimension d2 on f.store_id = d2.id group by d2.store_name;
|
6
|
-
|
7
|
-
# This will sum sales quantity and group by calendar year and store name
|
8
|
-
select d1.calendar_year, d2.store_name, sum(f.sales_quantity) from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d2.store_name;
|
9
|
-
|
10
|
-
# This will sum sales quantity and group by calendar year and store region
|
11
|
-
select d1.calendar_year, d2.store_region, sum(f.sales_quantity) as sales_quantity from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d2.store_region;
|
12
|
-
|
13
|
-
|
14
|
-
select d1.calendar_year, d1.calendar_quarter, d2.store_region, sum(f.sales_quantity) as sales_quantity from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_quarter, d2.store_region;
|
15
|
-
|
16
|
-
select d1.calendar_year, d1.calendar_quarter, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_region, d2.store_district, sum(f.sales_quantity) as sales_quantity, sum(f.sales_dollar_amount) as sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id group by d1.calendar_year, d1.calendar_quarter, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month, d2.store_region, d2.store_district;
|
17
|
-
|
18
|
-
|
19
|
-
select * from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id;
|
20
|
-
|
21
|
-
|
22
|
-
select f.pos_transaction_number, d1.calendar_year, d1.calendar_month_name, d1.calendar_week, d1.day_number_in_calendar_month as day, d2.store_region, d2.store_district, f.sales_quantity, f.sales_dollar_amount from pos_retail_sales_transaction_facts f join date_dimension d1 on f.date_id = d1.id join store_dimension d2 on f.store_id = d2.id;
|
23
|
-
|
24
|
-
|
25
|
-
# This will calculate the number of days per year
|
26
|
-
select calendar_year, count(id) from date_dimension group by calendar_year;
|
27
|
-
|
28
|
-
# This will calculate the number of days per month for a particular calendar year
|
29
|
-
select calendar_year, calendar_month_name, count(id) from date_dimension where calendar_year = 2002 group by calendar_month_name;
|
30
|
-
|
31
|
-
# This will calculate the number of fiscal year months in each calendar year. * This is what to use for denomniators *
|
32
|
-
select calendar_year, count(distinct(fiscal_year_month)) from date_dimension group by calendar_year;
|
33
|
-
|
34
|
-
# The example below shows the number of days in each week for each fiscal month
|
35
|
-
select calendar_year_month, count(distinct(day_of_week)) from date_dimension where calendar_year = 2002 group by calendar_year_month;
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module ActiveWarehouse
|
2
|
-
class Bridge < ActiveRecord::Base
|
3
|
-
class << self
|
4
|
-
# Get the table name. By default the table name will be the name of the dimension in singular form.
|
5
|
-
#
|
6
|
-
# Example: DateDimension will have a table called date_dimension
|
7
|
-
def table_name
|
8
|
-
name = self.name.demodulize.underscore
|
9
|
-
set_table_name(name)
|
10
|
-
name
|
11
|
-
end
|
12
|
-
|
13
|
-
def build_table(force=false)
|
14
|
-
connection.drop_table(table_name) if force and table_exists?
|
15
|
-
if !table_exists?
|
16
|
-
connection.create_table(table_name, :id => false) do |t|
|
17
|
-
t.column :parent_id, :integer
|
18
|
-
t.column :child_id, :integer
|
19
|
-
t.column :levels_from_parent, :integer
|
20
|
-
t.column :bottom_flag, :boolean
|
21
|
-
t.column :top_flag, :boolean
|
22
|
-
end
|
23
|
-
connection.add_index table_name, :parent_id
|
24
|
-
connection.add_index table_name, :child_id
|
25
|
-
connection.add_index table_name, :levels_from_parent
|
26
|
-
connection.add_index table_name, :bottom_flag
|
27
|
-
connection.add_index table_name, :top_flag
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
module ActiveWarehouse
|
2
|
-
class Dimension < ActiveRecord::Base
|
3
|
-
class << self
|
4
|
-
|
5
|
-
# Indicate that this dimension is a variable depth hierarchical dimension. Calling this method will
|
6
|
-
# mix-in the ActiveWarehouse::HierarchicalDimension module, adding methods to support the hierarchical
|
7
|
-
# representation of this dimension
|
8
|
-
def acts_as_hierarchy_dimension
|
9
|
-
# Mix in the hierarchy dimension support code
|
10
|
-
include ActiveWarehouse::HierarchicalDimension
|
11
|
-
end
|
12
|
-
|
13
|
-
# Define a named attribute hierarchy in the dimension.
|
14
|
-
#
|
15
|
-
# Example: define_hierarchy(:fiscal_calendar, [:fiscal_year, :fiscal_quarter, :fiscal_month])
|
16
|
-
#
|
17
|
-
# This would indicate that one of the drill down paths for this dimension is:
|
18
|
-
# Fiscal Year -> Fiscal Quarter -> Fiscal Month
|
19
|
-
#
|
20
|
-
# Internally the hierarchies are stored in order. The first hierarchy defined will be used as the default
|
21
|
-
# if no hierarchy is specified when rendering a cube.
|
22
|
-
def define_hierarchy(name, levels)
|
23
|
-
hierarchies << name
|
24
|
-
hierarchy_levels[name] = levels
|
25
|
-
end
|
26
|
-
|
27
|
-
# Get the named attribute hierarchy
|
28
|
-
#
|
29
|
-
# Example: hierarchy(:fiscal_calendar) might return [:fiscal_year, :fiscal_quarter, :fiscal_month]
|
30
|
-
def hierarchy(name)
|
31
|
-
hierarchy_levels[name]
|
32
|
-
end
|
33
|
-
|
34
|
-
# Get the ordered hierarchy names
|
35
|
-
def hierarchies
|
36
|
-
@hierarchies ||= []
|
37
|
-
end
|
38
|
-
|
39
|
-
# Get the hierarchy levels hash
|
40
|
-
def hierarchy_levels
|
41
|
-
@hierarchy_levels ||= {}
|
42
|
-
end
|
43
|
-
|
44
|
-
# Return a symbol used when referring to this dimension. The symbol is calculated by demodulizing and underscoring the
|
45
|
-
# dimension's class name and then removing the trailing _dimension.
|
46
|
-
#
|
47
|
-
# Example: DateDimension will return a symbol :date
|
48
|
-
def sym
|
49
|
-
self.name.demodulize.underscore.gsub(/_dimension/, '').to_sym
|
50
|
-
end
|
51
|
-
|
52
|
-
# Get the table name. By default the table name will be the name of the dimension in singular form.
|
53
|
-
#
|
54
|
-
# Example: DateDimension will have a table called date_dimension
|
55
|
-
def table_name
|
56
|
-
name = self.name.demodulize.underscore
|
57
|
-
set_table_name(name)
|
58
|
-
name
|
59
|
-
end
|
60
|
-
|
61
|
-
# Convert the given name into a dimension class name
|
62
|
-
def class_name(name)
|
63
|
-
dimension_name = name.to_s
|
64
|
-
dimension_name = "#{dimension_name}_dimension" unless dimension_name =~ /_dimension$/
|
65
|
-
dimension_name.classify
|
66
|
-
end
|
67
|
-
|
68
|
-
# Get a class for the specified named dimension
|
69
|
-
def class_for_name(name)
|
70
|
-
class_name(name).constantize
|
71
|
-
end
|
72
|
-
|
73
|
-
# Return the time when the underlying dimension source file was last modified. This is used
|
74
|
-
# to determine if a cube structure rebuild is required
|
75
|
-
def last_modified
|
76
|
-
File.new(__FILE__).mtime
|
77
|
-
end
|
78
|
-
|
79
|
-
# Get the dimension class for the specified dimension parameter. The dimension parameter may be a class,
|
80
|
-
# String or Symbol.
|
81
|
-
def to_dimension(dimension)
|
82
|
-
return dimension if dimension.is_a?(Class) and dimension.superclass == Dimension
|
83
|
-
return class_for_name(dimension)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Returns a hash of all of the values at the specified hierarchy level mapped to the count at that level.
|
87
|
-
# For example, given a date dimension with years from 2002 to 2004 and a hierarchy defined with:
|
88
|
-
#
|
89
|
-
# hierarchy :cy, [:calendar_year, :calendar_quarter, :calendar_month_name]
|
90
|
-
#
|
91
|
-
# ...then...
|
92
|
-
#
|
93
|
-
# DateDimension.denominator_count(:cy, :calendar_year, :calendar_quarter) returns {'2002' => 4, '2003' => 4, '2004' => 4}
|
94
|
-
#
|
95
|
-
# If the denominator_level parameter is omitted or nil then:
|
96
|
-
#
|
97
|
-
# DateDimension.denominator_count(:cy, :calendar_year) returns {'2003' => 365, '2003' => 365, '2004' => 366}
|
98
|
-
#
|
99
|
-
def denominator_count(hierarchy_name, level, denominator_level=nil)
|
100
|
-
if hierarchy_levels[hierarchy_name].nil?
|
101
|
-
raise ArgumentError, "The hierarchy '#{hierarchy_name}' does not exist in your dimension #{name}"
|
102
|
-
end
|
103
|
-
|
104
|
-
q = nil
|
105
|
-
# If the denominator_level is specified and it is not the last element in the hierarchy then do a distinct count. If
|
106
|
-
# the denominator level is less than the current level then raise an ArgumentError. In other words, if the current level is
|
107
|
-
# calendar month then passing in calendar year as the denominator level would raise an ArgumentErro.
|
108
|
-
#
|
109
|
-
# If the denominator_level is not specified then assume the finest grain possible (in the context of a date dimension
|
110
|
-
# this would be each day) and use the id to count.
|
111
|
-
if denominator_level && hierarchy_levels[hierarchy_name].last != denominator_level
|
112
|
-
level_index = hierarchy_levels[hierarchy_name].index(level)
|
113
|
-
denominator_index = hierarchy_levels[hierarchy_name].index(denominator_level)
|
114
|
-
|
115
|
-
if level_index.nil?
|
116
|
-
raise ArgumentError, "The level '#{level}' does not appear to exist"
|
117
|
-
end
|
118
|
-
if denominator_index.nil?
|
119
|
-
raise ArgumentError, "The denominator level '#{denominator_level}' does not appear to exist"
|
120
|
-
end
|
121
|
-
if hierarchy_levels[hierarchy_name].index(denominator_level) < hierarchy_levels[hierarchy_name].index(level)
|
122
|
-
raise ArgumentError, "The index of the denominator level '#{denominator_level}' in the hierarchy '#{hierarchy_name}' must be greater than or equal to the level '#{level}'"
|
123
|
-
end
|
124
|
-
|
125
|
-
q = "select #{level}, count(distinct(#{denominator_level})) from #{table_name} group by #{level}"
|
126
|
-
else
|
127
|
-
q = "select #{level}, count(id) from #{table_name} group by #{level}"
|
128
|
-
end
|
129
|
-
denominators = {}
|
130
|
-
connection.execute(q).each do |row|
|
131
|
-
denominators[row[0]] = row[1].to_i
|
132
|
-
end
|
133
|
-
denominators
|
134
|
-
end
|
135
|
-
|
136
|
-
# Get the foreign key for this dimension which is used in Fact tables.
|
137
|
-
#
|
138
|
-
# Example: DateDimension would have a foreign key of date_id
|
139
|
-
def foreign_key
|
140
|
-
table_name.sub(/_dimension/,'') + '_id'
|
141
|
-
end
|
142
|
-
|
143
|
-
# Get an array of the available values for a particular hierarchy level
|
144
|
-
# For example, given a DateDimension with data from 2002 to 2004:
|
145
|
-
#
|
146
|
-
# available_values('calendar_year') returns ['2002','2003','2004']
|
147
|
-
def available_values(level)
|
148
|
-
find(:all, :group => level.to_s, :order => level.to_s).collect {|dim| dim.send(level.to_sym)}
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module ActiveWarehouse
|
2
|
-
module HierarchicalDimension
|
3
|
-
def self.included(base)
|
4
|
-
base.extend(ClassMethods)
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
# Get the bridge class for this hierarchical dimension
|
9
|
-
def bridge_class
|
10
|
-
unless @bridge_class
|
11
|
-
@bridge_class = Class.new(ActiveWarehouse::Bridge)
|
12
|
-
Object.const_set(bridge_class_name, @bridge_class)
|
13
|
-
end
|
14
|
-
@bridge_class
|
15
|
-
end
|
16
|
-
|
17
|
-
# Get the bridge class name for this hierarchical dimension
|
18
|
-
def bridge_class_name
|
19
|
-
name.gsub(/Dimension$/, '') + 'HierarchyBridge'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Get the parent for this node
|
24
|
-
def parent
|
25
|
-
bridge = bridge_class.new
|
26
|
-
bridge.find(:first, :conditions => ['levels_from_parent = 1 and child_id = ?', self.id])
|
27
|
-
end
|
28
|
-
|
29
|
-
# Get the children for this node
|
30
|
-
def children
|
31
|
-
bridge = bridge_class.new
|
32
|
-
bridge.find(:all, :conditions => ['levels_from_parent = 1 and parent_id = ?', self.id])
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|