activewarehouse 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. data/README +41 -0
  2. data/Rakefile +121 -0
  3. data/TODO +4 -0
  4. data/db/migrations/001_create_table_reports.rb +28 -0
  5. data/doc/agg_queries.txt +26 -0
  6. data/doc/agg_queries_results.txt +150 -0
  7. data/doc/queries.txt +35 -0
  8. data/generators/cube/USAGE +1 -0
  9. data/generators/cube/cube_generator.rb +28 -0
  10. data/generators/cube/templates/model.rb +3 -0
  11. data/generators/cube/templates/unit_test.rb +8 -0
  12. data/generators/dimension/USAGE +1 -0
  13. data/generators/dimension/dimension_generator.rb +46 -0
  14. data/generators/dimension/templates/fixture.yml +5 -0
  15. data/generators/dimension/templates/migration.rb +20 -0
  16. data/generators/dimension/templates/model.rb +3 -0
  17. data/generators/dimension/templates/unit_test.rb +10 -0
  18. data/generators/fact/USAGE +1 -0
  19. data/generators/fact/fact_generator.rb +46 -0
  20. data/generators/fact/templates/fixture.yml +5 -0
  21. data/generators/fact/templates/migration.rb +11 -0
  22. data/generators/fact/templates/model.rb +3 -0
  23. data/generators/fact/templates/unit_test.rb +10 -0
  24. data/install.rb +5 -0
  25. data/lib/active_warehouse.rb +65 -0
  26. data/lib/active_warehouse/builder.rb +2 -0
  27. data/lib/active_warehouse/builder/date_dimension_builder.rb +65 -0
  28. data/lib/active_warehouse/builder/random_data_builder.rb +13 -0
  29. data/lib/active_warehouse/core_ext.rb +1 -0
  30. data/lib/active_warehouse/core_ext/time.rb +5 -0
  31. data/lib/active_warehouse/core_ext/time/calculations.rb +40 -0
  32. data/lib/active_warehouse/migrations.rb +65 -0
  33. data/lib/active_warehouse/model.rb +5 -0
  34. data/lib/active_warehouse/model/aggregate.rb +244 -0
  35. data/lib/active_warehouse/model/cube.rb +273 -0
  36. data/lib/active_warehouse/model/dimension.rb +3 -0
  37. data/lib/active_warehouse/model/dimension/bridge.rb +32 -0
  38. data/lib/active_warehouse/model/dimension/dimension.rb +152 -0
  39. data/lib/active_warehouse/model/dimension/hierarchical_dimension.rb +35 -0
  40. data/lib/active_warehouse/model/fact.rb +96 -0
  41. data/lib/active_warehouse/model/report.rb +3 -0
  42. data/lib/active_warehouse/model/report/abstract_report.rb +121 -0
  43. data/lib/active_warehouse/model/report/chart_report.rb +9 -0
  44. data/lib/active_warehouse/model/report/table_report.rb +23 -0
  45. data/lib/active_warehouse/version.rb +9 -0
  46. data/lib/active_warehouse/view.rb +2 -0
  47. data/lib/active_warehouse/view/report_helper.rb +213 -0
  48. data/tasks/active_warehouse_tasks.rake +50 -0
  49. metadata +144 -0
data/README ADDED
@@ -0,0 +1,41 @@
1
+ ActiveWarehouse
2
+ ===============
3
+ The ActiveWarehouse library provides classes and functions which help with building Data Warehouses using Rails. It can be installed either as a plugin or as a Gem. If you install it as a gem you must include the following in your config/environment.rb:
4
+
5
+ require_gem 'activewarehouse'
6
+ require 'active_warehouse'
7
+
8
+ Additionally, to use the Rake tasks you must include the following in your Rakefile:
9
+
10
+ load 'tasks/active_warehouse_tasks.rake'
11
+
12
+ Generators
13
+ ===============
14
+ ActiveWarehouse comes with several generators
15
+
16
+ script/generate fact Sales
17
+ script/generate fact sales
18
+
19
+ Creates a SalesFact class and a sales_facts table.
20
+
21
+ script/generate dimension Region
22
+ script/generate dimension region
23
+
24
+ Creates a RegionDimension class and a region_dimension table.
25
+
26
+ script/generate cube RegionalSales
27
+ script/generate cube regional_sales
28
+
29
+ Creates a RegionalSalesCube class.
30
+
31
+ The rules for naming are as follows:
32
+
33
+ Facts:
34
+ Fact classes and tables follow the typical Rails rules: classes are singular and tables are pluralized.
35
+ Both the class and table name are suffixed by "_fact".
36
+ Dimensions:
37
+ Dimension classes and tables are both singular.
38
+ Both the class name and the table name are suffixed by "_dimension".
39
+ Cube:
40
+ Cube class is singular. If a cube table is created it will also be singular.
41
+
data/Rakefile ADDED
@@ -0,0 +1,121 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/contrib/rubyforgepublisher'
6
+
7
+ require File.join(File.dirname(__FILE__), 'lib/active_warehouse', 'version')
8
+
9
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
10
+ PKG_NAME = 'activewarehouse'
11
+ PKG_VERSION = ActiveWarehouse::VERSION::STRING + PKG_BUILD
12
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
13
+ PKG_DESTINATION = ENV["PKG_DESTINATION"] || "../#{PKG_NAME}"
14
+
15
+ RELEASE_NAME = "REL #{PKG_VERSION}"
16
+
17
+ RUBY_FORGE_PROJECT = "activewarehouse"
18
+ RUBY_FORGE_USER = "aeden"
19
+
20
+ desc 'Default: run unit tests.'
21
+ task :default => :test
22
+
23
+ desc 'Test the active_warehouse plugin.'
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.pattern = 'test/**/*_test.rb'
27
+ t.verbose = true
28
+ end
29
+
30
+ desc 'Generate documentation for the active_warehouse plugin.'
31
+ Rake::RDocTask.new(:rdoc) do |rdoc|
32
+ rdoc.rdoc_dir = 'rdoc'
33
+ rdoc.title = 'ActiveWarehouse'
34
+ rdoc.options << '--line-numbers' << '--inline-source'
35
+ rdoc.rdoc_files.include('README')
36
+ rdoc.rdoc_files.include('lib/**/*.rb')
37
+ end
38
+
39
+ # Gem Spec
40
+ PKG_FILES = FileList[
41
+ '[a-zA-Z]*.rb',
42
+ 'README',
43
+ 'TODO',
44
+ 'Rakefile',
45
+ 'db/**/*',
46
+ 'doc/**/*',
47
+ 'generators/**/*',
48
+ 'lib/**/*',
49
+ 'tasks/**/*'
50
+ ] - [ 'test' ]
51
+
52
+ spec = Gem::Specification.new do |s|
53
+ s.name = 'activewarehouse'
54
+ s.version = PKG_VERSION
55
+ s.summary = "Build data warehouses with Rails."
56
+ s.description = <<-EOF
57
+ ActiveWarehouse extends Rails to provide functionality specific for building data warehouses.
58
+ EOF
59
+
60
+ s.add_dependency('rake', '>= 0.7.1')
61
+ s.add_dependency('activesupport', '>= 1.3.1.5618')
62
+ s.add_dependency('activerecord', '>= 1.14.4.5618')
63
+ s.add_dependency('actionpack', '>= 1.12.5.5618')
64
+
65
+ s.rdoc_options << '--exclude' << '.'
66
+ s.has_rdoc = false
67
+
68
+ s.files = PKG_FILES.to_a.delete_if {|f| f.include?('.svn')}
69
+ s.require_path = 'lib'
70
+
71
+ #s.bindir = "bin" # Use these for applications.
72
+ #s.executables = []
73
+ #s.default_executable = ""
74
+
75
+ s.author = "Anthony Eden"
76
+ s.email = "anthonyeden@gmail.com"
77
+ s.homepage = "http://activewarehouse.rubyforge.org"
78
+ s.rubyforge_project = "activewarehouse"
79
+ end
80
+
81
+ Rake::GemPackageTask.new(spec) do |pkg|
82
+ pkg.gem_spec = spec
83
+ pkg.need_tar = true
84
+ pkg.need_zip = true
85
+ end
86
+
87
+ desc "Generate code statistics"
88
+ task :lines do
89
+ lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
90
+
91
+ for file_name in FileList["lib/**/*.rb"]
92
+ next if file_name =~ /vendor/
93
+ f = File.open(file_name)
94
+
95
+ while line = f.gets
96
+ lines += 1
97
+ next if line =~ /^\s*$/
98
+ next if line =~ /^\s*#/
99
+ codelines += 1
100
+ end
101
+ puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
102
+
103
+ total_lines += lines
104
+ total_codelines += codelines
105
+
106
+ lines, codelines = 0, 0
107
+ end
108
+
109
+ puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
110
+ end
111
+
112
+ desc "Publish the release files to RubyForge."
113
+ task :release => [ :package ] do
114
+ `rubyforge login`
115
+
116
+ for ext in %w( gem tgz zip )
117
+ release_command = "rubyforge add_release activewarehouse #{PKG_NAME} 'REL #{PKG_VERSION}' pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}"
118
+ puts release_command
119
+ system(release_command)
120
+ end
121
+ end
data/TODO ADDED
@@ -0,0 +1,4 @@
1
+ TODO list:
2
+
3
+ * Modify the fact generator so that the migration has a map for foreign key and a map for fact attributes. The foreign keys can then automatically be indexed as that is pretty much standard behavior.
4
+ * Make the belongs_to connection between facts and dimensions automatic.
@@ -0,0 +1,28 @@
1
+ class CreateTableReports < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :table_reports do |t|
4
+ t.column :title, :string
5
+ t.column :cube_name, :string, :null => false
6
+
7
+ t.column :column_dimension_name, :string
8
+ t.column :column_hierarchy, :string
9
+ t.column :column_constraints, :text
10
+ t.column :column_stage, :integer
11
+ t.column :column_param_prefix, :string
12
+
13
+ t.column :row_dimension_name, :string
14
+ t.column :row_hierarchy, :string
15
+ t.column :row_constraints, :text
16
+ t.column :row_stage, :integer
17
+ t.column :row_param_prefix, :string
18
+
19
+ t.column :fact_attributes, :text
20
+
21
+ t.column :created_at, :datetime
22
+ t.column :updated_at, :datetime
23
+ end
24
+ end
25
+ def self.down
26
+ drop_table :table_reports
27
+ end
28
+ end
@@ -0,0 +1,26 @@
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;
@@ -0,0 +1,150 @@
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 ADDED
@@ -0,0 +1,35 @@
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;
@@ -0,0 +1 @@
1
+ ./script/generate cube NAME
@@ -0,0 +1,28 @@
1
+ class CubeGenerator < Rails::Generator::NamedBase
2
+ attr_accessor :file_name
3
+
4
+ def initialize(runtime_args, runtime_options = {})
5
+ super
6
+
7
+ @name = @name.underscore
8
+ @table_name = "#{@name}_cube"
9
+ @class_name = "#{@name.camelize}Cube"
10
+ @file_name = "#{@class_name.tableize.singularize}"
11
+ end
12
+
13
+ def manifest
14
+ record do |m|
15
+ # Check for class naming collisions.
16
+ m.class_collisions class_path, "#{class_name}", "#{class_name}Test"
17
+
18
+ # Create required directories if necessary
19
+ m.directory File.join('app/models', class_path)
20
+ m.directory File.join('test/unit', class_path)
21
+
22
+ # Generate the files
23
+ m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
24
+ m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
25
+ end
26
+ end
27
+
28
+ end