axiom-sql-generator 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,17 +5,17 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_union' do
|
6
6
|
subject { object.visit_axiom_algebra_union(union) }
|
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(:left) { operand
|
16
|
-
let(:right) { operand
|
17
|
-
let(:union) { left.union(right)
|
18
|
-
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(:left) { operand }
|
16
|
+
let(:right) { operand }
|
17
|
+
let(:union) { left.union(right) }
|
18
|
+
let(:object) { described_class.new }
|
19
19
|
|
20
20
|
context 'when the operands are base relations' do
|
21
21
|
let(:operand) { base_relation }
|
@@ -27,7 +27,7 @@ describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_union' do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'when the operands are projections' do
|
30
|
-
let(:operand) { base_relation.project([
|
30
|
+
let(:operand) { base_relation.project([:id, :name]) }
|
31
31
|
|
32
32
|
it_should_behave_like 'a generated SQL SELECT query'
|
33
33
|
|
@@ -45,7 +45,7 @@ describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_union' do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
context 'when the operands are renames' do
|
48
|
-
let(:operand) { base_relation.rename(:
|
48
|
+
let(:operand) { base_relation.rename(id: :user_id) }
|
49
49
|
|
50
50
|
it_should_behave_like 'a generated SQL SELECT query'
|
51
51
|
|
@@ -84,7 +84,7 @@ describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_union' do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
context 'summarize by a subset of the operand header' do
|
87
|
-
let(:operand) { base_relation.summarize([
|
87
|
+
let(:operand) { base_relation.summarize([:id, :name]) { |r| r.add(:count, r.age.count) } }
|
88
88
|
|
89
89
|
it_should_behave_like 'a generated SQL SELECT query'
|
90
90
|
|
@@ -93,8 +93,8 @@ describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_union' do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
context 'when the operand is
|
97
|
-
let(:operand) { base_relation.sort_by { |r| [
|
96
|
+
context 'when the operand is sorted' do
|
97
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] } }
|
98
98
|
|
99
99
|
it_should_behave_like 'a generated SQL SELECT query'
|
100
100
|
|
@@ -103,7 +103,7 @@ describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_union' do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
context 'when the operand is reversed' do
|
106
|
-
let(:operand) { base_relation.sort_by { |r| [
|
106
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.reverse }
|
107
107
|
|
108
108
|
it_should_behave_like 'a generated SQL SELECT query'
|
109
109
|
|
@@ -112,7 +112,7 @@ describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_union' do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
context 'when the operand is limited' do
|
115
|
-
let(:operand) { base_relation.sort_by { |r| [
|
115
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1) }
|
116
116
|
|
117
117
|
it_should_behave_like 'a generated SQL SELECT query'
|
118
118
|
|
@@ -121,7 +121,7 @@ describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_union' do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
context 'when the operands are offsets' do
|
124
|
-
let(:operand) { base_relation.sort_by { |r| [
|
124
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1) }
|
125
125
|
|
126
126
|
it_should_behave_like 'a generated SQL SELECT query'
|
127
127
|
|
@@ -5,14 +5,14 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation, '#to_s' do
|
6
6
|
subject { object.to_s }
|
7
7
|
|
8
|
-
let(:described_class) { Class.new(SQL::Generator::Relation)
|
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('users', header, body)
|
15
|
-
let(:object) { described_class.new
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Relation) }
|
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('users', header, body) }
|
15
|
+
let(:object) { described_class.new }
|
16
16
|
|
17
17
|
context 'when no object visited' do
|
18
18
|
it_should_behave_like 'an idempotent method'
|
@@ -25,7 +25,7 @@ describe SQL::Generator::Relation, '#to_s' do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'when an object is visited' do
|
28
|
-
let(:visitable) {
|
28
|
+
let(:visitable) { double('Visitable') }
|
29
29
|
|
30
30
|
before do
|
31
31
|
described_class.class_eval do
|
@@ -5,13 +5,13 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation, '#to_sql' do
|
6
6
|
subject { object.to_sql }
|
7
7
|
|
8
|
-
let(:described_class) { Class.new(SQL::Generator::Relation)
|
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(:object) { described_class.new
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Relation) }
|
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(:object) { described_class.new }
|
15
15
|
|
16
16
|
context 'when no object visited' do
|
17
17
|
it_should_behave_like 'an idempotent method'
|
@@ -24,7 +24,7 @@ describe SQL::Generator::Relation, '#to_sql' do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'when an object is visited' do
|
27
|
-
let(:visitable) {
|
27
|
+
let(:visitable) { double('Visitable') }
|
28
28
|
|
29
29
|
before do
|
30
30
|
described_class.class_eval do
|
@@ -5,14 +5,14 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation, '#to_subquery' do
|
6
6
|
subject { object.to_subquery }
|
7
7
|
|
8
|
-
let(:described_class) { Class.new(SQL::Generator::Relation)
|
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('users', header, body)
|
15
|
-
let(:object) { described_class.new
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Relation) }
|
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('users', header, body) }
|
15
|
+
let(:object) { described_class.new }
|
16
16
|
|
17
17
|
context 'when no object visited' do
|
18
18
|
it_should_behave_like 'an idempotent method'
|
@@ -25,7 +25,7 @@ describe SQL::Generator::Relation, '#to_subquery' do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'when an object is visited' do
|
28
|
-
let(:visitable) {
|
28
|
+
let(:visitable) { double('Visitable') }
|
29
29
|
|
30
30
|
before do
|
31
31
|
described_class.class_eval do
|
@@ -5,13 +5,13 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Unary, '#to_s' do
|
6
6
|
subject { object.to_s }
|
7
7
|
|
8
|
-
let(:id) { Attribute::Integer.new(:id)
|
9
|
-
let(:name) { Attribute::String.new(:name)
|
10
|
-
let(:age) { Attribute::Integer.new(:age, :
|
11
|
-
let(:header) { [
|
12
|
-
let(:body) { [
|
13
|
-
let(:base_relation) { Relation::Base.new('users', header, body)
|
14
|
-
let(:object) { described_class.new
|
8
|
+
let(:id) { Attribute::Integer.new(:id) }
|
9
|
+
let(:name) { Attribute::String.new(:name) }
|
10
|
+
let(:age) { Attribute::Integer.new(:age, required: false) }
|
11
|
+
let(:header) { [id, name, age] }
|
12
|
+
let(:body) { [[1, 'Dan Kubb', 35]].each }
|
13
|
+
let(:base_relation) { Relation::Base.new('users', header, body) }
|
14
|
+
let(:object) { described_class.new }
|
15
15
|
|
16
16
|
context 'when no object visited' do
|
17
17
|
it_should_behave_like 'an idempotent method'
|
@@ -35,7 +35,7 @@ describe SQL::Generator::Relation::Unary, '#to_s' do
|
|
35
35
|
|
36
36
|
context 'when a limit is visited' do
|
37
37
|
before do
|
38
|
-
object.visit(base_relation.sort_by { |r| [
|
38
|
+
object.visit(base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1))
|
39
39
|
end
|
40
40
|
|
41
41
|
it_should_behave_like 'a generated SQL expression'
|
@@ -45,7 +45,7 @@ describe SQL::Generator::Relation::Unary, '#to_s' do
|
|
45
45
|
|
46
46
|
context 'when an offset is visited' do
|
47
47
|
before do
|
48
|
-
object.visit(base_relation.sort_by { |r| [
|
48
|
+
object.visit(base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1))
|
49
49
|
end
|
50
50
|
|
51
51
|
it_should_behave_like 'a generated SQL expression'
|
@@ -5,13 +5,13 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Unary, '#to_subquery' do
|
6
6
|
subject { object.to_subquery }
|
7
7
|
|
8
|
-
let(:id) { Attribute::Integer.new(:id)
|
9
|
-
let(:name) { Attribute::String.new(:name)
|
10
|
-
let(:age) { Attribute::Integer.new(:age, :
|
11
|
-
let(:header) { [
|
12
|
-
let(:body) { [
|
13
|
-
let(:base_relation) { Relation::Base.new('users', header, body)
|
14
|
-
let(:object) { described_class.new
|
8
|
+
let(:id) { Attribute::Integer.new(:id) }
|
9
|
+
let(:name) { Attribute::String.new(:name) }
|
10
|
+
let(:age) { Attribute::Integer.new(:age, required: false) }
|
11
|
+
let(:header) { [id, name, age] }
|
12
|
+
let(:body) { [[1, 'Dan Kubb', 35]].each }
|
13
|
+
let(:base_relation) { Relation::Base.new('users', header, body) }
|
14
|
+
let(:object) { described_class.new }
|
15
15
|
|
16
16
|
context 'when no object visited' do
|
17
17
|
it_should_behave_like 'an idempotent method'
|
@@ -25,7 +25,7 @@ describe SQL::Generator::Relation::Unary, '#to_subquery' do
|
|
25
25
|
|
26
26
|
context 'when a projection is visited' do
|
27
27
|
before do
|
28
|
-
object.visit(base_relation.project([
|
28
|
+
object.visit(base_relation.project([:id, :name]))
|
29
29
|
end
|
30
30
|
|
31
31
|
it_should_behave_like 'a generated SQL expression'
|
@@ -35,7 +35,7 @@ describe SQL::Generator::Relation::Unary, '#to_subquery' do
|
|
35
35
|
|
36
36
|
context 'when a rename is visited' do
|
37
37
|
before do
|
38
|
-
object.visit(base_relation.rename(:
|
38
|
+
object.visit(base_relation.rename(id: :user_id))
|
39
39
|
end
|
40
40
|
|
41
41
|
it_should_behave_like 'a generated SQL expression'
|
@@ -55,7 +55,7 @@ describe SQL::Generator::Relation::Unary, '#to_subquery' do
|
|
55
55
|
|
56
56
|
context 'when a limit is visited' do
|
57
57
|
before do
|
58
|
-
object.visit(base_relation.sort_by { |r| [
|
58
|
+
object.visit(base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1))
|
59
59
|
end
|
60
60
|
|
61
61
|
it_should_behave_like 'a generated SQL expression'
|
@@ -65,7 +65,7 @@ describe SQL::Generator::Relation::Unary, '#to_subquery' do
|
|
65
65
|
|
66
66
|
context 'when an offset is visited' do
|
67
67
|
before do
|
68
|
-
object.visit(base_relation.sort_by { |r| [
|
68
|
+
object.visit(base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1))
|
69
69
|
end
|
70
70
|
|
71
71
|
it_should_behave_like 'a generated SQL expression'
|
@@ -5,15 +5,15 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_extension' do
|
6
6
|
subject { object.visit_axiom_algebra_extension(extension) }
|
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(:extension) { operand.extend { |r| r.add(:one, 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(:extension) { operand.extend { |r| r.add(:one, 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_extension' 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_extension' 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(id: :user_id) }
|
47
47
|
|
48
48
|
it_should_behave_like 'a generated SQL SELECT query'
|
49
49
|
|
@@ -82,7 +82,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_extension' do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
context 'summarize by a subset of the operand header' do
|
85
|
-
let(:operand) { base_relation.summarize([
|
85
|
+
let(:operand) { base_relation.summarize([:id, :name]) { |r| r.add(:count, r.age.count) } }
|
86
86
|
|
87
87
|
it_should_behave_like 'a generated SQL SELECT query'
|
88
88
|
|
@@ -91,8 +91,8 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_extension' do
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
context 'when the operand is
|
95
|
-
let(:operand) { base_relation.sort_by { |r| [
|
94
|
+
context 'when the operand is sorted' do
|
95
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] } }
|
96
96
|
|
97
97
|
it_should_behave_like 'a generated SQL SELECT query'
|
98
98
|
|
@@ -101,7 +101,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_extension' do
|
|
101
101
|
end
|
102
102
|
|
103
103
|
context 'when the operand is reversed' do
|
104
|
-
let(:operand) { base_relation.sort_by { |r| [
|
104
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.reverse }
|
105
105
|
|
106
106
|
it_should_behave_like 'a generated SQL SELECT query'
|
107
107
|
|
@@ -110,7 +110,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_extension' do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
context 'when the operand is limited' do
|
113
|
-
let(:operand) { base_relation.sort_by { |r| [
|
113
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1) }
|
114
114
|
|
115
115
|
it_should_behave_like 'a generated SQL SELECT query'
|
116
116
|
|
@@ -119,7 +119,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_extension' do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
context 'when the operand is an offset' do
|
122
|
-
let(:operand) { base_relation.sort_by { |r| [
|
122
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1) }
|
123
123
|
|
124
124
|
it_should_behave_like 'a generated SQL SELECT query'
|
125
125
|
|
@@ -5,15 +5,15 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_projection' do
|
6
6
|
subject { object.visit_axiom_algebra_projection(projection) }
|
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(:projection) { operand.project([
|
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(:projection) { operand.project([:id, :name]) }
|
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_projection' 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
|
|
@@ -37,7 +37,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_projection' do
|
|
37
37
|
let(:operand) { base_relation.extend { |r| r.add(:one, 1) } }
|
38
38
|
|
39
39
|
context 'when the projection includes the extended column' do
|
40
|
-
let(:projection) { operand.project([
|
40
|
+
let(:projection) { operand.project([:id, :name, :one]) }
|
41
41
|
|
42
42
|
it_should_behave_like 'a generated SQL SELECT query'
|
43
43
|
|
@@ -46,7 +46,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_projection' do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
context 'when the projection does not include the extended column' do
|
49
|
-
let(:projection) { operand.project([
|
49
|
+
let(:projection) { operand.project([:id, :name]) }
|
50
50
|
|
51
51
|
it_should_behave_like 'a generated SQL SELECT query'
|
52
52
|
|
@@ -56,10 +56,10 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_projection' do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
context 'when the operand is a rename' do
|
59
|
-
let(:operand) { base_relation.rename(:
|
59
|
+
let(:operand) { base_relation.rename(id: :user_id) }
|
60
60
|
|
61
61
|
context 'when the projection includes the renamed column' do
|
62
|
-
let(:projection) { operand.project([
|
62
|
+
let(:projection) { operand.project([:user_id, :name]) }
|
63
63
|
|
64
64
|
it_should_behave_like 'a generated SQL SELECT query'
|
65
65
|
|
@@ -68,7 +68,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_projection' do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
context 'when the projection does not include the renamed column' do
|
71
|
-
let(:projection) { operand.project([
|
71
|
+
let(:projection) { operand.project([:name, :age]) }
|
72
72
|
|
73
73
|
it_should_behave_like 'a generated SQL SELECT query'
|
74
74
|
|
@@ -90,7 +90,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_projection' do
|
|
90
90
|
context 'summarize per table dee' do
|
91
91
|
let(:summarize_per) { TABLE_DEE }
|
92
92
|
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
93
|
-
let(:projection) { operand.project([
|
93
|
+
let(:projection) { operand.project([:count]) }
|
94
94
|
|
95
95
|
it_should_behave_like 'a generated SQL SELECT query'
|
96
96
|
|
@@ -101,7 +101,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_projection' do
|
|
101
101
|
context 'summarize per table dum' do
|
102
102
|
let(:summarize_per) { TABLE_DUM }
|
103
103
|
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
104
|
-
let(:projection) { operand.project([
|
104
|
+
let(:projection) { operand.project([:count]) }
|
105
105
|
|
106
106
|
it_should_behave_like 'a generated SQL SELECT query'
|
107
107
|
|
@@ -110,7 +110,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_projection' do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
context 'summarize by a subset of the operand header' do
|
113
|
-
let(:operand) { base_relation.summarize([
|
113
|
+
let(:operand) { base_relation.summarize([:id, :name]) { |r| r.add(:count, r.age.count) } }
|
114
114
|
|
115
115
|
it_should_behave_like 'a generated SQL SELECT query'
|
116
116
|
|
@@ -119,8 +119,8 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_projection' do
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
context 'when the operand is
|
123
|
-
let(:operand) { base_relation.sort_by { |r| [
|
122
|
+
context 'when the operand is sorted' do
|
123
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] } }
|
124
124
|
|
125
125
|
it_should_behave_like 'a generated SQL SELECT query'
|
126
126
|
|
@@ -129,7 +129,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_projection' do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
context 'when the operand is reversed' do
|
132
|
-
let(:operand) { base_relation.sort_by { |r| [
|
132
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.reverse }
|
133
133
|
|
134
134
|
it_should_behave_like 'a generated SQL SELECT query'
|
135
135
|
|
@@ -138,7 +138,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_projection' do
|
|
138
138
|
end
|
139
139
|
|
140
140
|
context 'when the operand is limited' do
|
141
|
-
let(:operand) { base_relation.sort_by { |r| [
|
141
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1) }
|
142
142
|
|
143
143
|
it_should_behave_like 'a generated SQL SELECT query'
|
144
144
|
|
@@ -147,7 +147,7 @@ describe SQL::Generator::Relation::Unary, '#visit_axiom_algebra_projection' do
|
|
147
147
|
end
|
148
148
|
|
149
149
|
context 'when the operand is an offset' do
|
150
|
-
let(:operand) { base_relation.sort_by { |r| [
|
150
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1) }
|
151
151
|
|
152
152
|
it_should_behave_like 'a generated SQL SELECT query'
|
153
153
|
|