veritas-sql-generator 0.0.4 → 0.0.5
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.
- data/.travis.yml +4 -2
- data/Gemfile +8 -9
- data/README.rdoc +17 -0
- data/Rakefile +2 -2
- data/TODO +0 -2
- data/lib/veritas/sql/generator/version.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- data/spec/unit/veritas/sql/generator/literal/visit_time_spec.rb +2 -2
- data/spec/unit/veritas/sql/generator/relation/binary/visit_veritas_algebra_join_spec.rb +10 -10
- data/spec/unit/veritas/sql/generator/relation/binary/visit_veritas_algebra_product_spec.rb +18 -18
- data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_difference_spec.rb +10 -10
- data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_intersection_spec.rb +10 -10
- data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_union_spec.rb +10 -10
- data/spec/unit/veritas/sql/generator/relation/unary/to_s_spec.rb +3 -3
- data/spec/unit/veritas/sql/generator/relation/unary/to_subquery_spec.rb +3 -3
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_extension_spec.rb +10 -10
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_projection_spec.rb +12 -12
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_rename_spec.rb +12 -12
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_restriction_spec.rb +17 -17
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_summarization_spec.rb +49 -49
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_limit_spec.rb +18 -18
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_offset_spec.rb +18 -18
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_order_spec.rb +21 -14
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_reverse_spec.rb +18 -18
- data/tasks/metrics/heckle.rake +1 -0
- data/veritas-sql-generator.gemspec +17 -17
- metadata +33 -33
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -2,22 +2,21 @@
|
|
2
2
|
|
3
3
|
source :rubygems
|
4
4
|
|
5
|
-
gem 'veritas', '0.0.
|
5
|
+
gem 'veritas', '~> 0.0.5', :git => 'git://github.com/dkubb/veritas.git'
|
6
6
|
|
7
7
|
group :development do
|
8
|
-
gem 'backports', '~> 2.
|
9
|
-
gem 'jeweler', '~> 1.6.
|
10
|
-
gem 'rake', '~> 0.9.
|
8
|
+
gem 'backports', '~> 2.3.0'
|
9
|
+
gem 'jeweler', '~> 1.6.4'
|
10
|
+
gem 'rake', '~> 0.9.2'
|
11
11
|
gem 'rspec', '~> 1.3.2'
|
12
|
-
gem 'yard', '~> 0.7.
|
12
|
+
gem 'yard', '~> 0.7.2'
|
13
13
|
end
|
14
14
|
|
15
15
|
group :guard do
|
16
|
-
gem '
|
17
|
-
gem 'guard', '~> 0.3.4'
|
16
|
+
gem 'guard', '~> 0.5.1'
|
18
17
|
gem 'guard-bundler', '~> 0.1.3'
|
19
18
|
gem 'guard-ego', '~> 0.0.1'
|
20
|
-
gem 'guard-rspec', '~> 0.
|
19
|
+
gem 'guard-rspec', '~> 0.4.0'
|
21
20
|
end
|
22
21
|
|
23
22
|
platform :jruby do
|
@@ -31,7 +30,7 @@ platforms :mri_18 do
|
|
31
30
|
gem 'flay', '~> 1.4.2'
|
32
31
|
gem 'flog', '~> 2.5.1'
|
33
32
|
gem 'heckle', '~> 1.4.3'
|
34
|
-
gem 'json', '~> 1.5.
|
33
|
+
gem 'json', '~> 1.5.3'
|
35
34
|
gem 'metric_fu', '~> 2.1.1'
|
36
35
|
gem 'mspec', '~> 1.5.17'
|
37
36
|
gem 'rcov', '~> 0.9.9'
|
data/README.rdoc
CHANGED
@@ -4,6 +4,23 @@ Relational algebra SQL generator
|
|
4
4
|
|
5
5
|
http://travis-ci.org/dkubb/veritas-sql-generator.png
|
6
6
|
|
7
|
+
== Usage
|
8
|
+
|
9
|
+
# visit every node in the relation AST
|
10
|
+
generator = Veritas::SQL::Generator::Relation.visit(relation)
|
11
|
+
|
12
|
+
# generate an SQL string
|
13
|
+
sql = generator.to_sql
|
14
|
+
|
15
|
+
# generate an SQL subquery string
|
16
|
+
subquery_sql = generator.to_subquery
|
17
|
+
|
18
|
+
== Description
|
19
|
+
|
20
|
+
The purpose of this gem is to produce valid SQL from a veritas[https://github.com/dkubb/veritas] relation. A relation is a representation of a query constructed using relational algebra organized into an AST. Each node in the AST corresponds to an operation defined in the algebra.
|
21
|
+
|
22
|
+
The SQL produced has been verified and tested against PostgreSQL 9.0.4. Dialects for MySQL, SQLite3, Oracle and SQL Server are planned.
|
23
|
+
|
7
24
|
== Note on Patches/Pull Requests
|
8
25
|
|
9
26
|
* If you want your code merged into the mainline, please discuss
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rake'
|
|
5
5
|
require File.expand_path('../lib/veritas/sql/generator/version', __FILE__)
|
6
6
|
|
7
7
|
begin
|
8
|
-
gem('jeweler', '~> 1.6.
|
8
|
+
gem('jeweler', '~> 1.6.2') if respond_to?(:gem, true)
|
9
9
|
require 'jeweler'
|
10
10
|
|
11
11
|
Jeweler::Tasks.new do |gem|
|
@@ -23,5 +23,5 @@ begin
|
|
23
23
|
|
24
24
|
FileList['tasks/**/*.rake'].each { |task| import task }
|
25
25
|
rescue LoadError
|
26
|
-
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.6.
|
26
|
+
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.6.2'
|
27
27
|
end
|
data/TODO
CHANGED
@@ -9,8 +9,6 @@
|
|
9
9
|
* Create Veritas::Literal::Range::Inclusive
|
10
10
|
* Create Veritas::Literal::Range::Exclusive
|
11
11
|
|
12
|
-
* Adjust reek and roodi scores down to lower thresholds
|
13
|
-
|
14
12
|
* Handle cases where an Inequality/Exclusion predicate is used (or a
|
15
13
|
Negation wrapping an Equality/Inclusion) on an *optional* attribute.
|
16
14
|
* Add "OR attribute IS NULL" to the statement to ensure cases when
|
data/spec/spec_helper.rb
CHANGED
@@ -5,9 +5,9 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Literal, '#visit_time' do
|
6
6
|
subject { object.visit_time(time) }
|
7
7
|
|
8
|
-
# Time#iso8601 is currently broken in JRuby 1.6.
|
8
|
+
# Time#iso8601 is currently broken in JRuby 1.6.2 when fractional seconds are not 0
|
9
9
|
def self.time_iso8601_broken?
|
10
|
-
RUBY_PLATFORM
|
10
|
+
RUBY_PLATFORM.include?('java') && JRUBY_VERSION <= '1.6.2' && RUBY_VERSION >= '1.9.2'
|
11
11
|
end
|
12
12
|
|
13
13
|
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Literal } }
|
@@ -55,7 +55,7 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_join' do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
context 'when the operands are restrictions' do
|
58
|
-
let(:operand) { base_relation.restrict { |r| r
|
58
|
+
let(:operand) { base_relation.restrict { |r| r.id.eq(1) } }
|
59
59
|
|
60
60
|
it_should_behave_like 'a generated SQL SELECT query'
|
61
61
|
|
@@ -65,8 +65,8 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_join' do
|
|
65
65
|
|
66
66
|
context 'when the operand is a summarization' do
|
67
67
|
context 'summarize per table dee' do
|
68
|
-
let(:summarize_per) { TABLE_DEE
|
69
|
-
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r
|
68
|
+
let(:summarize_per) { TABLE_DEE }
|
69
|
+
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
70
70
|
|
71
71
|
it_should_behave_like 'a generated SQL SELECT query'
|
72
72
|
|
@@ -75,8 +75,8 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_join' do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
context 'summarize per table dum' do
|
78
|
-
let(:summarize_per) { TABLE_DUM
|
79
|
-
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r
|
78
|
+
let(:summarize_per) { TABLE_DUM }
|
79
|
+
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
80
80
|
|
81
81
|
it_should_behave_like 'a generated SQL SELECT query'
|
82
82
|
|
@@ -85,7 +85,7 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_join' do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
context 'summarize by a subset of the operand header' do
|
88
|
-
let(:operand) { base_relation.summarize([ :id, :name ]) { |r| r.add(:count, r
|
88
|
+
let(:operand) { base_relation.summarize([ :id, :name ]) { |r| r.add(:count, r.age.count) } }
|
89
89
|
|
90
90
|
it_should_behave_like 'a generated SQL SELECT query'
|
91
91
|
|
@@ -95,7 +95,7 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_join' do
|
|
95
95
|
end
|
96
96
|
|
97
97
|
context 'when the operands are ordered' do
|
98
|
-
let(:operand) { base_relation.
|
98
|
+
let(:operand) { base_relation.sort_by { |r| [ r.id, r.name, r.age ] } }
|
99
99
|
|
100
100
|
it_should_behave_like 'a generated SQL SELECT query'
|
101
101
|
|
@@ -104,7 +104,7 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_join' do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
context 'when the operands are reversed' do
|
107
|
-
let(:operand) { base_relation.
|
107
|
+
let(:operand) { base_relation.sort_by { |r| [ r.id, r.name, r.age ] }.reverse }
|
108
108
|
|
109
109
|
it_should_behave_like 'a generated SQL SELECT query'
|
110
110
|
|
@@ -113,7 +113,7 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_join' do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
context 'when the operands are limited' do
|
116
|
-
let(:operand) { base_relation.
|
116
|
+
let(:operand) { base_relation.sort_by { |r| [ r.id, r.name, r.age ] }.take(1) }
|
117
117
|
|
118
118
|
it_should_behave_like 'a generated SQL SELECT query'
|
119
119
|
|
@@ -122,7 +122,7 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_join' do
|
|
122
122
|
end
|
123
123
|
|
124
124
|
context 'when the operands are offsets' do
|
125
|
-
let(:operand) { base_relation.
|
125
|
+
let(:operand) { base_relation.sort_by { |r| [ r.id, r.name, r.age ] }.drop(1) }
|
126
126
|
|
127
127
|
it_should_behave_like 'a generated SQL SELECT query'
|
128
128
|
|
@@ -58,8 +58,8 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_product' do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
context 'when the operand is a restriction' do
|
61
|
-
let(:left) { users.restrict { |r| r
|
62
|
-
let(:right) { other.restrict { |r| r
|
61
|
+
let(:left) { users.restrict { |r| r.id.eq(1) } }
|
62
|
+
let(:right) { other.restrict { |r| r.other_id.eq(1) } }
|
63
63
|
|
64
64
|
it_should_behave_like 'a generated SQL SELECT query'
|
65
65
|
|
@@ -69,9 +69,9 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_product' do
|
|
69
69
|
|
70
70
|
context 'when the operand is a summarization' do
|
71
71
|
context 'summarize per table dee' do
|
72
|
-
let(:summarize_per) { TABLE_DEE
|
73
|
-
let(:left) { users.summarize(summarize_per) { |r| r.add(:count, r
|
74
|
-
let(:right) { other.summarize(summarize_per) { |r| r.add(:other_count, r
|
72
|
+
let(:summarize_per) { TABLE_DEE }
|
73
|
+
let(:left) { users.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
74
|
+
let(:right) { other.summarize(summarize_per) { |r| r.add(:other_count, r.other_id.count) } }
|
75
75
|
|
76
76
|
it_should_behave_like 'a generated SQL SELECT query'
|
77
77
|
|
@@ -80,9 +80,9 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_product' do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
context 'summarize per table dum' do
|
83
|
-
let(:summarize_per) { TABLE_DUM
|
84
|
-
let(:left) { users.summarize(summarize_per) { |r| r.add(:count, r
|
85
|
-
let(:right) { other.summarize(summarize_per) { |r| r.add(:other_count, r
|
83
|
+
let(:summarize_per) { TABLE_DUM }
|
84
|
+
let(:left) { users.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
85
|
+
let(:right) { other.summarize(summarize_per) { |r| r.add(:other_count, r.other_id.count) } }
|
86
86
|
|
87
87
|
it_should_behave_like 'a generated SQL SELECT query'
|
88
88
|
|
@@ -91,8 +91,8 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_product' do
|
|
91
91
|
end
|
92
92
|
|
93
93
|
context 'summarize by a subset of the operand header' do
|
94
|
-
let(:left) { users.summarize([ :id, :name ]) { |r| r.add(:count, r
|
95
|
-
let(:right) { other.summarize([ :other_id, :other_name ]) { |r| r.add(:other_count, r
|
94
|
+
let(:left) { users.summarize([ :id, :name ]) { |r| r.add(:count, r.age.count) } }
|
95
|
+
let(:right) { other.summarize([ :other_id, :other_name ]) { |r| r.add(:other_count, r.other_age.count) } }
|
96
96
|
|
97
97
|
it_should_behave_like 'a generated SQL SELECT query'
|
98
98
|
|
@@ -102,8 +102,8 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_product' do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
context 'when the operand is ordered' do
|
105
|
-
let(:left) { users.
|
106
|
-
let(:right) { other.
|
105
|
+
let(:left) { users.sort_by { |r| [ r.id, r.name, r.age ] } }
|
106
|
+
let(:right) { other.sort_by { |r| [ r.other_id, r.other_name, r.other_age ] } }
|
107
107
|
|
108
108
|
it_should_behave_like 'a generated SQL SELECT query'
|
109
109
|
|
@@ -112,8 +112,8 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_product' do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
context 'when the operand is reversed' do
|
115
|
-
let(:left) { users.
|
116
|
-
let(:right) { other.
|
115
|
+
let(:left) { users.sort_by { |r| [ r.id, r.name, r.age ] }.reverse }
|
116
|
+
let(:right) { other.sort_by { |r| [ r.other_id, r.other_name, r.other_age ] }.reverse }
|
117
117
|
|
118
118
|
it_should_behave_like 'a generated SQL SELECT query'
|
119
119
|
|
@@ -122,8 +122,8 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_product' do
|
|
122
122
|
end
|
123
123
|
|
124
124
|
context 'when the operand is limited' do
|
125
|
-
let(:left) { users.
|
126
|
-
let(:right) { other.
|
125
|
+
let(:left) { users.sort_by { |r| [ r.id, r.name, r.age ] }.take(1) }
|
126
|
+
let(:right) { other.sort_by { |r| [ r.other_id, r.other_name, r.other_age ] }.take(1) }
|
127
127
|
|
128
128
|
it_should_behave_like 'a generated SQL SELECT query'
|
129
129
|
|
@@ -132,8 +132,8 @@ describe SQL::Generator::Relation::Binary, '#visit_veritas_algebra_product' do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
context 'when the operand is an offset' do
|
135
|
-
let(:left) { users.
|
136
|
-
let(:right) { other.
|
135
|
+
let(:left) { users.sort_by { |r| [ r.id, r.name, r.age ] }.drop(1) }
|
136
|
+
let(:right) { other.sort_by { |r| [ r.other_id, r.other_name, r.other_age ] }.drop(1) }
|
137
137
|
|
138
138
|
it_should_behave_like 'a generated SQL SELECT query'
|
139
139
|
|
@@ -54,7 +54,7 @@ describe SQL::Generator::Relation::Set, '#visit_veritas_algebra_difference' do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
context 'when the operands are restrictions' do
|
57
|
-
let(:operand) { base_relation.restrict { |r| r
|
57
|
+
let(:operand) { base_relation.restrict { |r| r.id.eq(1) } }
|
58
58
|
|
59
59
|
it_should_behave_like 'a generated SQL SELECT query'
|
60
60
|
|
@@ -67,8 +67,8 @@ describe SQL::Generator::Relation::Set, '#visit_veritas_algebra_difference' do
|
|
67
67
|
|
68
68
|
context 'when the operand is a summarization' do
|
69
69
|
context 'summarize per table dee' do
|
70
|
-
let(:summarize_per) { TABLE_DEE
|
71
|
-
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r
|
70
|
+
let(:summarize_per) { TABLE_DEE }
|
71
|
+
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
72
72
|
|
73
73
|
it_should_behave_like 'a generated SQL SELECT query'
|
74
74
|
|
@@ -77,8 +77,8 @@ describe SQL::Generator::Relation::Set, '#visit_veritas_algebra_difference' do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
context 'summarize per table dum' do
|
80
|
-
let(:summarize_per) { TABLE_DUM
|
81
|
-
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r
|
80
|
+
let(:summarize_per) { TABLE_DUM }
|
81
|
+
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
82
82
|
|
83
83
|
it_should_behave_like 'a generated SQL SELECT query'
|
84
84
|
|
@@ -87,7 +87,7 @@ describe SQL::Generator::Relation::Set, '#visit_veritas_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([ :id, :name ]) { |r| r.add(:count, r
|
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
|
|
@@ -97,7 +97,7 @@ describe SQL::Generator::Relation::Set, '#visit_veritas_algebra_difference' do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
context 'when the operand is ordered' do
|
100
|
-
let(:operand) { base_relation.
|
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_veritas_algebra_difference' do
|
|
106
106
|
end
|
107
107
|
|
108
108
|
context 'when the operand is reversed' do
|
109
|
-
let(:operand) { base_relation.
|
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_veritas_algebra_difference' do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
context 'when the operand is limited' do
|
118
|
-
let(:operand) { base_relation.
|
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_veritas_algebra_difference' do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
context 'when the operands are offsets' do
|
127
|
-
let(:operand) { base_relation.
|
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
|
|
data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_intersection_spec.rb
CHANGED
@@ -54,7 +54,7 @@ describe SQL::Generator::Relation::Set, '#visit_veritas_algebra_intersection' do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
context 'when the operands are restrictions' do
|
57
|
-
let(:operand) { base_relation.restrict { |r| r
|
57
|
+
let(:operand) { base_relation.restrict { |r| r.id.eq(1) } }
|
58
58
|
|
59
59
|
it_should_behave_like 'a generated SQL SELECT query'
|
60
60
|
|
@@ -64,8 +64,8 @@ describe SQL::Generator::Relation::Set, '#visit_veritas_algebra_intersection' do
|
|
64
64
|
|
65
65
|
context 'when the operand is a summarization' do
|
66
66
|
context 'summarize per table dee' do
|
67
|
-
let(:summarize_per) { TABLE_DEE
|
68
|
-
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r
|
67
|
+
let(:summarize_per) { TABLE_DEE }
|
68
|
+
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
69
69
|
|
70
70
|
it_should_behave_like 'a generated SQL SELECT query'
|
71
71
|
|
@@ -74,8 +74,8 @@ describe SQL::Generator::Relation::Set, '#visit_veritas_algebra_intersection' do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
context 'summarize per table dum' do
|
77
|
-
let(:summarize_per) { TABLE_DUM
|
78
|
-
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r
|
77
|
+
let(:summarize_per) { TABLE_DUM }
|
78
|
+
let(:operand) { base_relation.summarize(summarize_per) { |r| r.add(:count, r.id.count) } }
|
79
79
|
|
80
80
|
it_should_behave_like 'a generated SQL SELECT query'
|
81
81
|
|
@@ -84,7 +84,7 @@ describe SQL::Generator::Relation::Set, '#visit_veritas_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([ :id, :name ]) { |r| r.add(:count, r
|
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
|
|
@@ -94,7 +94,7 @@ describe SQL::Generator::Relation::Set, '#visit_veritas_algebra_intersection' do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
context 'when the operand is ordered' do
|
97
|
-
let(:operand) { base_relation.
|
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_veritas_algebra_intersection' do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
context 'when the operand is reversed' do
|
106
|
-
let(:operand) { base_relation.
|
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_veritas_algebra_intersection' do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
context 'when the operand is limited' do
|
115
|
-
let(:operand) { base_relation.
|
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_veritas_algebra_intersection' do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
context 'when the operands are offsets' do
|
124
|
-
let(:operand) { base_relation.
|
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
|
|