locomotive 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/locomotive.rb +6 -0
- data/lib/locomotive/core_extensions.rb +6 -0
- data/lib/locomotive/core_extensions/array.rb +22 -0
- data/lib/locomotive/core_extensions/class.rb +47 -0
- data/lib/locomotive/core_extensions/hash.rb +7 -0
- data/lib/locomotive/core_extensions/inflector.rb +29 -0
- data/lib/locomotive/core_extensions/module.rb +77 -0
- data/lib/locomotive/core_extensions/symbol.rb +17 -0
- data/lib/locomotive/misc.rb +1 -0
- data/lib/locomotive/misc/type_check.rb +129 -0
- data/lib/locomotive/relational_algebra.rb +8 -0
- data/lib/locomotive/relational_algebra/attributes.rb +171 -0
- data/lib/locomotive/relational_algebra/operators.rb +15 -0
- data/lib/locomotive/relational_algebra/operators/abstraction.rb +2 -0
- data/lib/locomotive/relational_algebra/operators/abstraction/lambda.rb +83 -0
- data/lib/locomotive/relational_algebra/operators/abstraction/variable.rb +65 -0
- data/lib/locomotive/relational_algebra/operators/aggregation.rb +2 -0
- data/lib/locomotive/relational_algebra/operators/aggregation/aggr_builtin.rb +26 -0
- data/lib/locomotive/relational_algebra/operators/aggregation/aggregation.rb +76 -0
- data/lib/locomotive/relational_algebra/operators/basic_operators.rb +144 -0
- data/lib/locomotive/relational_algebra/operators/boolean.rb +4 -0
- data/lib/locomotive/relational_algebra/operators/boolean/and.rb +9 -0
- data/lib/locomotive/relational_algebra/operators/boolean/basic_boolean.rb +66 -0
- data/lib/locomotive/relational_algebra/operators/boolean/not.rb +56 -0
- data/lib/locomotive/relational_algebra/operators/boolean/or.rb +9 -0
- data/lib/locomotive/relational_algebra/operators/builtins.rb +3 -0
- data/lib/locomotive/relational_algebra/operators/builtins/arith_builtin.rb +37 -0
- data/lib/locomotive/relational_algebra/operators/builtins/basic_builtin.rb +20 -0
- data/lib/locomotive/relational_algebra/operators/builtins/function.rb +69 -0
- data/lib/locomotive/relational_algebra/operators/comparisons.rb +6 -0
- data/lib/locomotive/relational_algebra/operators/comparisons/basic_comparison.rb +65 -0
- data/lib/locomotive/relational_algebra/operators/comparisons/equal.rb +13 -0
- data/lib/locomotive/relational_algebra/operators/comparisons/greater.rb +13 -0
- data/lib/locomotive/relational_algebra/operators/comparisons/greater_equal.rb +14 -0
- data/lib/locomotive/relational_algebra/operators/comparisons/less.rb +21 -0
- data/lib/locomotive/relational_algebra/operators/comparisons/less_equal.rb +13 -0
- data/lib/locomotive/relational_algebra/operators/error.rb +1 -0
- data/lib/locomotive/relational_algebra/operators/error/error.rb +52 -0
- data/lib/locomotive/relational_algebra/operators/filter.rb +1 -0
- data/lib/locomotive/relational_algebra/operators/filter/select.rb +50 -0
- data/lib/locomotive/relational_algebra/operators/join.rb +5 -0
- data/lib/locomotive/relational_algebra/operators/join/basic_join.rb +9 -0
- data/lib/locomotive/relational_algebra/operators/join/cross.rb +28 -0
- data/lib/locomotive/relational_algebra/operators/join/equi_join.rb +61 -0
- data/lib/locomotive/relational_algebra/operators/join/predicates.rb +95 -0
- data/lib/locomotive/relational_algebra/operators/join/theta_join.rb +53 -0
- data/lib/locomotive/relational_algebra/operators/projections.rb +2 -0
- data/lib/locomotive/relational_algebra/operators/projections/attach.rb +67 -0
- data/lib/locomotive/relational_algebra/operators/projections/projection.rb +106 -0
- data/lib/locomotive/relational_algebra/operators/ranking.rb +6 -0
- data/lib/locomotive/relational_algebra/operators/ranking/basic_ranking.rb +67 -0
- data/lib/locomotive/relational_algebra/operators/ranking/rank.rb +9 -0
- data/lib/locomotive/relational_algebra/operators/ranking/rank_lists.rb +45 -0
- data/lib/locomotive/relational_algebra/operators/ranking/row_id.rb +24 -0
- data/lib/locomotive/relational_algebra/operators/ranking/row_number.rb +55 -0
- data/lib/locomotive/relational_algebra/operators/ranking/row_rank.rb +9 -0
- data/lib/locomotive/relational_algebra/operators/serialization.rb +2 -0
- data/lib/locomotive/relational_algebra/operators/serialization/basic_serialize.rb +9 -0
- data/lib/locomotive/relational_algebra/operators/serialization/serialize_relation.rb +105 -0
- data/lib/locomotive/relational_algebra/operators/set.rb +4 -0
- data/lib/locomotive/relational_algebra/operators/set/basic_set.rb +24 -0
- data/lib/locomotive/relational_algebra/operators/set/difference.rb +11 -0
- data/lib/locomotive/relational_algebra/operators/set/distinct.rb +35 -0
- data/lib/locomotive/relational_algebra/operators/set/union.rb +11 -0
- data/lib/locomotive/relational_algebra/operators/tables.rb +3 -0
- data/lib/locomotive/relational_algebra/operators/tables/literal_table.rb +95 -0
- data/lib/locomotive/relational_algebra/operators/tables/nil.rb +13 -0
- data/lib/locomotive/relational_algebra/operators/tables/ref_table.rb +75 -0
- data/lib/locomotive/relational_algebra/operators/typeing.rb +1 -0
- data/lib/locomotive/relational_algebra/operators/typeing/cast.rb +59 -0
- data/lib/locomotive/relational_algebra/ordering.rb +30 -0
- data/lib/locomotive/relational_algebra/query_information.rb +666 -0
- data/lib/locomotive/relational_algebra/rel_alg_ast_node.rb +51 -0
- data/lib/locomotive/relational_algebra/rel_alg_exceptions.rb +15 -0
- data/lib/locomotive/relational_algebra/schema.rb +87 -0
- data/lib/locomotive/relational_algebra/types.rb +86 -0
- data/lib/locomotive/tree_helpers.rb +3 -0
- data/lib/locomotive/tree_helpers/annotations.rb +58 -0
- data/lib/locomotive/tree_helpers/ast.rb +99 -0
- data/lib/locomotive/tree_helpers/ast_traversal.rb +43 -0
- data/lib/locomotive/utils.rb +2 -0
- data/lib/locomotive/utils/relalg2xml.rb +239 -0
- data/lib/locomotive/utils/xml.rb +47 -0
- metadata +157 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
module Locomotive
|
2
|
+
|
3
|
+
module RelationalAlgebra
|
4
|
+
|
5
|
+
class Not < Unary
|
6
|
+
attr_accessor :res, :item
|
7
|
+
def_sig :res=, ConstAttribute
|
8
|
+
def_sig :item=, ConstAttribute
|
9
|
+
|
10
|
+
def initialize(op, res, item)
|
11
|
+
self.res,
|
12
|
+
self.item = res, item
|
13
|
+
super(op)
|
14
|
+
end
|
15
|
+
|
16
|
+
def child=(op)
|
17
|
+
unless op.schema.attributes?([item])
|
18
|
+
raise CorruptedSchema,
|
19
|
+
"Schema #{op.schema.attributes} does not " \
|
20
|
+
"contain all attributes of #{item1}."
|
21
|
+
end
|
22
|
+
|
23
|
+
self.schema = op.schema +
|
24
|
+
Schema.new({ res => [RBool.instance] })
|
25
|
+
|
26
|
+
super(op)
|
27
|
+
end
|
28
|
+
|
29
|
+
def xml_content
|
30
|
+
content do
|
31
|
+
[column(:name => res.to_xml, :new => true),
|
32
|
+
column(:name => item.to_xml, :new => false)].join
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def xml_kind
|
37
|
+
self.class.to_s.split('::').last.downcase.to_sym
|
38
|
+
end
|
39
|
+
|
40
|
+
def clone
|
41
|
+
Not.new(child.clone,
|
42
|
+
res.clone,
|
43
|
+
item.clone)
|
44
|
+
end
|
45
|
+
|
46
|
+
def set(var, plan)
|
47
|
+
self.class.new(
|
48
|
+
child.set(var,plan),
|
49
|
+
res.clone,
|
50
|
+
item.clone)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Locomotive
|
2
|
+
|
3
|
+
module RelationalAlgebra
|
4
|
+
|
5
|
+
class Addition < Fun
|
6
|
+
def to_xml
|
7
|
+
:add
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Subtraction < Fun
|
12
|
+
def to_xml
|
13
|
+
:subtract
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Multiplication < Fun
|
18
|
+
def to_xml
|
19
|
+
:multiply
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Division < Fun
|
24
|
+
def to_xml
|
25
|
+
:divide
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Contains < Fun
|
30
|
+
def to_xml
|
31
|
+
:contains
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Locomotive
|
2
|
+
|
3
|
+
module RelationalAlgebra
|
4
|
+
|
5
|
+
class Function < Unary;
|
6
|
+
def_node :column, :kind
|
7
|
+
|
8
|
+
attr_accessor :res,
|
9
|
+
:operator,
|
10
|
+
:items
|
11
|
+
def_sig :res=, ConstAttribute
|
12
|
+
def_sig :operator=, Fun
|
13
|
+
def_sig :items=, [ConstAttribute]
|
14
|
+
|
15
|
+
|
16
|
+
def initialize(op, operator, res, items)
|
17
|
+
self.operator,
|
18
|
+
self.res,
|
19
|
+
self.items = operator, res, items
|
20
|
+
super(op)
|
21
|
+
end
|
22
|
+
|
23
|
+
def child=(op)
|
24
|
+
unless op.schema.attributes?(self.items)
|
25
|
+
raise CorruptedSchema,
|
26
|
+
"Schema #{op.schema.attributes} does not " \
|
27
|
+
"contain all attributes of #{items}."
|
28
|
+
end
|
29
|
+
|
30
|
+
self.schema = op.schema +
|
31
|
+
Schema.new( { res => op.schema[items.first] } )
|
32
|
+
super(op)
|
33
|
+
end
|
34
|
+
|
35
|
+
def xml_kind
|
36
|
+
:fun
|
37
|
+
end
|
38
|
+
|
39
|
+
def xml_content
|
40
|
+
content do
|
41
|
+
[
|
42
|
+
kind(:name => operator.to_xml),
|
43
|
+
column(:name => res.to_xml, :new => true),
|
44
|
+
items.collect do |it|
|
45
|
+
column :name => it.to_xml, :new => false
|
46
|
+
end.join
|
47
|
+
].join
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def clone
|
52
|
+
Function.new(child.clone,
|
53
|
+
operator.clone,
|
54
|
+
res.clone,
|
55
|
+
items.clone)
|
56
|
+
end
|
57
|
+
|
58
|
+
def set(var, plan)
|
59
|
+
Function.new(
|
60
|
+
child.set(var,plan),
|
61
|
+
operator.clone,
|
62
|
+
res.clone,
|
63
|
+
items.clone)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
require 'locomotive/relational_algebra/operators/comparisons/basic_comparison'
|
2
|
+
require 'locomotive/relational_algebra/operators/comparisons/equal'
|
3
|
+
require 'locomotive/relational_algebra/operators/comparisons/greater'
|
4
|
+
require 'locomotive/relational_algebra/operators/comparisons/greater_equal'
|
5
|
+
require 'locomotive/relational_algebra/operators/comparisons/less'
|
6
|
+
require 'locomotive/relational_algebra/operators/comparisons/less_equal'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Locomotive
|
2
|
+
|
3
|
+
module RelationalAlgebra
|
4
|
+
|
5
|
+
class Comparison < Unary
|
6
|
+
def_node
|
7
|
+
attr_accessor :res,
|
8
|
+
:item1,
|
9
|
+
:item2
|
10
|
+
def_sig :res=, ConstAttribute
|
11
|
+
def_sig :item1=, ConstAttribute
|
12
|
+
def_sig :item2=, ConstAttribute
|
13
|
+
|
14
|
+
def initialize(op, res, items)
|
15
|
+
self.res,
|
16
|
+
self.item1,
|
17
|
+
self.item2 = res, items[0], items[1]
|
18
|
+
super(op)
|
19
|
+
end
|
20
|
+
|
21
|
+
def child=(op)
|
22
|
+
unless op.schema.attributes?([self.item1])
|
23
|
+
raise CorruptedSchema,
|
24
|
+
"Schema #{op.schema.attributes} does not " \
|
25
|
+
"contain all attributes of #{item1}."
|
26
|
+
end
|
27
|
+
unless op.schema.attributes?([self.item2])
|
28
|
+
raise CorruptedSchema,
|
29
|
+
"Schema #{op.schema.attributes} does not " \
|
30
|
+
"contain all attributes of #{item2}."
|
31
|
+
end
|
32
|
+
|
33
|
+
self.schema = op.schema + Schema.new({ self.res => [RBool.instance]})
|
34
|
+
super(op)
|
35
|
+
end
|
36
|
+
|
37
|
+
def clone
|
38
|
+
self.class.new(child.clone,
|
39
|
+
res.clone,
|
40
|
+
[item1.clone,
|
41
|
+
item2.clone])
|
42
|
+
end
|
43
|
+
|
44
|
+
def set(var,plan)
|
45
|
+
self.class.new(
|
46
|
+
child.set(var,plan),
|
47
|
+
res.clone,
|
48
|
+
[item1.clone,
|
49
|
+
item2.clone])
|
50
|
+
end
|
51
|
+
|
52
|
+
def xml_content
|
53
|
+
content do
|
54
|
+
[column(:name => res.to_xml, :new => true),
|
55
|
+
column(:name => item1.to_xml, :new => false, :position => 1),
|
56
|
+
column(:name => item2.to_xml, :new => false, :position => 2)
|
57
|
+
].join
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Locomotive
|
2
|
+
|
3
|
+
module RelationalAlgebra
|
4
|
+
|
5
|
+
class LessThan < Comparison
|
6
|
+
|
7
|
+
def initialize(op, res, items)
|
8
|
+
super(op, res, items)
|
9
|
+
change = self.item2
|
10
|
+
self.item2 = self.item1
|
11
|
+
self.item1 = change
|
12
|
+
end
|
13
|
+
|
14
|
+
def xml_kind
|
15
|
+
:gt
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'locomotive/relational_algebra/operators/error/error'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Locomotive
|
2
|
+
|
3
|
+
module RelationalAlgebra
|
4
|
+
|
5
|
+
class Error < Binary
|
6
|
+
attr_accessor :item
|
7
|
+
def_sig :item=, ConstAttribute
|
8
|
+
|
9
|
+
def initialize(op1, op2, item)
|
10
|
+
self.item = item
|
11
|
+
super(op1, op2)
|
12
|
+
end
|
13
|
+
|
14
|
+
def left_and_right=(op1, op2)
|
15
|
+
unless op.schema.attributes?([item])
|
16
|
+
raise CorruptedSchema,
|
17
|
+
"Schema #{op.schema.attributes} does not " \
|
18
|
+
"contain all attributes of #{item}."
|
19
|
+
end
|
20
|
+
|
21
|
+
# set the schema to its right child
|
22
|
+
self.schema = op2.schema
|
23
|
+
end
|
24
|
+
|
25
|
+
def xml_kind
|
26
|
+
:error
|
27
|
+
end
|
28
|
+
|
29
|
+
def xml_content
|
30
|
+
content do
|
31
|
+
column :name => item.to_xml, :new => false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def clone
|
36
|
+
Error.new(
|
37
|
+
left.clone, right.clone,
|
38
|
+
item.clone)
|
39
|
+
end
|
40
|
+
|
41
|
+
def set(var, plan)
|
42
|
+
Error.new(
|
43
|
+
left.set(var,plan),
|
44
|
+
right.set(var.plan),
|
45
|
+
item.clone)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'locomotive/relational_algebra/operators/filter/select'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Locomotive
|
2
|
+
|
3
|
+
module RelationalAlgebra
|
4
|
+
|
5
|
+
class Select < Unary
|
6
|
+
attr_accessor :item
|
7
|
+
|
8
|
+
def initialize(op, item)
|
9
|
+
self.item = item
|
10
|
+
super(op)
|
11
|
+
end
|
12
|
+
|
13
|
+
def child=(op)
|
14
|
+
unless op.schema.attributes?([item])
|
15
|
+
raise CorruptedSchema,
|
16
|
+
"Schema #{op.schema.attributes} does not " \
|
17
|
+
"contain all attributes of #{item}."
|
18
|
+
end
|
19
|
+
|
20
|
+
unless op.schema[item].member? RBool.instance
|
21
|
+
raise CorruptedSchema,
|
22
|
+
"#{item}(#{op.schema[item]}) doesn have the type Boolean."
|
23
|
+
end
|
24
|
+
|
25
|
+
self.schema = op.schema.clone
|
26
|
+
super(op)
|
27
|
+
end
|
28
|
+
|
29
|
+
def xml_content
|
30
|
+
content do
|
31
|
+
column :name => item.to_xml, :new => false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def clone
|
36
|
+
Select.new(
|
37
|
+
self.child.clone,
|
38
|
+
self.item.clone)
|
39
|
+
end
|
40
|
+
|
41
|
+
def set(var,plan)
|
42
|
+
Select.new(
|
43
|
+
child.set(var,plan),
|
44
|
+
item.clone)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|