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,13 +5,13 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation, '.visit' do
|
6
6
|
subject { object.visit(relation) }
|
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
|
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 }
|
15
15
|
|
16
16
|
context 'when the relation is an insertion operation' do
|
17
17
|
let(:relation) { base_relation.insert(base_relation) }
|
@@ -34,7 +34,7 @@ describe SQL::Generator::Relation, '.visit' do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'when the relation is a binary operation' do
|
37
|
-
let(:relation) { base_relation.join(base_relation.project([
|
37
|
+
let(:relation) { base_relation.join(base_relation.project([:id])) }
|
38
38
|
|
39
39
|
it { should be_kind_of(SQL::Generator::Relation::Binary) }
|
40
40
|
|
@@ -44,7 +44,7 @@ describe SQL::Generator::Relation, '.visit' do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'when the relation is a unary operation' do
|
47
|
-
let(:relation) { base_relation.project([
|
47
|
+
let(:relation) { base_relation.project([:id]) }
|
48
48
|
|
49
49
|
it { should be_kind_of(SQL::Generator::Relation::Unary) }
|
50
50
|
|
@@ -64,7 +64,7 @@ describe SQL::Generator::Relation, '.visit' do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
context 'when the relation is invalid' do
|
67
|
-
let(:relation) {
|
67
|
+
let(:relation) { double('Invalid Relation') }
|
68
68
|
|
69
69
|
specify { expect { subject }.to raise_error(SQL::Generator::InvalidRelationError, "#{relation.class} is not a visitable relation") }
|
70
70
|
end
|
@@ -8,8 +8,8 @@ describe SQL::Generator::Relation::Insertion, '#to_subquery' do
|
|
8
8
|
let(:object) { described_class.new }
|
9
9
|
|
10
10
|
it 'delegates to #to_s' do
|
11
|
-
sql =
|
12
|
-
object.
|
11
|
+
sql = double('sql')
|
12
|
+
expect(object).to receive(:to_s).with(no_args).and_return(sql)
|
13
13
|
should equal(sql)
|
14
14
|
end
|
15
15
|
end
|
@@ -5,19 +5,19 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Insertion, '#visit_axiom_relation_operation_insertion' do
|
6
6
|
subject { object.visit_axiom_relation_operation_insertion(insertion) }
|
7
7
|
|
8
|
-
let(:object) { described_class.new
|
9
|
-
let(:insertion) { operand.insert(other)
|
10
|
-
let(:operand) { Relation::Base.new(relation_name, header, body)
|
11
|
-
let(:relation_name) { 'users'
|
12
|
-
let(:header) { [
|
13
|
-
let(:body) { [].each
|
14
|
-
let(:id) { Attribute::Integer.new(:id)
|
15
|
-
let(:name) { Attribute::String.new(:name)
|
16
|
-
let(:age) { Attribute::Integer.new(:age, :
|
8
|
+
let(:object) { described_class.new }
|
9
|
+
let(:insertion) { operand.insert(other) }
|
10
|
+
let(:operand) { Relation::Base.new(relation_name, header, body) }
|
11
|
+
let(:relation_name) { 'users' }
|
12
|
+
let(:header) { [id, name, age] }
|
13
|
+
let(:body) { [].each }
|
14
|
+
let(:id) { Attribute::Integer.new(:id) }
|
15
|
+
let(:name) { Attribute::String.new(:name) }
|
16
|
+
let(:age) { Attribute::Integer.new(:age, required: false) }
|
17
17
|
|
18
18
|
context 'inserting a non-empty materialized relation' do
|
19
|
-
let(:other) { operand.materialize
|
20
|
-
let(:body) { [
|
19
|
+
let(:other) { operand.materialize }
|
20
|
+
let(:body) { [[1, 'Dan Kubb', 36]].each }
|
21
21
|
|
22
22
|
it_should_behave_like 'a generated SQL expression'
|
23
23
|
|
@@ -44,8 +44,8 @@ describe SQL::Generator::Relation::Insertion, '#visit_axiom_relation_operation_i
|
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'inserting a projection' do
|
47
|
-
let(:header) { [
|
48
|
-
let(:other) { operand.project([
|
47
|
+
let(:header) { [id, name] }
|
48
|
+
let(:other) { operand.project([:id, :name]) }
|
49
49
|
|
50
50
|
it_should_behave_like 'a generated SQL SELECT query'
|
51
51
|
|
@@ -54,7 +54,7 @@ describe SQL::Generator::Relation::Insertion, '#visit_axiom_relation_operation_i
|
|
54
54
|
end
|
55
55
|
|
56
56
|
context 'inserting an extension' do
|
57
|
-
let(:other) { Relation::Base.new('other', [
|
57
|
+
let(:other) { Relation::Base.new('other', [id, name], body).extend { |r| r.add(age, 1) } }
|
58
58
|
|
59
59
|
it_should_behave_like 'a generated SQL SELECT query'
|
60
60
|
|
@@ -63,7 +63,7 @@ describe SQL::Generator::Relation::Insertion, '#visit_axiom_relation_operation_i
|
|
63
63
|
end
|
64
64
|
|
65
65
|
context 'inserting a rename' do
|
66
|
-
let(:other) { Relation::Base.new('other', [
|
66
|
+
let(:other) { Relation::Base.new('other', [[:other_id, Integer], name, age], body).rename(other_id: :id) }
|
67
67
|
|
68
68
|
it_should_behave_like 'a generated SQL SELECT query'
|
69
69
|
|
@@ -83,7 +83,7 @@ describe SQL::Generator::Relation::Insertion, '#visit_axiom_relation_operation_i
|
|
83
83
|
context 'inserting a summarization' do
|
84
84
|
context 'summarize per table dee' do
|
85
85
|
let(:summarize_per) { TABLE_DEE }
|
86
|
-
let(:operand) { Relation::Base.new(relation_name, [
|
86
|
+
let(:operand) { Relation::Base.new(relation_name, [id], body) }
|
87
87
|
let(:other) { operand.summarize(summarize_per) { |r| r.add(id, r.id.count) } }
|
88
88
|
|
89
89
|
it_should_behave_like 'a generated SQL SELECT query'
|
@@ -94,7 +94,7 @@ describe SQL::Generator::Relation::Insertion, '#visit_axiom_relation_operation_i
|
|
94
94
|
|
95
95
|
context 'summarize per table dum' do
|
96
96
|
let(:summarize_per) { TABLE_DUM }
|
97
|
-
let(:operand) { Relation::Base.new(relation_name, [
|
97
|
+
let(:operand) { Relation::Base.new(relation_name, [id], body) }
|
98
98
|
let(:other) { operand.summarize(summarize_per) { |r| r.add(id, r.id.count) } }
|
99
99
|
|
100
100
|
it_should_behave_like 'a generated SQL SELECT query'
|
@@ -104,7 +104,7 @@ describe SQL::Generator::Relation::Insertion, '#visit_axiom_relation_operation_i
|
|
104
104
|
end
|
105
105
|
|
106
106
|
context 'summarize by a subset of the operand header' do
|
107
|
-
let(:other) { operand.summarize([
|
107
|
+
let(:other) { operand.summarize([:id, :name]) { |r| r.add(age, r.age.count) } }
|
108
108
|
|
109
109
|
it_should_behave_like 'a generated SQL SELECT query'
|
110
110
|
|
@@ -113,8 +113,8 @@ describe SQL::Generator::Relation::Insertion, '#visit_axiom_relation_operation_i
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
context 'inserting
|
117
|
-
let(:other) { operand.sort_by { |r| [
|
116
|
+
context 'inserting a sorted relation' do
|
117
|
+
let(:other) { operand.sort_by { |r| [r.id, r.name, r.age] } }
|
118
118
|
|
119
119
|
it_should_behave_like 'a generated SQL SELECT query'
|
120
120
|
|
@@ -123,7 +123,7 @@ describe SQL::Generator::Relation::Insertion, '#visit_axiom_relation_operation_i
|
|
123
123
|
end
|
124
124
|
|
125
125
|
context 'inserting a reverse' do
|
126
|
-
let(:other) { operand.sort_by { |r| [
|
126
|
+
let(:other) { operand.sort_by { |r| [r.id, r.name, r.age] }.reverse }
|
127
127
|
|
128
128
|
it_should_behave_like 'a generated SQL SELECT query'
|
129
129
|
|
@@ -132,7 +132,7 @@ describe SQL::Generator::Relation::Insertion, '#visit_axiom_relation_operation_i
|
|
132
132
|
end
|
133
133
|
|
134
134
|
context 'inserting a limit' do
|
135
|
-
let(:other) { operand.sort_by { |r| [
|
135
|
+
let(:other) { operand.sort_by { |r| [r.id, r.name, r.age] }.take(1) }
|
136
136
|
|
137
137
|
it_should_behave_like 'a generated SQL SELECT query'
|
138
138
|
|
@@ -141,7 +141,7 @@ describe SQL::Generator::Relation::Insertion, '#visit_axiom_relation_operation_i
|
|
141
141
|
end
|
142
142
|
|
143
143
|
context 'inserting an offset' do
|
144
|
-
let(:other) { operand.sort_by { |r| [
|
144
|
+
let(:other) { operand.sort_by { |r| [r.id, r.name, r.age] }.drop(1) }
|
145
145
|
|
146
146
|
it_should_behave_like 'a generated SQL SELECT query'
|
147
147
|
|
data/spec/unit/axiom/sql/generator/relation/materialized/visit_axiom_relation_materialized_spec.rb
CHANGED
@@ -5,11 +5,11 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Materialized, '#visit_axiom_relation_materialized' do
|
6
6
|
subject { object.visit_axiom_relation_materialized(relation) }
|
7
7
|
|
8
|
-
let(:object) { described_class.new
|
9
|
-
let(:header) { [
|
8
|
+
let(:object) { described_class.new }
|
9
|
+
let(:header) { [[:id, Integer], [:name, String]] }
|
10
10
|
|
11
11
|
context 'with an non-empty relation' do
|
12
|
-
let(:relation) { Relation.new(header, [
|
12
|
+
let(:relation) { Relation.new(header, [[1, 'John Doe'], [2, 'Jane Doe']]) }
|
13
13
|
|
14
14
|
it_should_behave_like 'a generated SQL expression'
|
15
15
|
|
@@ -5,8 +5,8 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Materialized, '#visited?' do
|
6
6
|
subject { object.visited? }
|
7
7
|
|
8
|
-
let(:object) { described_class.new
|
9
|
-
let(:relation) { Relation.new([
|
8
|
+
let(:object) { described_class.new }
|
9
|
+
let(:relation) { Relation.new([[:id, Integer]], [[]]) }
|
10
10
|
|
11
11
|
context 'when the relation is visited' do
|
12
12
|
before do
|
data/spec/unit/axiom/sql/generator/relation/set/class_methods/normalize_operand_headers_spec.rb
CHANGED
@@ -5,11 +5,11 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Set, '.normalize_operand_headers' do
|
6
6
|
subject { object.normalize_operand_headers(relation) }
|
7
7
|
|
8
|
-
let(:object) { described_class
|
9
|
-
let(:relation) { left.union(right)
|
10
|
-
let(:relation_name) { 'test'
|
11
|
-
let(:header) { [
|
12
|
-
let(:body) { [].each
|
8
|
+
let(:object) { described_class }
|
9
|
+
let(:relation) { left.union(right) }
|
10
|
+
let(:relation_name) { 'test' }
|
11
|
+
let(:header) { [[:id, Integer], [:name, String]] }
|
12
|
+
let(:body) { [].each }
|
13
13
|
|
14
14
|
context 'when the left and right headers are sorted in the same order' do
|
15
15
|
let(:left) { Relation::Base.new(relation_name, header, body) }
|
@@ -5,13 +5,13 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Set, '#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'
|
@@ -5,13 +5,13 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Set, '#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'
|
@@ -5,17 +5,17 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_difference' do
|
6
6
|
subject { object.visit_axiom_algebra_difference(difference) }
|
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(:difference) { left.difference(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(:difference) { left.difference(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_difference' 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_difference' 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
|
|
@@ -87,7 +87,7 @@ describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_difference' do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
context 'summarize by a subset of the operand header' do
|
90
|
-
let(:operand) { base_relation.summarize([
|
90
|
+
let(:operand) { base_relation.summarize([:id, :name]) { |r| r.add(:count, r.age.count) } }
|
91
91
|
|
92
92
|
it_should_behave_like 'a generated SQL SELECT query'
|
93
93
|
|
@@ -96,8 +96,8 @@ describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_difference' do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
context 'when the operand is
|
100
|
-
let(:operand) { base_relation.sort_by { |r| [
|
99
|
+
context 'when the operand is sorted' do
|
100
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] } }
|
101
101
|
|
102
102
|
it_should_behave_like 'a generated SQL SELECT query'
|
103
103
|
|
@@ -106,7 +106,7 @@ describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_difference' do
|
|
106
106
|
end
|
107
107
|
|
108
108
|
context 'when the operand is reversed' do
|
109
|
-
let(:operand) { base_relation.sort_by { |r| [
|
109
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.reverse }
|
110
110
|
|
111
111
|
it_should_behave_like 'a generated SQL SELECT query'
|
112
112
|
|
@@ -115,7 +115,7 @@ describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_difference' do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
context 'when the operand is limited' do
|
118
|
-
let(:operand) { base_relation.sort_by { |r| [
|
118
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.take(1) }
|
119
119
|
|
120
120
|
it_should_behave_like 'a generated SQL SELECT query'
|
121
121
|
|
@@ -124,7 +124,7 @@ describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_difference' do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
context 'when the operands are offsets' do
|
127
|
-
let(:operand) { base_relation.sort_by { |r| [
|
127
|
+
let(:operand) { base_relation.sort_by { |r| [r.id, r.name, r.age] }.drop(1) }
|
128
128
|
|
129
129
|
it_should_behave_like 'a generated SQL SELECT query'
|
130
130
|
|
@@ -5,17 +5,17 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Set, '#visit_axiom_algebra_intersection' do
|
6
6
|
subject { object.visit_axiom_algebra_intersection(intersection) }
|
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(:intersection) { left.intersect(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(:intersection) { left.intersect(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_intersection' 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_intersection' 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_intersection' 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_intersection' 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_intersection' 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_intersection' 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_intersection' 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
|
|