axiom-sql-generator 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.ruby-gemset +1 -0
- data/.travis.yml +17 -23
- data/CONTRIBUTING.md +1 -2
- data/Gemfile +10 -3
- data/Gemfile.devtools +39 -27
- data/README.md +5 -33
- data/axiom-sql-generator.gemspec +3 -5
- data/config/devtools.yml +2 -0
- data/config/flay.yml +1 -1
- data/config/reek.yml +1 -1
- data/config/rubocop.yml +59 -0
- data/lib/axiom/sql/generator/core_ext/date_time.rb +5 -6
- data/lib/axiom/sql/generator/direction.rb +4 -4
- data/lib/axiom/sql/generator/function/predicate.rb +1 -1
- data/lib/axiom/sql/generator/relation.rb +12 -11
- data/lib/axiom/sql/generator/relation/binary.rb +1 -1
- data/lib/axiom/sql/generator/relation/insertion.rb +1 -1
- data/lib/axiom/sql/generator/relation/unary.rb +20 -20
- data/lib/axiom/sql/generator/version.rb +1 -1
- data/lib/axiom/sql/generator/visitor.rb +3 -3
- data/spec/spec_helper.rb +11 -10
- data/spec/support/config_alias.rb +2 -0
- data/spec/unit/axiom/sql/generator/direction/{visit_axiom_relation_operation_order_ascending_spec.rb → visit_axiom_relation_operation_sorted_ascending_spec.rb} +2 -2
- data/spec/unit/axiom/sql/generator/direction/{visit_axiom_relation_operation_order_descending_spec.rb → visit_axiom_relation_operation_sorted_descending_spec.rb} +2 -2
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_exclusion_spec.rb +1 -1
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_inclusion_spec.rb +1 -1
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_inequality_spec.rb +3 -3
- data/spec/unit/axiom/sql/generator/literal/visit_enumerable_spec.rb +1 -1
- data/spec/unit/axiom/sql/generator/relation/binary/base/to_subquery_spec.rb +7 -7
- data/spec/unit/axiom/sql/generator/relation/binary/base/visit_axiom_relation_base_spec.rb +8 -8
- data/spec/unit/axiom/sql/generator/relation/binary/to_s_spec.rb +7 -7
- data/spec/unit/axiom/sql/generator/relation/binary/to_subquery_spec.rb +7 -7
- data/spec/unit/axiom/sql/generator/relation/binary/visit_axiom_algebra_join_spec.rb +20 -20
- data/spec/unit/axiom/sql/generator/relation/binary/visit_axiom_algebra_product_spec.rb +26 -26
- data/spec/unit/axiom/sql/generator/relation/class_methods/visit_spec.rb +10 -10
- data/spec/unit/axiom/sql/generator/relation/insertion/to_subquery_spec.rb +2 -2
- data/spec/unit/axiom/sql/generator/relation/insertion/visit_axiom_relation_operation_insertion_spec.rb +23 -23
- data/spec/unit/axiom/sql/generator/relation/materialized/visit_axiom_relation_materialized_spec.rb +3 -3
- data/spec/unit/axiom/sql/generator/relation/materialized/visited_spec.rb +2 -2
- data/spec/unit/axiom/sql/generator/relation/set/class_methods/normalize_operand_headers_spec.rb +5 -5
- data/spec/unit/axiom/sql/generator/relation/set/to_s_spec.rb +7 -7
- data/spec/unit/axiom/sql/generator/relation/set/to_subquery_spec.rb +7 -7
- data/spec/unit/axiom/sql/generator/relation/set/visit_axiom_algebra_difference_spec.rb +19 -19
- data/spec/unit/axiom/sql/generator/relation/set/visit_axiom_algebra_intersection_spec.rb +19 -19
- data/spec/unit/axiom/sql/generator/relation/set/visit_axiom_algebra_union_spec.rb +19 -19
- data/spec/unit/axiom/sql/generator/relation/to_s_spec.rb +9 -9
- data/spec/unit/axiom/sql/generator/relation/to_sql_spec.rb +8 -8
- data/spec/unit/axiom/sql/generator/relation/to_subquery_spec.rb +9 -9
- data/spec/unit/axiom/sql/generator/relation/unary/to_s_spec.rb +9 -9
- data/spec/unit/axiom/sql/generator/relation/unary/to_subquery_spec.rb +11 -11
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_extension_spec.rb +17 -17
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_projection_spec.rb +23 -23
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_rename_spec.rb +19 -19
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_restriction_spec.rb +22 -22
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_summarization_spec.rb +48 -48
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_base_spec.rb +8 -8
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_limit_spec.rb +24 -24
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_offset_spec.rb +24 -24
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_reverse_spec.rb +26 -26
- data/spec/unit/axiom/sql/generator/relation/unary/{visit_axiom_relation_operation_order_spec.rb → visit_axiom_relation_operation_sorted_spec.rb} +28 -28
- data/spec/unit/axiom/sql/generator/relation/visit_spec.rb +3 -3
- data/spec/unit/axiom/sql/generator/relation/visited_spec.rb +7 -7
- data/spec/unit/axiom/sql/generator/visitor/visit_spec.rb +2 -2
- metadata +22 -41
- data/.rvmrc +0 -1
|
@@ -5,15 +5,15 @@ require 'spec_helper'
|
|
|
5
5
|
describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_rename' do
|
|
6
6
|
subject { object.visit_axiom_algebra_rename(rename) }
|
|
7
7
|
|
|
8
|
-
let(:relation_name) { 'users'
|
|
9
|
-
let(:id) { Attribute::Integer.new(:id)
|
|
10
|
-
let(:name) { Attribute::String.new(:name)
|
|
11
|
-
let(:age) { Attribute::Integer.new(:age, :
|
|
12
|
-
let(:header) { [
|
|
13
|
-
let(:body) { [
|
|
14
|
-
let(:base_relation) { Relation::Base.new(relation_name, header, body)
|
|
15
|
-
let(:rename) { operand.rename(:
|
|
16
|
-
let(:object) { described_class.new
|
|
8
|
+
let(:relation_name) { 'users' }
|
|
9
|
+
let(:id) { Attribute::Integer.new(:id) }
|
|
10
|
+
let(:name) { Attribute::String.new(:name) }
|
|
11
|
+
let(:age) { Attribute::Integer.new(:age, required: false) }
|
|
12
|
+
let(:header) { [id, name, age] }
|
|
13
|
+
let(:body) { [[1, 'Dan Kubb', 35]].each }
|
|
14
|
+
let(:base_relation) { Relation::Base.new(relation_name, header, body) }
|
|
15
|
+
let(:rename) { operand.rename(id: :user_id) }
|
|
16
|
+
let(:object) { described_class.new }
|
|
17
17
|
|
|
18
18
|
context 'when the operand is a base relation' do
|
|
19
19
|
let(:operand) { base_relation }
|
|
@@ -25,7 +25,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_rename' do
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
context 'when the operand is a projection' do
|
|
28
|
-
let(:operand) { base_relation.project([
|
|
28
|
+
let(:operand) { base_relation.project([:id, :name]) }
|
|
29
29
|
|
|
30
30
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
31
31
|
|
|
@@ -43,7 +43,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_rename' do
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
context 'when the operand is a rename' do
|
|
46
|
-
let(:operand) { base_relation.rename(:
|
|
46
|
+
let(:operand) { base_relation.rename(name: :other_name) }
|
|
47
47
|
|
|
48
48
|
context 'when the relation is not optimized' do
|
|
49
49
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
@@ -75,7 +75,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_rename' do
|
|
|
75
75
|
context 'summarize per table dee' do
|
|
76
76
|
let(:summarize_per) { TABLE_DEE }
|
|
77
77
|
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
|
78
|
-
let(:rename) { operand.rename(:
|
|
78
|
+
let(:rename) { operand.rename(count: :other_count) }
|
|
79
79
|
|
|
80
80
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
81
81
|
|
|
@@ -86,7 +86,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_rename' do
|
|
|
86
86
|
context 'summarize per table dum' do
|
|
87
87
|
let(:summarize_per) { TABLE_DUM }
|
|
88
88
|
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
|
89
|
-
let(:rename) { operand.rename(:
|
|
89
|
+
let(:rename) { operand.rename(count: :other_count) }
|
|
90
90
|
|
|
91
91
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
92
92
|
|
|
@@ -95,7 +95,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_rename' do
|
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
context 'summarize by a subset of the operand header' do
|
|
98
|
-
let(:operand) { base_relation.summarize([
|
|
98
|
+
let(:operand) { base_relation.summarize([:id, :name]) { |r| r.add(:count, r.age.count) } }
|
|
99
99
|
|
|
100
100
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
101
101
|
|
|
@@ -104,8 +104,8 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_rename' do
|
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
-
context 'when the operand is
|
|
108
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
107
|
+
context 'when the operand is sorted' do
|
|
108
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] } }
|
|
109
109
|
|
|
110
110
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
111
111
|
|
|
@@ -114,7 +114,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_rename' do
|
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
context 'when the operand is reversed' do
|
|
117
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
117
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.reverse }
|
|
118
118
|
|
|
119
119
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
120
120
|
|
|
@@ -123,7 +123,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_rename' do
|
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
context 'when the operand is limited' do
|
|
126
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
126
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1) }
|
|
127
127
|
|
|
128
128
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
129
129
|
|
|
@@ -132,7 +132,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_rename' do
|
|
|
132
132
|
end
|
|
133
133
|
|
|
134
134
|
context 'when the operand is an offset' do
|
|
135
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
135
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1) }
|
|
136
136
|
|
|
137
137
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
138
138
|
|
|
@@ -5,15 +5,15 @@ require 'spec_helper'
|
|
|
5
5
|
describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_restriction' do
|
|
6
6
|
subject { object.visit_axiom_algebra_restriction(restriction) }
|
|
7
7
|
|
|
8
|
-
let(:relation_name) { 'users'
|
|
9
|
-
let(:id) { Attribute::Integer.new(:id)
|
|
10
|
-
let(:name) { Attribute::String.new(:name)
|
|
11
|
-
let(:age) { Attribute::Integer.new(:age, :
|
|
12
|
-
let(:header) { [
|
|
13
|
-
let(:body) { [
|
|
14
|
-
let(:base_relation) { Relation::Base.new(relation_name, header, body)
|
|
15
|
-
let(:restriction) { operand.restrict { |r| r.id.eq(1) }
|
|
16
|
-
let(:object) { described_class.new
|
|
8
|
+
let(:relation_name) { 'users' }
|
|
9
|
+
let(:id) { Attribute::Integer.new(:id) }
|
|
10
|
+
let(:name) { Attribute::String.new(:name) }
|
|
11
|
+
let(:age) { Attribute::Integer.new(:age, required: false) }
|
|
12
|
+
let(:header) { [id, name, age] }
|
|
13
|
+
let(:body) { [[1, 'Dan Kubb', 35]].each }
|
|
14
|
+
let(:base_relation) { Relation::Base.new(relation_name, header, body) }
|
|
15
|
+
let(:restriction) { operand.restrict { |r| r.id.eq(1) } }
|
|
16
|
+
let(:object) { described_class.new }
|
|
17
17
|
|
|
18
18
|
context 'when the operand is a base relation' do
|
|
19
19
|
let(:operand) { base_relation }
|
|
@@ -25,7 +25,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_restriction' do
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
context 'when the operand is a projection' do
|
|
28
|
-
let(:operand) { base_relation.project([
|
|
28
|
+
let(:operand) { base_relation.project([:id, :name]) }
|
|
29
29
|
|
|
30
30
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
31
31
|
|
|
@@ -43,7 +43,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_restriction' do
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
context 'when the operand is a projection then a restriction' do
|
|
46
|
-
let(:operand) { base_relation.project([
|
|
46
|
+
let(:operand) { base_relation.project([:id, :name]).restrict { |r| r.id.ne(2) } }
|
|
47
47
|
|
|
48
48
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
49
49
|
|
|
@@ -52,8 +52,8 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_restriction' do
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
context 'when the operand is a projection then a restriction, followed by another restriction' do
|
|
55
|
-
let(:tautology) { Function::Proposition::Tautology.instance
|
|
56
|
-
let(:operand) { base_relation.project([
|
|
55
|
+
let(:tautology) { Function::Proposition::Tautology.instance }
|
|
56
|
+
let(:operand) { base_relation.project([:id, :name]).restrict { tautology }.restrict { tautology } }
|
|
57
57
|
|
|
58
58
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
59
59
|
|
|
@@ -63,7 +63,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_restriction' do
|
|
|
63
63
|
|
|
64
64
|
context 'when the operand is a rename' do
|
|
65
65
|
context 'when the restriction includes the renamed column' do
|
|
66
|
-
let(:operand) { base_relation.rename(:
|
|
66
|
+
let(:operand) { base_relation.rename(id: :user_id) }
|
|
67
67
|
let(:restriction) { operand.restrict { |r| r.user_id.eq(1) } }
|
|
68
68
|
|
|
69
69
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
@@ -73,8 +73,8 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_restriction' do
|
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
context 'when the restriction does not include the renamed column' do
|
|
76
|
-
let(:operand) { base_relation.rename(:
|
|
77
|
-
let(:restriction) { operand.restrict { |r| r.id.eq(1) }
|
|
76
|
+
let(:operand) { base_relation.rename(name: :other_name) }
|
|
77
|
+
let(:restriction) { operand.restrict { |r| r.id.eq(1) } }
|
|
78
78
|
|
|
79
79
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
80
80
|
|
|
@@ -116,7 +116,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_restriction' do
|
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
context 'summarize by a subset of the operand header' do
|
|
119
|
-
let(:operand) { base_relation.summarize([
|
|
119
|
+
let(:operand) { base_relation.summarize([:id, :name]) { |r| r.add(:count, r.age.count) } }
|
|
120
120
|
|
|
121
121
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
122
122
|
|
|
@@ -125,8 +125,8 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_restriction' do
|
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
127
|
|
|
128
|
-
context 'when the operand is
|
|
129
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
128
|
+
context 'when the operand is sorted' do
|
|
129
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] } }
|
|
130
130
|
|
|
131
131
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
132
132
|
|
|
@@ -135,7 +135,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_restriction' do
|
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
context 'when the operand is reversed' do
|
|
138
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
138
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.reverse }
|
|
139
139
|
|
|
140
140
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
141
141
|
|
|
@@ -144,7 +144,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_restriction' do
|
|
|
144
144
|
end
|
|
145
145
|
|
|
146
146
|
context 'when the operand is limited' do
|
|
147
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
147
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1) }
|
|
148
148
|
|
|
149
149
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
150
150
|
|
|
@@ -153,7 +153,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_restriction' do
|
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
context 'when the operand is an offset' do
|
|
156
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
156
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1) }
|
|
157
157
|
|
|
158
158
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
159
159
|
|
|
@@ -5,15 +5,15 @@ require 'spec_helper'
|
|
|
5
5
|
describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' do
|
|
6
6
|
subject { object.visit_axiom_algebra_summarization(summarization) }
|
|
7
7
|
|
|
8
|
-
let(:relation_name) { 'users'
|
|
9
|
-
let(:id) { Attribute::Integer.new(:id)
|
|
10
|
-
let(:name) { Attribute::String.new(:name)
|
|
11
|
-
let(:age) { Attribute::Integer.new(:age, :
|
|
12
|
-
let(:header) { [
|
|
13
|
-
let(:body) { [
|
|
14
|
-
let(:base_relation) { Relation::Base.new(relation_name, header, body)
|
|
15
|
-
let(:other_relation) { Relation::Base.new('other', [
|
|
16
|
-
let(:object) { described_class.new
|
|
8
|
+
let(:relation_name) { 'users' }
|
|
9
|
+
let(:id) { Attribute::Integer.new(:id) }
|
|
10
|
+
let(:name) { Attribute::String.new(:name) }
|
|
11
|
+
let(:age) { Attribute::Integer.new(:age, required: false) }
|
|
12
|
+
let(:header) { [id, name, age] }
|
|
13
|
+
let(:body) { [[1, 'Dan Kubb', 35]].each }
|
|
14
|
+
let(:base_relation) { Relation::Base.new(relation_name, header, body) }
|
|
15
|
+
let(:other_relation) { Relation::Base.new('other', [id], [[1]]) }
|
|
16
|
+
let(:object) { described_class.new }
|
|
17
17
|
|
|
18
18
|
context 'summarize per table dee' do
|
|
19
19
|
let(:summarize_per) { TABLE_DEE }
|
|
@@ -38,7 +38,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
context 'when the operand is a projection' do
|
|
41
|
-
let(:operand) { base_relation.project([
|
|
41
|
+
let(:operand) { base_relation.project([:id, :name]) }
|
|
42
42
|
let(:summarization) { operand.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
|
43
43
|
|
|
44
44
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
@@ -48,7 +48,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
context 'when the operand is a rename' do
|
|
51
|
-
let(:operand) { base_relation.rename(:
|
|
51
|
+
let(:operand) { base_relation.rename(name: :other_name) }
|
|
52
52
|
|
|
53
53
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
54
54
|
|
|
@@ -66,7 +66,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
context 'when the operand is a summarization' do
|
|
69
|
-
let(:operand) { base_relation.summarize([
|
|
69
|
+
let(:operand) { base_relation.summarize([:id]) { |r| r.add(:count, r.age.count) } }
|
|
70
70
|
let(:summarization) { operand.summarize(summarize_per) { |r| r.add(:count, r.count.count) } }
|
|
71
71
|
|
|
72
72
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
@@ -75,8 +75,8 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
75
75
|
its(:to_subquery) { should eql('(SELECT COUNT ("count") AS "count" FROM (SELECT "id", COUNT ("age") AS "count" FROM "users" GROUP BY "id" HAVING COUNT (*) > 0) AS "users")') }
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
context 'when the operand is
|
|
79
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
78
|
+
context 'when the operand is sorted' do
|
|
79
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] } }
|
|
80
80
|
|
|
81
81
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
82
82
|
|
|
@@ -85,7 +85,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
context 'when the operand is reversed' do
|
|
88
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
88
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.reverse }
|
|
89
89
|
|
|
90
90
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
91
91
|
|
|
@@ -94,7 +94,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
context 'when the operand is limited' do
|
|
97
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
97
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1) }
|
|
98
98
|
|
|
99
99
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
100
100
|
|
|
@@ -103,7 +103,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
context 'when the operand is an offset' do
|
|
106
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
106
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1) }
|
|
107
107
|
|
|
108
108
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
109
109
|
|
|
@@ -171,7 +171,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
context 'when the operand is a projection' do
|
|
174
|
-
let(:operand) { base_relation.project([
|
|
174
|
+
let(:operand) { base_relation.project([:id, :name]) }
|
|
175
175
|
let(:summarization) { operand.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
|
176
176
|
|
|
177
177
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
@@ -181,7 +181,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
context 'when the operand is a rename' do
|
|
184
|
-
let(:operand) { base_relation.rename(:
|
|
184
|
+
let(:operand) { base_relation.rename(name: :other_name) }
|
|
185
185
|
|
|
186
186
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
187
187
|
|
|
@@ -199,7 +199,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
199
199
|
end
|
|
200
200
|
|
|
201
201
|
context 'when the operand is a summarization' do
|
|
202
|
-
let(:operand) { base_relation.summarize([
|
|
202
|
+
let(:operand) { base_relation.summarize([:id]) { |r| r.add(:count, r.age.count) } }
|
|
203
203
|
let(:summarization) { operand.summarize(summarize_per) { |r| r.add(:count, r.count.count) } }
|
|
204
204
|
|
|
205
205
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
@@ -208,8 +208,8 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
208
208
|
its(:to_subquery) { should eql('(SELECT COUNT ("count") AS "count" FROM (SELECT "id", COUNT ("age") AS "count" FROM "users" GROUP BY "id" HAVING COUNT (*) > 0) AS "users" HAVING FALSE)') }
|
|
209
209
|
end
|
|
210
210
|
|
|
211
|
-
context 'when the operand is
|
|
212
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
211
|
+
context 'when the operand is sorted' do
|
|
212
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] } }
|
|
213
213
|
|
|
214
214
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
215
215
|
|
|
@@ -218,7 +218,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
218
218
|
end
|
|
219
219
|
|
|
220
220
|
context 'when the operand is reversed' do
|
|
221
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
221
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.reverse }
|
|
222
222
|
|
|
223
223
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
224
224
|
|
|
@@ -227,7 +227,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
227
227
|
end
|
|
228
228
|
|
|
229
229
|
context 'when the operand is limited' do
|
|
230
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
230
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1) }
|
|
231
231
|
|
|
232
232
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
233
233
|
|
|
@@ -236,7 +236,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
236
236
|
end
|
|
237
237
|
|
|
238
238
|
context 'when the operand is an offset' do
|
|
239
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
239
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1) }
|
|
240
240
|
|
|
241
241
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
242
242
|
|
|
@@ -282,7 +282,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
282
282
|
end
|
|
283
283
|
|
|
284
284
|
context 'summarize by a subset of the operand header' do
|
|
285
|
-
let(:summarize_by) { [
|
|
285
|
+
let(:summarize_by) { [:id] }
|
|
286
286
|
let(:summarization) { operand.summarize(summarize_by) { |r| r.add(:count, r.age.count) } }
|
|
287
287
|
|
|
288
288
|
context 'when the operand is a base relation' do
|
|
@@ -295,7 +295,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
295
295
|
end
|
|
296
296
|
|
|
297
297
|
context 'when the operand is a projection' do
|
|
298
|
-
let(:operand) { base_relation.project([
|
|
298
|
+
let(:operand) { base_relation.project([:id, :name]) }
|
|
299
299
|
let(:summarization) { operand.summarize(summarize_by) { |r| r.add(:count, r.name.count) } }
|
|
300
300
|
|
|
301
301
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
@@ -314,7 +314,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
314
314
|
end
|
|
315
315
|
|
|
316
316
|
context 'when the operand is a rename' do
|
|
317
|
-
let(:operand) { base_relation.rename(:
|
|
317
|
+
let(:operand) { base_relation.rename(name: :other_name) }
|
|
318
318
|
|
|
319
319
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
320
320
|
|
|
@@ -331,8 +331,8 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
331
331
|
its(:to_subquery) { should eql('(SELECT "id", COUNT ("age") AS "count" FROM (SELECT * FROM "users" WHERE "id" = 1) AS "users" GROUP BY "id" HAVING COUNT (*) > 0)') }
|
|
332
332
|
end
|
|
333
333
|
|
|
334
|
-
context 'when the operand is
|
|
335
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
334
|
+
context 'when the operand is sorted' do
|
|
335
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] } }
|
|
336
336
|
|
|
337
337
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
338
338
|
|
|
@@ -341,7 +341,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
341
341
|
end
|
|
342
342
|
|
|
343
343
|
context 'when the operand is reversed' do
|
|
344
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
344
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.reverse }
|
|
345
345
|
|
|
346
346
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
347
347
|
|
|
@@ -350,7 +350,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
350
350
|
end
|
|
351
351
|
|
|
352
352
|
context 'when the operand is limited' do
|
|
353
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
353
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1) }
|
|
354
354
|
|
|
355
355
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
356
356
|
|
|
@@ -359,7 +359,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
359
359
|
end
|
|
360
360
|
|
|
361
361
|
context 'when the operand is an offset' do
|
|
362
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
362
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1) }
|
|
363
363
|
|
|
364
364
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
365
365
|
|
|
@@ -418,7 +418,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
418
418
|
end
|
|
419
419
|
|
|
420
420
|
context 'when the operand is a projection' do
|
|
421
|
-
let(:operand) { base_relation.project([
|
|
421
|
+
let(:operand) { base_relation.project([:id, :name]) }
|
|
422
422
|
let(:summarization) { operand.summarize(summarize_per) { |r| r.add(:count, r.name.count) } }
|
|
423
423
|
|
|
424
424
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
@@ -437,7 +437,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
437
437
|
end
|
|
438
438
|
|
|
439
439
|
context 'when the operand is a rename' do
|
|
440
|
-
let(:operand) { base_relation.rename(:
|
|
440
|
+
let(:operand) { base_relation.rename(name: :other_name) }
|
|
441
441
|
|
|
442
442
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
443
443
|
|
|
@@ -454,8 +454,8 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
454
454
|
its(:to_subquery) { should eql('(SELECT "id", COUNT ("age") AS "count" FROM "other" AS "other" NATURAL LEFT JOIN (SELECT * FROM "users" WHERE "id" = 1) AS "users" GROUP BY "id")') }
|
|
455
455
|
end
|
|
456
456
|
|
|
457
|
-
context 'when the operand is
|
|
458
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
457
|
+
context 'when the operand is sorted' do
|
|
458
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] } }
|
|
459
459
|
|
|
460
460
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
461
461
|
|
|
@@ -464,7 +464,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
464
464
|
end
|
|
465
465
|
|
|
466
466
|
context 'when the operand is reversed' do
|
|
467
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
467
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.reverse }
|
|
468
468
|
|
|
469
469
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
470
470
|
|
|
@@ -473,7 +473,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
473
473
|
end
|
|
474
474
|
|
|
475
475
|
context 'when the operand is limited' do
|
|
476
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
476
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1) }
|
|
477
477
|
|
|
478
478
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
479
479
|
|
|
@@ -482,7 +482,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
482
482
|
end
|
|
483
483
|
|
|
484
484
|
context 'when the operand is an offset' do
|
|
485
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
485
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1) }
|
|
486
486
|
|
|
487
487
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
488
488
|
|
|
@@ -528,7 +528,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
528
528
|
end
|
|
529
529
|
|
|
530
530
|
context 'summarize per another projected relation' do
|
|
531
|
-
let(:summarize_per) { other_relation.project([
|
|
531
|
+
let(:summarize_per) { other_relation.project([:id]) }
|
|
532
532
|
let(:summarization) { operand.summarize(summarize_per) { |r| r.add(:count, r.age.count) } }
|
|
533
533
|
|
|
534
534
|
context 'when the operand is a base relation' do
|
|
@@ -541,7 +541,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
541
541
|
end
|
|
542
542
|
|
|
543
543
|
context 'when the operand is a projection' do
|
|
544
|
-
let(:operand) { base_relation.project([
|
|
544
|
+
let(:operand) { base_relation.project([:id, :name]) }
|
|
545
545
|
let(:summarization) { operand.summarize(summarize_per) { |r| r.add(:count, r.name.count) } }
|
|
546
546
|
|
|
547
547
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
@@ -560,7 +560,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
560
560
|
end
|
|
561
561
|
|
|
562
562
|
context 'when the operand is a rename' do
|
|
563
|
-
let(:operand) { base_relation.rename(:
|
|
563
|
+
let(:operand) { base_relation.rename(name: :other_name) }
|
|
564
564
|
|
|
565
565
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
566
566
|
|
|
@@ -577,8 +577,8 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
577
577
|
its(:to_subquery) { should eql('(SELECT "id", COUNT ("age") AS "count" FROM (SELECT DISTINCT "id" FROM "other") AS "other" NATURAL LEFT JOIN (SELECT * FROM "users" WHERE "id" = 1) AS "users" GROUP BY "id")') }
|
|
578
578
|
end
|
|
579
579
|
|
|
580
|
-
context 'when the operand is
|
|
581
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
580
|
+
context 'when the operand is sorted' do
|
|
581
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] } }
|
|
582
582
|
|
|
583
583
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
584
584
|
|
|
@@ -587,7 +587,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
587
587
|
end
|
|
588
588
|
|
|
589
589
|
context 'when the operand is reversed' do
|
|
590
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
590
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.reverse }
|
|
591
591
|
|
|
592
592
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
593
593
|
|
|
@@ -596,7 +596,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
596
596
|
end
|
|
597
597
|
|
|
598
598
|
context 'when the operand is limited' do
|
|
599
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
599
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1) }
|
|
600
600
|
|
|
601
601
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
602
602
|
|
|
@@ -605,7 +605,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_summarization' d
|
|
|
605
605
|
end
|
|
606
606
|
|
|
607
607
|
context 'when the operand is an offset' do
|
|
608
|
-
let(:operand) { base_relation.sort_by { |r| [
|
|
608
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1) }
|
|
609
609
|
|
|
610
610
|
it_should_behave_like 'a generated SQL SELECT query'
|
|
611
611
|
|