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
@@ -99,7 +99,7 @@ module Axiom
|
|
99
99
|
#
|
100
100
|
# @api private
|
101
101
|
def set_name
|
102
|
-
@name = [
|
102
|
+
@name = [@left.name, @right.name].uniq.join(UNDERSCORE).freeze
|
103
103
|
end
|
104
104
|
|
105
105
|
# Generates an SQL statement for base relation binary operands
|
@@ -17,21 +17,21 @@ module Axiom
|
|
17
17
|
Function::String,
|
18
18
|
Function::Numeric
|
19
19
|
|
20
|
-
inheritable_alias(:
|
20
|
+
inheritable_alias(visit_axiom_relation_operation_reverse: :visit_axiom_relation_operation_sorted)
|
21
21
|
|
22
22
|
DISTINCT = 'DISTINCT '.freeze
|
23
23
|
NO_ROWS = ' HAVING FALSE'.freeze
|
24
24
|
ANY_ROWS = ' HAVING COUNT (*) > 0'
|
25
25
|
COLLAPSIBLE = {
|
26
|
-
Algebra::Summarization
|
27
|
-
Algebra::Projection
|
28
|
-
Algebra::Extension
|
29
|
-
Algebra::Rename
|
30
|
-
Algebra::Restriction
|
31
|
-
Axiom::Relation::Operation::
|
32
|
-
Axiom::Relation::Operation::Reverse => Set[
|
33
|
-
Axiom::Relation::Operation::Offset => Set[
|
34
|
-
Axiom::Relation::Operation::Limit => Set[
|
26
|
+
Algebra::Summarization => Set[].freeze,
|
27
|
+
Algebra::Projection => Set[Algebra::Projection, Algebra::Restriction].freeze,
|
28
|
+
Algebra::Extension => Set[Algebra::Projection, Algebra::Restriction, Axiom::Relation::Operation::Sorted, Axiom::Relation::Operation::Reverse, Axiom::Relation::Operation::Offset, Axiom::Relation::Operation::Limit].freeze,
|
29
|
+
Algebra::Rename => Set[Algebra::Projection, Algebra::Restriction, Axiom::Relation::Operation::Sorted, Axiom::Relation::Operation::Reverse, Axiom::Relation::Operation::Offset, Axiom::Relation::Operation::Limit].freeze,
|
30
|
+
Algebra::Restriction => Set[Algebra::Projection, Axiom::Relation::Operation::Sorted, Axiom::Relation::Operation::Reverse].freeze,
|
31
|
+
Axiom::Relation::Operation::Sorted => Set[Algebra::Projection, Algebra::Extension, Algebra::Rename, Algebra::Restriction, Algebra::Summarization, Axiom::Relation::Operation::Sorted, Axiom::Relation::Operation::Reverse].freeze,
|
32
|
+
Axiom::Relation::Operation::Reverse => Set[Algebra::Projection, Algebra::Extension, Algebra::Rename, Algebra::Restriction, Algebra::Summarization, Axiom::Relation::Operation::Sorted, Axiom::Relation::Operation::Reverse].freeze,
|
33
|
+
Axiom::Relation::Operation::Offset => Set[Algebra::Projection, Algebra::Extension, Algebra::Rename, Algebra::Restriction, Algebra::Summarization, Axiom::Relation::Operation::Sorted, Axiom::Relation::Operation::Reverse].freeze,
|
34
|
+
Axiom::Relation::Operation::Limit => Set[Algebra::Projection, Algebra::Extension, Algebra::Rename, Algebra::Restriction, Algebra::Summarization, Axiom::Relation::Operation::Sorted, Axiom::Relation::Operation::Reverse, Axiom::Relation::Operation::Offset].freeze,
|
35
35
|
}.freeze
|
36
36
|
|
37
37
|
# Initialize a Unary relation SQL generator
|
@@ -52,7 +52,7 @@ module Axiom
|
|
52
52
|
#
|
53
53
|
# @api private
|
54
54
|
def visit_axiom_relation_base(base_relation)
|
55
|
-
@name = base_relation.name
|
55
|
+
@name = base_relation.name.to_s.freeze
|
56
56
|
@from = visit_identifier(@name)
|
57
57
|
@header = base_relation.header
|
58
58
|
@columns = columns_for(base_relation)
|
@@ -141,19 +141,19 @@ module Axiom
|
|
141
141
|
self
|
142
142
|
end
|
143
143
|
|
144
|
-
# Visit
|
144
|
+
# Visit a Sorted
|
145
145
|
#
|
146
|
-
# @param [Relation::Operation::
|
146
|
+
# @param [Relation::Operation::Sorted] sorted
|
147
147
|
#
|
148
148
|
# @return [self]
|
149
149
|
#
|
150
150
|
# @api private
|
151
|
-
def
|
152
|
-
@from = subquery_for(
|
153
|
-
@order = " ORDER BY #{order_for(
|
154
|
-
@header =
|
155
|
-
@columns ||= columns_for(
|
156
|
-
scope_query(
|
151
|
+
def visit_axiom_relation_operation_sorted(sorted)
|
152
|
+
@from = subquery_for(sorted)
|
153
|
+
@order = " ORDER BY #{order_for(sorted.directions)}"
|
154
|
+
@header = sorted.header
|
155
|
+
@columns ||= columns_for(sorted)
|
156
|
+
scope_query(sorted)
|
157
157
|
self
|
158
158
|
end
|
159
159
|
|
@@ -199,7 +199,7 @@ module Axiom
|
|
199
199
|
#
|
200
200
|
# @api private
|
201
201
|
def generate_sql(columns)
|
202
|
-
[
|
202
|
+
["SELECT #{columns} FROM #{@from}", @where, @group, @having, @order, @limit, @offset].join
|
203
203
|
end
|
204
204
|
|
205
205
|
# Return the columns to use in a query
|
@@ -26,7 +26,7 @@ module Axiom
|
|
26
26
|
#
|
27
27
|
# @api private
|
28
28
|
def self.handler_for(visitable_class)
|
29
|
-
handlers[visitable_class] or
|
29
|
+
handlers[visitable_class] or fail UnknownObject, "No handler for #{visitable_class} in #{self}"
|
30
30
|
end
|
31
31
|
|
32
32
|
# Return the handler cache that maps modules to method names
|
@@ -84,7 +84,7 @@ module Axiom
|
|
84
84
|
#
|
85
85
|
# @api public
|
86
86
|
def visit(_visitable)
|
87
|
-
|
87
|
+
fail NotImplementedError, "#{self.class}#visit must be implemented"
|
88
88
|
end
|
89
89
|
|
90
90
|
# Test if a visitable object has been visited
|
@@ -96,7 +96,7 @@ module Axiom
|
|
96
96
|
#
|
97
97
|
# @api public
|
98
98
|
def visited?
|
99
|
-
|
99
|
+
fail NotImplementedError, "#{self.class}#visited? must be implemented"
|
100
100
|
end
|
101
101
|
|
102
102
|
private
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'devtools/spec_helper'
|
4
|
-
|
5
3
|
if ENV['COVERAGE'] == 'true'
|
6
4
|
require 'simplecov'
|
7
5
|
require 'coveralls'
|
@@ -12,22 +10,25 @@ if ENV['COVERAGE'] == 'true'
|
|
12
10
|
]
|
13
11
|
|
14
12
|
SimpleCov.start do
|
15
|
-
command_name
|
16
|
-
|
17
|
-
add_filter
|
18
|
-
add_filter
|
13
|
+
command_name 'spec:unit'
|
14
|
+
|
15
|
+
add_filter 'config'
|
16
|
+
add_filter 'spec'
|
17
|
+
add_filter 'vendor'
|
18
|
+
|
19
19
|
minimum_coverage 100
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
require 'devtools/spec_helper'
|
23
24
|
require 'axiom-sql-generator'
|
24
25
|
|
25
26
|
include Axiom
|
26
27
|
|
27
|
-
|
28
|
-
Dir[File.expand_path('../{support,shared}/**/*.rb', __FILE__)].each do |file|
|
29
|
-
require file
|
30
|
-
end
|
28
|
+
Types.finalize
|
31
29
|
|
32
30
|
RSpec.configure do |config|
|
31
|
+
config.expect_with :rspec do |expect_with|
|
32
|
+
expect_with.syntax = :expect
|
33
|
+
end
|
33
34
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe SQL::Generator::Direction, '#
|
6
|
-
subject { object.
|
5
|
+
describe SQL::Generator::Direction, '#visit_axiom_relation_operation_sorted_ascending' do
|
6
|
+
subject { object.visit_axiom_relation_operation_sorted_ascending(direction) }
|
7
7
|
|
8
8
|
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Direction } }
|
9
9
|
let(:direction) { Attribute::Integer.new(:id).asc }
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe SQL::Generator::Direction, '#
|
6
|
-
subject { object.
|
5
|
+
describe SQL::Generator::Direction, '#visit_axiom_relation_operation_sorted_descending' do
|
6
|
+
subject { object.visit_axiom_relation_operation_sorted_descending(direction) }
|
7
7
|
|
8
8
|
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Direction } }
|
9
9
|
let(:direction) { Attribute::Integer.new(:id).desc }
|
@@ -30,7 +30,7 @@ describe SQL::Generator::Function::Predicate, '#visit_axiom_function_predicate_e
|
|
30
30
|
end
|
31
31
|
|
32
32
|
context 'when right operand is an Array' do
|
33
|
-
let(:exclusion) { attribute.exclude([
|
33
|
+
let(:exclusion) { attribute.exclude([1, 2]) }
|
34
34
|
|
35
35
|
it_should_behave_like 'a generated SQL expression'
|
36
36
|
|
@@ -30,7 +30,7 @@ describe SQL::Generator::Function::Predicate, '#visit_axiom_function_predicate_i
|
|
30
30
|
end
|
31
31
|
|
32
32
|
context 'when right operand is an Array' do
|
33
|
-
let(:inclusion) { attribute.include([
|
33
|
+
let(:inclusion) { attribute.include([1, 2]) }
|
34
34
|
|
35
35
|
it_should_behave_like 'a generated SQL expression'
|
36
36
|
|
@@ -9,8 +9,8 @@ describe SQL::Generator::Function::Predicate, '#visit_axiom_function_predicate_i
|
|
9
9
|
let(:object) { described_class.new }
|
10
10
|
|
11
11
|
context 'and the left attribute is optional' do
|
12
|
-
let(:attribute) { Attribute::Integer.new(:age, :
|
13
|
-
let(:inequality) { attribute.ne(1)
|
12
|
+
let(:attribute) { Attribute::Integer.new(:age, required: false) }
|
13
|
+
let(:inequality) { attribute.ne(1) }
|
14
14
|
|
15
15
|
it_should_behave_like 'a generated SQL expression'
|
16
16
|
|
@@ -18,7 +18,7 @@ describe SQL::Generator::Function::Predicate, '#visit_axiom_function_predicate_i
|
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'and the right attribute is optional' do
|
21
|
-
let(:attribute) { Attribute::Integer.new(:age, :
|
21
|
+
let(:attribute) { Attribute::Integer.new(:age, required: false) }
|
22
22
|
let(:inequality) { Function::Predicate::Inequality.new(1, attribute) }
|
23
23
|
|
24
24
|
it_should_behave_like 'a generated SQL expression'
|
@@ -6,7 +6,7 @@ describe SQL::Generator::Literal, '#visit_enumerable' do
|
|
6
6
|
subject { object.visit_enumerable(enumerable) }
|
7
7
|
|
8
8
|
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Literal } }
|
9
|
-
let(:enumerable) { [
|
9
|
+
let(:enumerable) { [1, 2].freeze }
|
10
10
|
let(:object) { described_class.new }
|
11
11
|
|
12
12
|
it_should_behave_like 'a generated SQL expression'
|
@@ -5,13 +5,13 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Binary::Base, '#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,14 +5,14 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Binary::Base, '#visit_axiom_relation_base' do
|
6
6
|
subject { object.visit_axiom_relation_base(base_relation) }
|
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(: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(:object) { described_class.new }
|
16
16
|
|
17
17
|
it_should_behave_like 'a generated SQL SELECT query'
|
18
18
|
|
@@ -5,13 +5,13 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Binary, '#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::Binary, '#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,18 +5,18 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Binary, '#visit_axiom_algebra_join' do
|
6
6
|
subject { object.visit_axiom_algebra_join(join) }
|
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', header, body)
|
16
|
-
let(:left) { operand
|
17
|
-
let(:right) { operand
|
18
|
-
let(:join) { left.join(right)
|
19
|
-
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', header, body) }
|
16
|
+
let(:left) { operand }
|
17
|
+
let(:right) { operand }
|
18
|
+
let(:join) { left.join(right) }
|
19
|
+
let(:object) { described_class.new }
|
20
20
|
|
21
21
|
context 'when the operands are base relations' do
|
22
22
|
let(:operand) { base_relation }
|
@@ -28,7 +28,7 @@ describe SQL::Generator::Relation::Binary, '#visit_axiom_algebra_join' do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'when the operands are projections' do
|
31
|
-
let(:operand) { base_relation.project([
|
31
|
+
let(:operand) { base_relation.project([:id, :name]) }
|
32
32
|
|
33
33
|
it_should_behave_like 'a generated SQL SELECT query'
|
34
34
|
|
@@ -46,7 +46,7 @@ describe SQL::Generator::Relation::Binary, '#visit_axiom_algebra_join' do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
context 'when the operands are rename' do
|
49
|
-
let(:operand) { base_relation.rename(:
|
49
|
+
let(:operand) { base_relation.rename(id: :user_id) }
|
50
50
|
|
51
51
|
it_should_behave_like 'a generated SQL SELECT query'
|
52
52
|
|
@@ -85,7 +85,7 @@ describe SQL::Generator::Relation::Binary, '#visit_axiom_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([
|
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
|
|
@@ -94,8 +94,8 @@ describe SQL::Generator::Relation::Binary, '#visit_axiom_algebra_join' do
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
context 'when the operands are
|
98
|
-
let(:operand) { base_relation.sort_by { |r| [
|
97
|
+
context 'when the operands are sorted' do
|
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_axiom_algebra_join' do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
context 'when the operands are reversed' do
|
107
|
-
let(:operand) { base_relation.sort_by { |r| [
|
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_axiom_algebra_join' do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
context 'when the operands are limited' do
|
116
|
-
let(:operand) { base_relation.sort_by { |r| [
|
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_axiom_algebra_join' do
|
|
122
122
|
end
|
123
123
|
|
124
124
|
context 'when the operands are offsets' do
|
125
|
-
let(:operand) { base_relation.sort_by { |r| [
|
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
|
|
@@ -5,17 +5,17 @@ require 'spec_helper'
|
|
5
5
|
describe SQL::Generator::Relation::Binary, '#visit_axiom_algebra_product' do
|
6
6
|
subject { object.visit_axiom_algebra_product(product) }
|
7
7
|
|
8
|
-
let(:relation_name) { 'users_other'
|
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(:other_header) { [
|
14
|
-
let(:body) { [
|
15
|
-
let(:users) { Relation::Base.new('users', header, body)
|
16
|
-
let(:other) { Relation::Base.new('other', other_header, body)
|
17
|
-
let(:product) { left.product(right)
|
18
|
-
let(:object) { described_class.new
|
8
|
+
let(:relation_name) { 'users_other' }
|
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(:other_header) { [id.rename(:other_id), name.rename(:other_name), age.rename(:other_age)] }
|
14
|
+
let(:body) { [[1, 'Dan Kubb', 35]].each }
|
15
|
+
let(:users) { Relation::Base.new('users', header, body) }
|
16
|
+
let(:other) { Relation::Base.new('other', other_header, body) }
|
17
|
+
let(:product) { left.product(right) }
|
18
|
+
let(:object) { described_class.new }
|
19
19
|
|
20
20
|
context 'when the operands are base relations' do
|
21
21
|
let(:left) { users }
|
@@ -28,8 +28,8 @@ describe SQL::Generator::Relation::Binary, '#visit_axiom_algebra_product' do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'when the operands are a projection' do
|
31
|
-
let(:left) { users.project([
|
32
|
-
let(:right) { other.project([
|
31
|
+
let(:left) { users.project([:id, :name]) }
|
32
|
+
let(:right) { other.project([:other_id, :other_name]) }
|
33
33
|
|
34
34
|
it_should_behave_like 'a generated SQL SELECT query'
|
35
35
|
|
@@ -48,8 +48,8 @@ describe SQL::Generator::Relation::Binary, '#visit_axiom_algebra_product' do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
context 'when the operand is a rename' do
|
51
|
-
let(:left) { users.rename(:
|
52
|
-
let(:right) { other.rename(:
|
51
|
+
let(:left) { users.rename(id: :user_id) }
|
52
|
+
let(:right) { other.rename(other_id: :other_user_id) }
|
53
53
|
|
54
54
|
it_should_behave_like 'a generated SQL SELECT query'
|
55
55
|
|
@@ -91,8 +91,8 @@ describe SQL::Generator::Relation::Binary, '#visit_axiom_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([
|
95
|
-
let(:right) { other.summarize([
|
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
|
|
@@ -101,9 +101,9 @@ describe SQL::Generator::Relation::Binary, '#visit_axiom_algebra_product' do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
context 'when the operand is
|
105
|
-
let(:left) { users.sort_by { |r| [
|
106
|
-
let(:right) { other.sort_by { |r| [
|
104
|
+
context 'when the operand is sorted' do
|
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_axiom_algebra_product' do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
context 'when the operand is reversed' do
|
115
|
-
let(:left) { users.sort_by { |r| [
|
116
|
-
let(:right) { other.sort_by { |r| [
|
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_axiom_algebra_product' do
|
|
122
122
|
end
|
123
123
|
|
124
124
|
context 'when the operand is limited' do
|
125
|
-
let(:left) { users.sort_by { |r| [
|
126
|
-
let(:right) { other.sort_by { |r| [
|
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_axiom_algebra_product' do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
context 'when the operand is an offset' do
|
135
|
-
let(:left) { users.sort_by { |r| [
|
136
|
-
let(:right) { other.sort_by { |r| [
|
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
|
|