aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2007-12-30 13:22:31 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2007-12-30 13:22:31 -0800
commitf9cc8bba39b1deb6b3f70cecb96beaf988054915 (patch)
treede8bc118ee34c5870f0175c05298f9ab39250617
parent960bbcb3ce4a82cf4f031d1c6682ce4c1a04474d (diff)
downloadrails-f9cc8bba39b1deb6b3f70cecb96beaf988054915.tar.gz
rails-f9cc8bba39b1deb6b3f70cecb96beaf988054915.tar.bz2
rails-f9cc8bba39b1deb6b3f70cecb96beaf988054915.zip
various
-rw-r--r--lib/sql_algebra.rb24
-rw-r--r--lib/sql_algebra/predicates/binary_predicate.rb (renamed from lib/sql_algebra/relations/predicates/binary_predicate.rb)0
-rw-r--r--lib/sql_algebra/predicates/equality_predicate.rb (renamed from lib/sql_algebra/relations/predicates/equality_predicate.rb)0
-rw-r--r--lib/sql_algebra/predicates/greater_than_or_equal_to_predicate.rb (renamed from lib/sql_algebra/relations/predicates/greater_than_or_equal_to_predicate.rb)0
-rw-r--r--lib/sql_algebra/predicates/greater_than_predicate.rb (renamed from lib/sql_algebra/relations/predicates/greater_than_predicate.rb)0
-rw-r--r--lib/sql_algebra/predicates/less_than_or_equal_to_predicate.rb (renamed from lib/sql_algebra/relations/predicates/less_than_or_equal_to_predicate.rb)0
-rw-r--r--lib/sql_algebra/predicates/less_than_predicate.rb (renamed from lib/sql_algebra/relations/predicates/less_than_predicate.rb)0
-rw-r--r--lib/sql_algebra/predicates/match_predicate.rb (renamed from lib/sql_algebra/relations/predicates/match_predicate.rb)0
-rw-r--r--lib/sql_algebra/predicates/predicate.rb (renamed from lib/sql_algebra/relations/predicates/predicate.rb)0
-rw-r--r--lib/sql_algebra/predicates/range_inclusion_predicate.rb (renamed from lib/sql_algebra/relations/predicates/range_inclusion_predicate.rb)0
-rw-r--r--lib/sql_algebra/predicates/relation_inclusion_predicate.rb (renamed from lib/sql_algebra/relations/predicates/relation_inclusion_predicate.rb)0
-rw-r--r--lib/sql_algebra/relations/order_relation.rb11
-rw-r--r--lib/sql_algebra/relations/projection_relation.rb11
-rw-r--r--lib/sql_algebra/relations/range_relation.rb11
-rw-r--r--lib/sql_algebra/relations/selection_relation.rb12
-rw-r--r--spec/predicates/binary_predicate_spec.rb6
-rw-r--r--spec/relations/order_relation_spec.rb18
-rw-r--r--spec/relations/projection_relation_spec.rb18
-rw-r--r--spec/relations/range_relation_spec.rb18
-rw-r--r--spec/relations/relation_spec.rb23
-rw-r--r--spec/relations/selection_relation_spec.rb28
21 files changed, 164 insertions, 16 deletions
diff --git a/lib/sql_algebra.rb b/lib/sql_algebra.rb
index b1816844e4..7407dc264b 100644
--- a/lib/sql_algebra.rb
+++ b/lib/sql_algebra.rb
@@ -7,17 +7,21 @@ require 'sql_algebra/relations/table_relation'
require 'sql_algebra/relations/join_operation'
require 'sql_algebra/relations/join_relation'
require 'sql_algebra/relations/attribute'
+require 'sql_algebra/relations/projection_relation'
+require 'sql_algebra/relations/selection_relation'
+require 'sql_algebra/relations/order_relation'
+require 'sql_algebra/relations/range_relation'
-require 'sql_algebra/relations/predicates/predicate'
-require 'sql_algebra/relations/predicates/binary_predicate'
-require 'sql_algebra/relations/predicates/equality_predicate'
-require 'sql_algebra/relations/predicates/less_than_predicate'
-require 'sql_algebra/relations/predicates/less_than_or_equal_to_predicate'
-require 'sql_algebra/relations/predicates/greater_than_predicate'
-require 'sql_algebra/relations/predicates/greater_than_or_equal_to_predicate'
-require 'sql_algebra/relations/predicates/range_inclusion_predicate'
-require 'sql_algebra/relations/predicates/relation_inclusion_predicate'
-require 'sql_algebra/relations/predicates/match_predicate'
+require 'sql_algebra/predicates/predicate'
+require 'sql_algebra/predicates/binary_predicate'
+require 'sql_algebra/predicates/equality_predicate'
+require 'sql_algebra/predicates/less_than_predicate'
+require 'sql_algebra/predicates/less_than_or_equal_to_predicate'
+require 'sql_algebra/predicates/greater_than_predicate'
+require 'sql_algebra/predicates/greater_than_or_equal_to_predicate'
+require 'sql_algebra/predicates/range_inclusion_predicate'
+require 'sql_algebra/predicates/relation_inclusion_predicate'
+require 'sql_algebra/predicates/match_predicate'
require 'sql_algebra/extensions/range'
diff --git a/lib/sql_algebra/relations/predicates/binary_predicate.rb b/lib/sql_algebra/predicates/binary_predicate.rb
index d7f4cb20e7..d7f4cb20e7 100644
--- a/lib/sql_algebra/relations/predicates/binary_predicate.rb
+++ b/lib/sql_algebra/predicates/binary_predicate.rb
diff --git a/lib/sql_algebra/relations/predicates/equality_predicate.rb b/lib/sql_algebra/predicates/equality_predicate.rb
index 2d206e6c12..2d206e6c12 100644
--- a/lib/sql_algebra/relations/predicates/equality_predicate.rb
+++ b/lib/sql_algebra/predicates/equality_predicate.rb
diff --git a/lib/sql_algebra/relations/predicates/greater_than_or_equal_to_predicate.rb b/lib/sql_algebra/predicates/greater_than_or_equal_to_predicate.rb
index 49127c312c..49127c312c 100644
--- a/lib/sql_algebra/relations/predicates/greater_than_or_equal_to_predicate.rb
+++ b/lib/sql_algebra/predicates/greater_than_or_equal_to_predicate.rb
diff --git a/lib/sql_algebra/relations/predicates/greater_than_predicate.rb b/lib/sql_algebra/predicates/greater_than_predicate.rb
index 03aecaed62..03aecaed62 100644
--- a/lib/sql_algebra/relations/predicates/greater_than_predicate.rb
+++ b/lib/sql_algebra/predicates/greater_than_predicate.rb
diff --git a/lib/sql_algebra/relations/predicates/less_than_or_equal_to_predicate.rb b/lib/sql_algebra/predicates/less_than_or_equal_to_predicate.rb
index fee6ea7f35..fee6ea7f35 100644
--- a/lib/sql_algebra/relations/predicates/less_than_or_equal_to_predicate.rb
+++ b/lib/sql_algebra/predicates/less_than_or_equal_to_predicate.rb
diff --git a/lib/sql_algebra/relations/predicates/less_than_predicate.rb b/lib/sql_algebra/predicates/less_than_predicate.rb
index 03cbdcf000..03cbdcf000 100644
--- a/lib/sql_algebra/relations/predicates/less_than_predicate.rb
+++ b/lib/sql_algebra/predicates/less_than_predicate.rb
diff --git a/lib/sql_algebra/relations/predicates/match_predicate.rb b/lib/sql_algebra/predicates/match_predicate.rb
index 90a13090d4..90a13090d4 100644
--- a/lib/sql_algebra/relations/predicates/match_predicate.rb
+++ b/lib/sql_algebra/predicates/match_predicate.rb
diff --git a/lib/sql_algebra/relations/predicates/predicate.rb b/lib/sql_algebra/predicates/predicate.rb
index 4c395a3fdc..4c395a3fdc 100644
--- a/lib/sql_algebra/relations/predicates/predicate.rb
+++ b/lib/sql_algebra/predicates/predicate.rb
diff --git a/lib/sql_algebra/relations/predicates/range_inclusion_predicate.rb b/lib/sql_algebra/predicates/range_inclusion_predicate.rb
index e69de29bb2..e69de29bb2 100644
--- a/lib/sql_algebra/relations/predicates/range_inclusion_predicate.rb
+++ b/lib/sql_algebra/predicates/range_inclusion_predicate.rb
diff --git a/lib/sql_algebra/relations/predicates/relation_inclusion_predicate.rb b/lib/sql_algebra/predicates/relation_inclusion_predicate.rb
index 5881a85d99..5881a85d99 100644
--- a/lib/sql_algebra/relations/predicates/relation_inclusion_predicate.rb
+++ b/lib/sql_algebra/predicates/relation_inclusion_predicate.rb
diff --git a/lib/sql_algebra/relations/order_relation.rb b/lib/sql_algebra/relations/order_relation.rb
new file mode 100644
index 0000000000..8d07c58d64
--- /dev/null
+++ b/lib/sql_algebra/relations/order_relation.rb
@@ -0,0 +1,11 @@
+class OrderRelation < Relation
+ attr_reader :relation, :attributes
+
+ def initialize(relation, *attributes)
+ @relation, @attributes = relation, attributes
+ end
+
+ def ==(other)
+ relation == other.relation and attributes.eql?(other.attributes)
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/projection_relation.rb b/lib/sql_algebra/relations/projection_relation.rb
new file mode 100644
index 0000000000..caebfc1b62
--- /dev/null
+++ b/lib/sql_algebra/relations/projection_relation.rb
@@ -0,0 +1,11 @@
+class ProjectionRelation < Relation
+ attr_reader :relation, :attributes
+
+ def initialize(relation, *attributes)
+ @relation, @attributes = relation, attributes
+ end
+
+ def ==(other)
+ relation == other.relation and attributes.eql?(other.attributes)
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/range_relation.rb b/lib/sql_algebra/relations/range_relation.rb
new file mode 100644
index 0000000000..fd7e2898fa
--- /dev/null
+++ b/lib/sql_algebra/relations/range_relation.rb
@@ -0,0 +1,11 @@
+class RangeRelation < Relation
+ attr_reader :relation, :range
+
+ def initialize(relation, range)
+ @relation, @range = relation, range
+ end
+
+ def ==(other)
+ relation == other.relation and range == other.range
+ end
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/selection_relation.rb b/lib/sql_algebra/relations/selection_relation.rb
new file mode 100644
index 0000000000..5654d8de31
--- /dev/null
+++ b/lib/sql_algebra/relations/selection_relation.rb
@@ -0,0 +1,12 @@
+class SelectionRelation < Relation
+ attr_reader :relation, :predicate
+
+ def initialize(relation, *predicates)
+ @predicate = predicates.shift
+ @relation = predicates.empty?? relation : SelectionRelation.new(relation, *predicates)
+ end
+
+ def ==(other)
+ relation == other.relation and predicate == other.predicate
+ end
+end \ No newline at end of file
diff --git a/spec/predicates/binary_predicate_spec.rb b/spec/predicates/binary_predicate_spec.rb
index 1be7dd067d..58e395b08d 100644
--- a/spec/predicates/binary_predicate_spec.rb
+++ b/spec/predicates/binary_predicate_spec.rb
@@ -8,6 +8,12 @@ describe BinaryPredicate do
@attribute2 = Attribute.new(@relation2, :attribute_name)
end
+ describe BinaryPredicate, '#initialize' do
+ it "requires that both columns come from the same relation" do
+ pending
+ end
+ end
+
describe BinaryPredicate, '==' do
before do
class ConcreteBinaryPredicate < BinaryPredicate
diff --git a/spec/relations/order_relation_spec.rb b/spec/relations/order_relation_spec.rb
new file mode 100644
index 0000000000..362544d0d1
--- /dev/null
+++ b/spec/relations/order_relation_spec.rb
@@ -0,0 +1,18 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe OrderRelation do
+ before do
+ @relation1 = TableRelation.new(:foo)
+ @relation2 = TableRelation.new(:bar)
+ @attribute1 = @relation1[:foo]
+ @attribute2 = @relation2[:bar]
+ end
+
+ describe OrderRelation, '==' do
+ it "obtains if the relation and attributes are identical" do
+ OrderRelation.new(@relation1, @attribute1, @attribute2).should == OrderRelation.new(@relation1, @attribute1, @attribute2)
+ OrderRelation.new(@relation1, @attribute1).should_not == OrderRelation.new(@relation2, @attribute1)
+ OrderRelation.new(@relation1, @attribute1, @attribute2).should_not == OrderRelation.new(@relation1, @attribute2, @attribute1)
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/relations/projection_relation_spec.rb b/spec/relations/projection_relation_spec.rb
new file mode 100644
index 0000000000..f802a2e293
--- /dev/null
+++ b/spec/relations/projection_relation_spec.rb
@@ -0,0 +1,18 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe ProjectionRelation do
+ before do
+ @relation1 = TableRelation.new(:foo)
+ @relation2 = TableRelation.new(:bar)
+ @attribute1 = @relation1[:foo]
+ @attribute2 = @relation2[:bar]
+ end
+
+ describe ProjectionRelation, '==' do
+ it "obtains if the relations and attributes are identical" do
+ ProjectionRelation.new(@relation1, @attribute1, @attribute2).should == ProjectionRelation.new(@relation1, @attribute1, @attribute2)
+ ProjectionRelation.new(@relation1, @attribute1).should_not == ProjectionRelation.new(@relation2, @attribute1)
+ ProjectionRelation.new(@relation1, @attribute1).should_not == ProjectionRelation.new(@relation1, @attribute2)
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/relations/range_relation_spec.rb b/spec/relations/range_relation_spec.rb
new file mode 100644
index 0000000000..2a1cd1d070
--- /dev/null
+++ b/spec/relations/range_relation_spec.rb
@@ -0,0 +1,18 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe RangeRelation do
+ before do
+ @relation1 = TableRelation.new(:foo)
+ @relation2 = TableRelation.new(:bar)
+ @range1 = 1..2
+ @range2 = Time.now..2.days.from_now
+ end
+
+ describe RangeRelation, '==' do
+ it "obtains if the relation and range are identical" do
+ RangeRelation.new(@relation1, @range1).should == RangeRelation.new(@relation1, @range1)
+ RangeRelation.new(@relation1, @range1).should_not == RangeRelation.new(@relation2, @range1)
+ RangeRelation.new(@relation1, @range1).should_not == RangeRelation.new(@relation1, @range2)
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/relations/relation_spec.rb b/spec/relations/relation_spec.rb
index c482eb4a01..7434bd563b 100644
--- a/spec/relations/relation_spec.rb
+++ b/spec/relations/relation_spec.rb
@@ -12,19 +12,17 @@ describe Relation do
end
end
- describe Relation, 'attributes' do
- end
-
describe Relation, '[]' do
it "manufactures a attribute" do
@relation1[:id].should be_eql(Attribute.new(@relation1, :id))
end
it "raises an error if the named attribute is not part of the relation" do
+ pending
end
end
- describe Relation, 'include?' do
+ describe Relation, '#include?' do
before do
@attribute = Attribute.new(@relation1, :id)
end
@@ -34,19 +32,32 @@ describe Relation do
end
end
- describe Relation, 'project' do
+ describe Relation, '#project' do
before do
@attribute1 = Attribute.new(@relation1, :id)
@attribute2 = Attribute.new(@relation1, :name)
end
it "only allows projecting attributes in the relation" do
+ pending
end
it "collapses identical projections" do
+ pending
+ end
+
+ it "manufactures a projected relation" do
+ @relation1.project(@attribute1, @attribute2).should == ProjectedRelation(@relation1, @attribute1, @attribute2)
end
end
- describe Relation, 'select' do
+ describe Relation, '#select' do
+ before do
+ @predicate = EqualityPredicate.new()
+ end
+
+ it "manufactures a selected relation" do
+ @relation1.select(@attribute1, @attribute2).should == SelectedRelation(@relation1, @attribute1, @attribute2)
+ end
end
end \ No newline at end of file
diff --git a/spec/relations/selection_relation_spec.rb b/spec/relations/selection_relation_spec.rb
new file mode 100644
index 0000000000..0cfd55449c
--- /dev/null
+++ b/spec/relations/selection_relation_spec.rb
@@ -0,0 +1,28 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe SelectionRelation do
+ before do
+ @relation1 = TableRelation.new(:foo)
+ @relation2 = TableRelation.new(:bar)
+ @predicate1 = EqualityPredicate.new(@relation1[:id], @relation2[:foo_id])
+ @predicate2 = LessThanPredicate.new(@relation1[:age], 2)
+ end
+
+ describe SelectionRelation, '==' do
+ it "obtains if both the predicate and the relation are identical" do
+ SelectionRelation.new(@relation1, @predicate1). \
+ should == SelectionRelation.new(@relation1, @predicate1)
+ SelectionRelation.new(@relation1, @predicate1). \
+ should_not == SelectionRelation.new(@relation2, @predicate1)
+ SelectionRelation.new(@relation1, @predicate1). \
+ should_not == SelectionRelation.new(@relation1, @predicate2)
+ end
+ end
+
+ describe SelectionRelation, '#initialize' do
+ it "manufactures nested selection relations if multiple predicates are provided" do
+ SelectionRelation.new(@relation1, @predicate1, @predicate2). \
+ should == SelectionRelation.new(SelectionRelation.new(@relation1, @predicate2), @predicate1)
+ end
+ end
+end \ No newline at end of file