alf-sequel 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +10 -7
- data/Gemfile.lock +26 -14
- data/README.md +45 -3
- data/lib/alf/sequel.rb +1 -0
- data/lib/alf/sequel/cog.rb +23 -75
- data/lib/alf/sequel/compiler.rb +8 -198
- data/lib/alf/sequel/connection.rb +5 -1
- data/lib/alf/sequel/connection/connection_methods.rb +4 -2
- data/lib/alf/sequel/connection/schema_methods.rb +2 -6
- data/lib/alf/sequel/connection/update_methods.rb +1 -1
- data/lib/alf/sequel/loader.rb +1 -0
- data/lib/alf/sequel/translator.rb +198 -0
- data/lib/alf/sequel/unit_of_work/insert.rb +10 -4
- data/lib/alf/sequel/unit_of_work/update.rb +3 -3
- data/lib/alf/sequel/version.rb +1 -1
- data/spec/connection/test_heading.rb +1 -1
- data/spec/{fixtures/sap.db → sap.db} +0 -0
- data/spec/spec_helper.rb +48 -6
- data/spec/unit_of_work/delete/test_delete.rb +2 -2
- data/spec/unit_of_work/insert/test_run.rb +12 -14
- data/spec/unit_of_work/update/test_run.rb +1 -1
- data/tasks/bench.rake +40 -0
- data/tasks/test.rake +3 -3
- metadata +29 -29
- data/lib/alf/sequel/compiler/predicate.rb +0 -76
- data/spec/alf.db +0 -0
- data/spec/compiler/test_clip.rb +0 -40
- data/spec/compiler/test_compact.rb +0 -18
- data/spec/compiler/test_extend.rb +0 -16
- data/spec/compiler/test_frame.rb +0 -89
- data/spec/compiler/test_intersect.rb +0 -18
- data/spec/compiler/test_join.rb +0 -26
- data/spec/compiler/test_leaf_operand.rb +0 -24
- data/spec/compiler/test_matching.rb +0 -34
- data/spec/compiler/test_not_matching.rb +0 -34
- data/spec/compiler/test_page.rb +0 -86
- data/spec/compiler/test_predicate.rb +0 -141
- data/spec/compiler/test_project.rb +0 -64
- data/spec/compiler/test_rename.rb +0 -26
- data/spec/compiler/test_restrict.rb +0 -48
- data/spec/compiler/test_sort.rb +0 -18
- data/spec/compiler/test_union.rb +0 -18
- data/spec/compiler_helper.rb +0 -34
- data/spec/fixtures/sap.rb +0 -43
- data/tasks/fixtures.rake +0 -12
@@ -26,7 +26,7 @@ module Alf
|
|
26
26
|
|
27
27
|
context 'when predicate is not a tautology' do
|
28
28
|
let(:relvar_name){ :suppliers }
|
29
|
-
let(:predicate){ Predicate.eq(sid:
|
29
|
+
let(:predicate){ Predicate.eq(sid: "S1") }
|
30
30
|
|
31
31
|
it 'removes only targetted tuples' do
|
32
32
|
conn.dataset(relvar_name).where(status: 55).to_a.size.should eq(1)
|
data/tasks/bench.rake
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
namespace :bench do
|
2
|
+
|
3
|
+
def bench_cmd
|
4
|
+
"ALF_TEST_ENV=postgres bundle exec ruby -Ilib bench/bench_all.rb"
|
5
|
+
end
|
6
|
+
|
7
|
+
def alf_cmd(tail)
|
8
|
+
"bundle exec alf --ff=%.6f --input-reader=rash #{tail}"
|
9
|
+
end
|
10
|
+
|
11
|
+
task :run do
|
12
|
+
cmd = bench_cmd
|
13
|
+
$stderr.puts cmd
|
14
|
+
exec(cmd)
|
15
|
+
end
|
16
|
+
|
17
|
+
task :summary do
|
18
|
+
cmd = bench_cmd
|
19
|
+
cmd << " | "
|
20
|
+
cmd << alf_cmd("summarize -- category -- min 'min{ total }' max 'max{ total }' avg 'avg{ total }' stddev 'stddev{ total }'")
|
21
|
+
$stderr.puts cmd
|
22
|
+
exec(cmd)
|
23
|
+
end
|
24
|
+
|
25
|
+
task :rank do
|
26
|
+
cmd = bench_cmd
|
27
|
+
cmd << " | "
|
28
|
+
cmd << alf_cmd("summarize -- category alf -- parsing 'avg{ parsing }' compiling 'avg{ compiling }' printing 'avg{ printing }' total 'avg{ total }'")
|
29
|
+
cmd << " | "
|
30
|
+
cmd << alf_cmd("rank -- total desc -- position")
|
31
|
+
cmd << " | "
|
32
|
+
cmd << alf_cmd("project -- position category alf parsing compiling printing total")
|
33
|
+
cmd << " | "
|
34
|
+
cmd << alf_cmd("restrict -- 'position < 10'")
|
35
|
+
$stderr.puts cmd
|
36
|
+
exec(cmd)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
task :bench => :"bench:run"
|
data/tasks/test.rake
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "rspec/core/rake_task"
|
2
|
-
desc "Run tests"
|
3
|
-
RSpec::Core::RakeTask.new(:test
|
2
|
+
desc "Run unit tests"
|
3
|
+
RSpec::Core::RakeTask.new(:test) do |t|
|
4
4
|
t.pattern = "spec/**/test_*.rb"
|
5
|
-
t.rspec_opts = ["--color"]
|
5
|
+
t.rspec_opts = ["--color", "--backtrace", "-Ilib", "-Ispec"]
|
6
6
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alf-sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.
|
53
|
+
version: 0.15.0
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,23 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.15.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: alf-sql
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.15.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.15.0
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: sequel
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +82,7 @@ dependencies:
|
|
66
82
|
requirements:
|
67
83
|
- - ~>
|
68
84
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
85
|
+
version: '4.2'
|
70
86
|
type: :runtime
|
71
87
|
prerelease: false
|
72
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +90,7 @@ dependencies:
|
|
74
90
|
requirements:
|
75
91
|
- - ~>
|
76
92
|
- !ruby/object:Gem::Version
|
77
|
-
version: '
|
93
|
+
version: '4.2'
|
78
94
|
description: This project implements an Alf adapter on top of the awesome sequel toolkit.
|
79
95
|
email:
|
80
96
|
- blambeau at gmail.com
|
@@ -87,13 +103,13 @@ files:
|
|
87
103
|
- Gemfile.lock
|
88
104
|
- lib/alf/sequel/adapter.rb
|
89
105
|
- lib/alf/sequel/cog.rb
|
90
|
-
- lib/alf/sequel/compiler/predicate.rb
|
91
106
|
- lib/alf/sequel/compiler.rb
|
92
107
|
- lib/alf/sequel/connection/connection_methods.rb
|
93
108
|
- lib/alf/sequel/connection/schema_methods.rb
|
94
109
|
- lib/alf/sequel/connection/update_methods.rb
|
95
110
|
- lib/alf/sequel/connection.rb
|
96
111
|
- lib/alf/sequel/loader.rb
|
112
|
+
- lib/alf/sequel/translator.rb
|
97
113
|
- lib/alf/sequel/unit_of_work/atomic.rb
|
98
114
|
- lib/alf/sequel/unit_of_work/delete.rb
|
99
115
|
- lib/alf/sequel/unit_of_work/insert.rb
|
@@ -107,24 +123,6 @@ files:
|
|
107
123
|
- Rakefile
|
108
124
|
- README.md
|
109
125
|
- spec/adapter/test_recognize.rb
|
110
|
-
- spec/alf.db
|
111
|
-
- spec/compiler/test_clip.rb
|
112
|
-
- spec/compiler/test_compact.rb
|
113
|
-
- spec/compiler/test_extend.rb
|
114
|
-
- spec/compiler/test_frame.rb
|
115
|
-
- spec/compiler/test_intersect.rb
|
116
|
-
- spec/compiler/test_join.rb
|
117
|
-
- spec/compiler/test_leaf_operand.rb
|
118
|
-
- spec/compiler/test_matching.rb
|
119
|
-
- spec/compiler/test_not_matching.rb
|
120
|
-
- spec/compiler/test_page.rb
|
121
|
-
- spec/compiler/test_predicate.rb
|
122
|
-
- spec/compiler/test_project.rb
|
123
|
-
- spec/compiler/test_rename.rb
|
124
|
-
- spec/compiler/test_restrict.rb
|
125
|
-
- spec/compiler/test_sort.rb
|
126
|
-
- spec/compiler/test_union.rb
|
127
|
-
- spec/compiler_helper.rb
|
128
126
|
- spec/connection/test_connection_uri.rb
|
129
127
|
- spec/connection/test_delete.rb
|
130
128
|
- spec/connection/test_heading.rb
|
@@ -134,8 +132,7 @@ files:
|
|
134
132
|
- spec/connection/test_ping.rb
|
135
133
|
- spec/connection/test_relvar.rb
|
136
134
|
- spec/connection/test_update.rb
|
137
|
-
- spec/
|
138
|
-
- spec/fixtures/sap.rb
|
135
|
+
- spec/sap.db
|
139
136
|
- spec/spec_helper.rb
|
140
137
|
- spec/test_assumptions.rb
|
141
138
|
- spec/test_sequel.rb
|
@@ -143,7 +140,7 @@ files:
|
|
143
140
|
- spec/unit_of_work/delete/test_delete.rb
|
144
141
|
- spec/unit_of_work/insert/test_run.rb
|
145
142
|
- spec/unit_of_work/update/test_run.rb
|
146
|
-
- tasks/
|
143
|
+
- tasks/bench.rake
|
147
144
|
- tasks/gem.rake
|
148
145
|
- tasks/test.rake
|
149
146
|
homepage: http://github.com/blambeau/alf-sequel
|
@@ -160,13 +157,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
157
|
version: '0'
|
161
158
|
segments:
|
162
159
|
- 0
|
163
|
-
hash:
|
160
|
+
hash: -1889341604392820910
|
164
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
162
|
none: false
|
166
163
|
requirements:
|
167
164
|
- - ! '>='
|
168
165
|
- !ruby/object:Gem::Version
|
169
166
|
version: '0'
|
167
|
+
segments:
|
168
|
+
- 0
|
169
|
+
hash: -1889341604392820910
|
170
170
|
requirements: []
|
171
171
|
rubyforge_project:
|
172
172
|
rubygems_version: 1.8.25
|
@@ -1,76 +0,0 @@
|
|
1
|
-
module Alf
|
2
|
-
module Sequel
|
3
|
-
class Compiler
|
4
|
-
class Predicate < Sexpr::Processor
|
5
|
-
|
6
|
-
def call(predicate)
|
7
|
-
super(predicate.expr)
|
8
|
-
end
|
9
|
-
|
10
|
-
def on_missing(sexpr)
|
11
|
-
throw :pass
|
12
|
-
end
|
13
|
-
alias :on_native :on_missing
|
14
|
-
|
15
|
-
def on_tautology(sexpr)
|
16
|
-
::Sequel::SQL::BooleanConstant.new(true)
|
17
|
-
end
|
18
|
-
|
19
|
-
def on_contradiction(sexpr)
|
20
|
-
::Sequel::SQL::BooleanConstant.new(false)
|
21
|
-
end
|
22
|
-
|
23
|
-
def on_var_ref(sexpr)
|
24
|
-
if qualifier = options[:qualifier]
|
25
|
-
::Sequel.qualify(qualifier, sexpr.last)
|
26
|
-
else
|
27
|
-
::Sequel.expr(sexpr.last)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def on_literal(sexpr)
|
32
|
-
sexpr.last.nil? ? nil : ::Sequel.expr(sexpr.last)
|
33
|
-
end
|
34
|
-
|
35
|
-
def on_eq(sexpr)
|
36
|
-
left, right = apply(sexpr.left), apply(sexpr.right)
|
37
|
-
::Sequel.expr(left => right)
|
38
|
-
end
|
39
|
-
|
40
|
-
def on_neq(sexpr)
|
41
|
-
left, right = apply(sexpr.left), apply(sexpr.right)
|
42
|
-
~::Sequel.expr(left => right)
|
43
|
-
end
|
44
|
-
|
45
|
-
def on_dyadic_comp(sexpr)
|
46
|
-
left, right = apply(sexpr.left), apply(sexpr.right)
|
47
|
-
left.send(sexpr.operator_symbol, right)
|
48
|
-
end
|
49
|
-
alias :on_lt :on_dyadic_comp
|
50
|
-
alias :on_lte :on_dyadic_comp
|
51
|
-
alias :on_gt :on_dyadic_comp
|
52
|
-
alias :on_gte :on_dyadic_comp
|
53
|
-
|
54
|
-
def on_in(sexpr)
|
55
|
-
left = apply(sexpr.var_ref)
|
56
|
-
::Sequel.expr(left => sexpr.values)
|
57
|
-
end
|
58
|
-
|
59
|
-
def on_not(sexpr)
|
60
|
-
~apply(sexpr.last)
|
61
|
-
end
|
62
|
-
|
63
|
-
def on_and(sexpr)
|
64
|
-
body = sexpr.sexpr_body
|
65
|
-
body[1..-1].inject(apply(body.first)){|f,t| f & apply(t) }
|
66
|
-
end
|
67
|
-
|
68
|
-
def on_or(sexpr)
|
69
|
-
body = sexpr.sexpr_body
|
70
|
-
body[1..-1].inject(apply(body.first)){|f,t| f | apply(t) }
|
71
|
-
end
|
72
|
-
|
73
|
-
end # class Predicate
|
74
|
-
end # class Compiler
|
75
|
-
end # module Sequel
|
76
|
-
end # module Alf
|
data/spec/alf.db
DELETED
Binary file
|
data/spec/compiler/test_clip.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'compiler_helper'
|
2
|
-
module Alf
|
3
|
-
module Sequel
|
4
|
-
describe Compiler, "clip" do
|
5
|
-
|
6
|
-
subject{ compile(expr) }
|
7
|
-
|
8
|
-
context 'when the operand is fully compilable' do
|
9
|
-
let(:expr){ clip(suppliers, [:sid, :name]) }
|
10
|
-
|
11
|
-
specify{
|
12
|
-
subject.sql.should eq("SELECT `t1`.`sid`, `t1`.`name` FROM `suppliers` AS 't1'")
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'when the operand is fully compilable (distinct normally needed)' do
|
17
|
-
let(:expr){ clip(suppliers, [:city]) }
|
18
|
-
|
19
|
-
specify{
|
20
|
-
subject.sql.should eq("SELECT `t1`.`city` FROM `suppliers` AS 't1'")
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'when the operand is fully compilable (allbut, distinct)' do
|
25
|
-
let(:expr){ clip(suppliers, [:sid, :name, :status], :allbut => true) }
|
26
|
-
|
27
|
-
specify{
|
28
|
-
subject.sql.should eq("SELECT `t1`.`city` FROM `suppliers` AS 't1'")
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when the operand is not compilable' do
|
33
|
-
let(:expr){ clip(an_operand, [:sid, :name]) }
|
34
|
-
|
35
|
-
it{ should be_a(Engine::Cog) }
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'compiler_helper'
|
2
|
-
module Alf
|
3
|
-
module Sequel
|
4
|
-
describe Compiler, "compact" do
|
5
|
-
|
6
|
-
subject{ compile(expr) }
|
7
|
-
|
8
|
-
context 'when the operand is fully compilable' do
|
9
|
-
let(:expr){ compact(suppliers) }
|
10
|
-
|
11
|
-
specify{
|
12
|
-
subject.sql.should eq("SELECT DISTINCT * FROM `suppliers` AS 't1'")
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'compiler_helper'
|
2
|
-
module Alf
|
3
|
-
module Sequel
|
4
|
-
describe Compiler, "extend" do
|
5
|
-
|
6
|
-
subject{ compile(expr) }
|
7
|
-
|
8
|
-
context 'with a native predicate' do
|
9
|
-
let(:expr){ extend(suppliers, :big => lambda{}) }
|
10
|
-
|
11
|
-
it{ should be_a(Engine::SetAttr) }
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/spec/compiler/test_frame.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'compiler_helper'
|
2
|
-
module Alf
|
3
|
-
module Sequel
|
4
|
-
describe Compiler, "frame" do
|
5
|
-
|
6
|
-
subject{ compile(expr) }
|
7
|
-
|
8
|
-
let(:expr){
|
9
|
-
frame(operand, ordering, offset, limit)
|
10
|
-
}
|
11
|
-
|
12
|
-
context 'when fully compilable' do
|
13
|
-
let(:operand){ suppliers }
|
14
|
-
|
15
|
-
[
|
16
|
-
[ [[:name, :asc]], 0, 8, "SELECT * FROM `suppliers` AS 't1' ORDER BY `t1`.`name` ASC LIMIT 8 OFFSET 0" ],
|
17
|
-
[ [[:name, :asc]], 2, 8, "SELECT * FROM `suppliers` AS 't1' ORDER BY `t1`.`name` ASC LIMIT 8 OFFSET 2" ],
|
18
|
-
[ [[:city, :asc]], 0, 8, "SELECT * FROM `suppliers` AS 't1' ORDER BY `t1`.`city` ASC, `t1`.`sid` ASC LIMIT 8 OFFSET 0" ],
|
19
|
-
[ [[:city, :desc]], 2, 8, "SELECT * FROM `suppliers` AS 't1' ORDER BY `t1`.`city` DESC, `t1`.`sid` ASC LIMIT 8 OFFSET 2" ],
|
20
|
-
].each do |(ordering,offset,limit,expected)|
|
21
|
-
|
22
|
-
context "frame(#{ordering}, #{offset}, #{limit})" do
|
23
|
-
let(:ordering){ ordering }
|
24
|
-
let(:offset) { offset }
|
25
|
-
let(:limit) { limit }
|
26
|
-
|
27
|
-
it 'should compile as expected' do
|
28
|
-
subject.sql.should eq(expected)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end # fully compilable
|
34
|
-
|
35
|
-
context 'when immediately uncompilable yet known keys' do
|
36
|
-
let(:operand){
|
37
|
-
Algebra::Operand::Fake.new.with_keys([:sid], [:name])
|
38
|
-
}
|
39
|
-
|
40
|
-
[
|
41
|
-
[ [[:name, :asc]], 2, 8, [[:name, :asc]] ],
|
42
|
-
[ [[:city, :asc]], 2, 8, [[:city, :asc], [:sid, :asc]] ]
|
43
|
-
].each do |ordering, offset, limit, expected|
|
44
|
-
|
45
|
-
context "frame(#{ordering}, #{offset}, #{limit})" do
|
46
|
-
let(:ordering){ ordering }
|
47
|
-
let(:offset) { offset }
|
48
|
-
let(:limit) { limit }
|
49
|
-
|
50
|
-
it{ should be_a(Engine::Take) }
|
51
|
-
|
52
|
-
it 'should have sort with good ordering' do
|
53
|
-
subject.operand.should be_a(Engine::Sort)
|
54
|
-
subject.operand.ordering.should eq(Ordering.new(expected))
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'when immediately uncompilable yet unknown keys' do
|
62
|
-
let(:operand){
|
63
|
-
Algebra::Operand::Fake.new
|
64
|
-
}
|
65
|
-
|
66
|
-
[
|
67
|
-
[ [[:name, :asc]], 2, 8, [[:name, :asc]] ],
|
68
|
-
[ [[:city, :asc]], 2, 8, [[:city, :asc]] ]
|
69
|
-
].each do |ordering, offset, limit, expected|
|
70
|
-
|
71
|
-
context "frame(#{ordering}, #{offset}, #{limit})" do
|
72
|
-
let(:ordering){ ordering }
|
73
|
-
let(:offset) { offset }
|
74
|
-
let(:limit) { limit }
|
75
|
-
|
76
|
-
it{ should be_a(Engine::Take) }
|
77
|
-
|
78
|
-
it 'should have sort with good ordering' do
|
79
|
-
subject.operand.should be_a(Engine::Sort)
|
80
|
-
subject.operand.ordering.should eq(Ordering.new(expected))
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|