chicagowarehouse 0.6.6 → 0.6.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a54a10415694e7c293cf98d338f1ec7e29343cc
4
- data.tar.gz: 65d485e97187351d7dc90cada98956f43a424eb9
3
+ metadata.gz: 0d1ffe55091b2b8fac1433fc50fef9671530f206
4
+ data.tar.gz: 480006599cc1e0cf41dc81c939f708c23df47697
5
5
  SHA512:
6
- metadata.gz: f3412a1bf3b456d3e1c47e36990366144390ea6a85d78f753f35e6fb76ab441ecd3bc6ccf024e205231405a25b01a80aae36f2144a807a9f7dadab8488d0926a
7
- data.tar.gz: ca7b1e11af675ce66af8c81511f34768c00072cc277f2925548916165ca15736cf43fa49e68467111da6b767c925cd527cc98544cbaa2fc3f296603b864e6c19
6
+ metadata.gz: 7683d3c320d51fd44bc56e4071327a459b1484677c0c28221b156209a57a515d2a41198fc6f0e549aa4cda672e966c785f6de96df11cb2b5e2d8a081561bd25c
7
+ data.tar.gz: 805ac03ef39232f596cc8ce254d7d0cc7daace567f7bbb8ea7a1477077875f86f1705986381b05ae590d47eae3288055b45212ba471d27e719472895e2212cc4
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ require 'rake'
14
14
  require 'jeweler'
15
15
  Jeweler::Tasks.new do |gem|
16
16
  gem.name = "chicagowarehouse"
17
- gem.version = "0.6.6"
17
+ gem.version = "0.6.7"
18
18
  gem.summary = "Ruby Data Warehousing"
19
19
  gem.description = "Simple Data Warehouse toolkit for ruby"
20
20
  gem.author = "Roland Swingler"
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: chicagowarehouse 0.6.6 ruby lib
5
+ # stub: chicagowarehouse 0.6.7 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "chicagowarehouse"
9
- s.version = "0.6.6"
9
+ s.version = "0.6.7"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -63,6 +63,7 @@ Gem::Specification.new do |s|
63
63
  "spec/database/schema_generator_spec.rb",
64
64
  "spec/db_connections.yml.dist",
65
65
  "spec/query_spec.rb",
66
+ "spec/schema/column_parser_spec.rb",
66
67
  "spec/schema/column_spec.rb",
67
68
  "spec/schema/dimension_builder_spec.rb",
68
69
  "spec/schema/dimension_reference_spec.rb",
@@ -93,8 +93,8 @@ module Chicago
93
93
  end
94
94
 
95
95
  def simple_column(elem)
96
- table, col = parse_parts(elem)
97
- QueryColumn.column(table, col, elem.to_sym)
96
+ table, col, table_qualifier = parse_parts(elem)
97
+ QueryColumn.column(table, col, elem.to_sym, table_qualifier)
98
98
  end
99
99
 
100
100
  def calculated_column(elem)
@@ -111,9 +111,10 @@ module Chicago
111
111
  if col.kind_of?(Chicago::Schema::Dimension)
112
112
  table = col
113
113
  col = parts.empty? ? table : table[parts.first]
114
+ table_qualifier = table.label if table.roleplayed?
114
115
  end
115
116
 
116
- [table, col]
117
+ [table, col, table_qualifier]
117
118
  end
118
119
 
119
120
  def parse_table(str)
@@ -40,6 +40,14 @@ module Chicago
40
40
  database_name.qualify(table)
41
41
  end
42
42
 
43
+ # Returns true if this dimension reference is roleplayed -
44
+ # i.e. it has a different name from the underlying dimension so
45
+ # that, for example, multiple date dimensions can be assigned to
46
+ # the same fact table.
47
+ def roleplayed?
48
+ name != @dimension.name
49
+ end
50
+
43
51
  # Returns the first null record id for this dimension, or 0 if
44
52
  # the dimension has no null records defined.
45
53
  def default_value
@@ -14,8 +14,9 @@ module Chicago
14
14
  end
15
15
 
16
16
  # @private
17
- def initialize(column)
17
+ def initialize(column, table_label=nil)
18
18
  @column = column
19
+ @table_label = table_label
19
20
  end
20
21
 
21
22
  # @private
@@ -23,21 +24,32 @@ module Chicago
23
24
  @column.send(*args, &block)
24
25
  end
25
26
 
27
+ # Returns the label for this column.
28
+ #
29
+ # The label is qualified by the table name if neccessary
30
+ # (i.e. if the column comes from a dimension which features
31
+ # multiple times in the same fact table).
32
+ def qualified_label
33
+ @table_label ? "#{label} (#{@table_label})" : label
34
+ end
35
+
26
36
  # Factory method that returns a query column.
27
37
  #
28
38
  # @param owner the column owner, normally a fact or dimension
29
39
  # @param column the wrapped column
30
40
  # @param column_alias the reference to this column as used by
31
41
  # the column parser.
32
- def self.column(owner, column, column_alias)
42
+ # @param table_label a table name to distinguish this column
43
+ # from and identically named one. May be nil.
44
+ def self.column(owner, column, column_alias, table_label)
33
45
  if column.kind_of?(Chicago::Schema::Dimension)
34
46
  DimensionAsColumn.new(owner, column, column_alias)
35
47
  elsif owner.kind_of?(Chicago::Schema::Dimension) && owner.identifiable? && owner.identifiers.include?(column.name)
36
48
  DimensionIdentifierColumn.new(owner, column, column_alias)
37
49
  elsif column.calculated?
38
- VirtualColumn.new(owner, column, column_alias)
50
+ VirtualColumn.new(owner, column, column_alias, table_label)
39
51
  else
40
- QualifiedColumn.new(owner, column, column_alias)
52
+ QualifiedColumn.new(owner, column, column_alias, table_label)
41
53
  end
42
54
  end
43
55
 
@@ -48,8 +60,8 @@ module Chicago
48
60
 
49
61
  # @abstract
50
62
  class AbstractQualifiedColumn < QueryColumn
51
- def initialize(owner, column, column_alias)
52
- super column
63
+ def initialize(owner, column, column_alias, table_label=nil)
64
+ super column, table_label
53
65
  @owner = owner
54
66
  @column_alias = column_alias
55
67
  end
@@ -85,7 +97,7 @@ module Chicago
85
97
  end
86
98
 
87
99
  class QualifiedColumn < AbstractQualifiedColumn
88
- def initialize(owner, column, column_alias)
100
+ def initialize(owner, column, column_alias, table_label)
89
101
  super
90
102
  @select_name = @column.name.qualify(@owner.name)
91
103
  @count_name = @select_name
@@ -100,8 +112,8 @@ module Chicago
100
112
  # - filters will appear in the HAVING clause, not the WHERE clause
101
113
  # of the SQL statement.
102
114
  class VirtualColumn < QualifiedColumn
103
- def initialize(owner, column, column_alias)
104
- super(owner, column, column_alias)
115
+ def initialize(owner, column, column_alias, table_label)
116
+ super
105
117
  @select_name = @column.calculation
106
118
  end
107
119
 
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chicago::Schema::ColumnParser do
4
+ let(:schema) do
5
+ schema = Chicago::StarSchema.new
6
+
7
+ schema.define_dimension(:date) do
8
+ columns do
9
+ string :day
10
+ end
11
+ end
12
+
13
+ schema.define_dimension(:product) do
14
+ columns do
15
+ string :name
16
+ end
17
+ end
18
+
19
+ schema.define_fact(:sales) do
20
+ dimensions :product, :date.as(:order_date), :date.as(:refund_date)
21
+ end
22
+
23
+ schema
24
+ end
25
+
26
+ subject { described_class.new(schema) }
27
+
28
+ it "has a qualified label for roleplayed dimensions" do
29
+ column = subject.parse("sales.order_date.day").first
30
+ expect(column.label).to eql("Day")
31
+ expect(column.qualified_label).to eql("Day (Order Date)")
32
+ end
33
+
34
+ it "has a non-qualified label for non-roleplayed dimensions" do
35
+ column = subject.parse("sales.product.name").first
36
+
37
+ expect(column.qualified_label).to eql("Name")
38
+ end
39
+ end
@@ -98,6 +98,11 @@ describe Chicago::Schema::DimensionReference do
98
98
  described_class.new(:foo, @dimension).default_value.should == 1
99
99
  end
100
100
 
101
+ it "knows whether it is a roleplayed dimension or not" do
102
+ expect(described_class.new(:bar, @dimension)).to_not be_roleplayed
103
+ expect(described_class.new(:foo, @dimension)).to be_roleplayed
104
+ end
105
+
101
106
  it "is visitable" do
102
107
  visitor = double(:visitor)
103
108
  column = described_class.new(:foo, @dimension)
@@ -5,7 +5,7 @@ describe Chicago::Schema::QueryColumn do
5
5
  describe "a standard column" do
6
6
  let(:owner) { double(:owner).as_null_object }
7
7
  let(:column) { double(:column, :calculated? => false).as_null_object }
8
- subject { described_class.column(owner, column, "foo.bar") }
8
+ subject { described_class.column(owner, column, "foo.bar", nil) }
9
9
 
10
10
  it "should have a column alias" do
11
11
  subject.column_alias.should == "foo.bar"
@@ -41,7 +41,7 @@ describe Chicago::Schema::QueryColumn do
41
41
  let(:calculation) { double(:calculation).as_null_object }
42
42
  let(:owner) { double(:owner).as_null_object }
43
43
  let(:column) { double(:column, :calculated? => true, :calculation => calculation).as_null_object }
44
- subject { described_class.column(owner, column, "foo.bar") }
44
+ subject { described_class.column(owner, column, "foo.bar", nil) }
45
45
 
46
46
  it "should have a column alias" do
47
47
  subject.column_alias.should == "foo.bar"
@@ -70,7 +70,7 @@ describe Chicago::Schema::QueryColumn do
70
70
  describe "a dimension column" do
71
71
  let(:owner) { double(:owner).as_null_object }
72
72
  let(:column) { double(:column).as_null_object }
73
- subject { described_class.column(owner, column, "foo.bar") }
73
+ subject { described_class.column(owner, column, "foo.bar", nil) }
74
74
 
75
75
  before :each do
76
76
  column.stub(:main_identifier).and_return(:name)
@@ -110,7 +110,7 @@ describe Chicago::Schema::QueryColumn do
110
110
  describe "a dimension identifier column" do
111
111
  let(:owner) { double(:owner).as_null_object }
112
112
  let(:column) { double(:column).as_null_object }
113
- subject { described_class.column(owner, column, "foo.bar") }
113
+ subject { described_class.column(owner, column, "foo.bar", nil) }
114
114
 
115
115
  before :each do
116
116
  column.stub(:name).and_return(:bar)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chicagowarehouse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roland Swingler
@@ -216,6 +216,7 @@ files:
216
216
  - spec/database/schema_generator_spec.rb
217
217
  - spec/db_connections.yml.dist
218
218
  - spec/query_spec.rb
219
+ - spec/schema/column_parser_spec.rb
219
220
  - spec/schema/column_spec.rb
220
221
  - spec/schema/dimension_builder_spec.rb
221
222
  - spec/schema/dimension_reference_spec.rb