From f9cc8bba39b1deb6b3f70cecb96beaf988054915 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Sun, 30 Dec 2007 13:22:31 -0800 Subject: various --- lib/sql_algebra/predicates/binary_predicate.rb | 12 ++++++++++++ lib/sql_algebra/predicates/equality_predicate.rb | 7 +++++++ .../predicates/greater_than_or_equal_to_predicate.rb | 2 ++ lib/sql_algebra/predicates/greater_than_predicate.rb | 2 ++ .../predicates/less_than_or_equal_to_predicate.rb | 2 ++ lib/sql_algebra/predicates/less_than_predicate.rb | 2 ++ lib/sql_algebra/predicates/match_predicate.rb | 7 +++++++ lib/sql_algebra/predicates/predicate.rb | 5 +++++ lib/sql_algebra/predicates/range_inclusion_predicate.rb | 0 lib/sql_algebra/predicates/relation_inclusion_predicate.rb | 11 +++++++++++ lib/sql_algebra/relations/order_relation.rb | 11 +++++++++++ lib/sql_algebra/relations/predicates/binary_predicate.rb | 12 ------------ lib/sql_algebra/relations/predicates/equality_predicate.rb | 7 ------- .../predicates/greater_than_or_equal_to_predicate.rb | 2 -- .../relations/predicates/greater_than_predicate.rb | 2 -- .../relations/predicates/less_than_or_equal_to_predicate.rb | 2 -- lib/sql_algebra/relations/predicates/less_than_predicate.rb | 2 -- lib/sql_algebra/relations/predicates/match_predicate.rb | 7 ------- lib/sql_algebra/relations/predicates/predicate.rb | 5 ----- .../relations/predicates/range_inclusion_predicate.rb | 0 .../relations/predicates/relation_inclusion_predicate.rb | 11 ----------- lib/sql_algebra/relations/projection_relation.rb | 11 +++++++++++ lib/sql_algebra/relations/range_relation.rb | 11 +++++++++++ lib/sql_algebra/relations/selection_relation.rb | 12 ++++++++++++ 24 files changed, 95 insertions(+), 50 deletions(-) create mode 100644 lib/sql_algebra/predicates/binary_predicate.rb create mode 100644 lib/sql_algebra/predicates/equality_predicate.rb create mode 100644 lib/sql_algebra/predicates/greater_than_or_equal_to_predicate.rb create mode 100644 lib/sql_algebra/predicates/greater_than_predicate.rb create mode 100644 lib/sql_algebra/predicates/less_than_or_equal_to_predicate.rb create mode 100644 lib/sql_algebra/predicates/less_than_predicate.rb create mode 100644 lib/sql_algebra/predicates/match_predicate.rb create mode 100644 lib/sql_algebra/predicates/predicate.rb create mode 100644 lib/sql_algebra/predicates/range_inclusion_predicate.rb create mode 100644 lib/sql_algebra/predicates/relation_inclusion_predicate.rb create mode 100644 lib/sql_algebra/relations/order_relation.rb delete mode 100644 lib/sql_algebra/relations/predicates/binary_predicate.rb delete mode 100644 lib/sql_algebra/relations/predicates/equality_predicate.rb delete mode 100644 lib/sql_algebra/relations/predicates/greater_than_or_equal_to_predicate.rb delete mode 100644 lib/sql_algebra/relations/predicates/greater_than_predicate.rb delete mode 100644 lib/sql_algebra/relations/predicates/less_than_or_equal_to_predicate.rb delete mode 100644 lib/sql_algebra/relations/predicates/less_than_predicate.rb delete mode 100644 lib/sql_algebra/relations/predicates/match_predicate.rb delete mode 100644 lib/sql_algebra/relations/predicates/predicate.rb delete mode 100644 lib/sql_algebra/relations/predicates/range_inclusion_predicate.rb delete mode 100644 lib/sql_algebra/relations/predicates/relation_inclusion_predicate.rb create mode 100644 lib/sql_algebra/relations/projection_relation.rb create mode 100644 lib/sql_algebra/relations/range_relation.rb create mode 100644 lib/sql_algebra/relations/selection_relation.rb (limited to 'lib/sql_algebra') diff --git a/lib/sql_algebra/predicates/binary_predicate.rb b/lib/sql_algebra/predicates/binary_predicate.rb new file mode 100644 index 0000000000..d7f4cb20e7 --- /dev/null +++ b/lib/sql_algebra/predicates/binary_predicate.rb @@ -0,0 +1,12 @@ +class BinaryPredicate < Predicate + attr_reader :attribute1, :attribute2 + + def initialize(attribute1, attribute2) + @attribute1, @attribute2 = attribute1, attribute2 + end + + def ==(other) + super and + (attribute1.eql?(other.attribute1) and attribute2.eql?(other.attribute2)) + end +end \ No newline at end of file diff --git a/lib/sql_algebra/predicates/equality_predicate.rb b/lib/sql_algebra/predicates/equality_predicate.rb new file mode 100644 index 0000000000..2d206e6c12 --- /dev/null +++ b/lib/sql_algebra/predicates/equality_predicate.rb @@ -0,0 +1,7 @@ +class EqualityPredicate < BinaryPredicate + def ==(other) + self.class == other.class and + ((attribute1.eql?(other.attribute1) and attribute2.eql?(other.attribute2)) or + (attribute1.eql?(other.attribute2) and attribute2.eql?(other.attribute1))) + end +end \ No newline at end of file diff --git a/lib/sql_algebra/predicates/greater_than_or_equal_to_predicate.rb b/lib/sql_algebra/predicates/greater_than_or_equal_to_predicate.rb new file mode 100644 index 0000000000..49127c312c --- /dev/null +++ b/lib/sql_algebra/predicates/greater_than_or_equal_to_predicate.rb @@ -0,0 +1,2 @@ +class GreaterThanOrEqualToPredicate < BinaryPredicate +end \ No newline at end of file diff --git a/lib/sql_algebra/predicates/greater_than_predicate.rb b/lib/sql_algebra/predicates/greater_than_predicate.rb new file mode 100644 index 0000000000..03aecaed62 --- /dev/null +++ b/lib/sql_algebra/predicates/greater_than_predicate.rb @@ -0,0 +1,2 @@ +class GreaterThanPredicate < BinaryPredicate +end \ No newline at end of file diff --git a/lib/sql_algebra/predicates/less_than_or_equal_to_predicate.rb b/lib/sql_algebra/predicates/less_than_or_equal_to_predicate.rb new file mode 100644 index 0000000000..fee6ea7f35 --- /dev/null +++ b/lib/sql_algebra/predicates/less_than_or_equal_to_predicate.rb @@ -0,0 +1,2 @@ +class LessThanOrEqualToPredicate < BinaryPredicate +end \ No newline at end of file diff --git a/lib/sql_algebra/predicates/less_than_predicate.rb b/lib/sql_algebra/predicates/less_than_predicate.rb new file mode 100644 index 0000000000..03cbdcf000 --- /dev/null +++ b/lib/sql_algebra/predicates/less_than_predicate.rb @@ -0,0 +1,2 @@ +class LessThanPredicate < BinaryPredicate +end \ No newline at end of file diff --git a/lib/sql_algebra/predicates/match_predicate.rb b/lib/sql_algebra/predicates/match_predicate.rb new file mode 100644 index 0000000000..90a13090d4 --- /dev/null +++ b/lib/sql_algebra/predicates/match_predicate.rb @@ -0,0 +1,7 @@ +class MatchPredicate < Predicate + attr_reader :attribute, :regexp + + def initialize(attribute, regexp) + @attribute, @regexp = attribute, regexp + end +end \ No newline at end of file diff --git a/lib/sql_algebra/predicates/predicate.rb b/lib/sql_algebra/predicates/predicate.rb new file mode 100644 index 0000000000..4c395a3fdc --- /dev/null +++ b/lib/sql_algebra/predicates/predicate.rb @@ -0,0 +1,5 @@ +class Predicate + def ==(other) + self.class == other.class + end +end \ No newline at end of file diff --git a/lib/sql_algebra/predicates/range_inclusion_predicate.rb b/lib/sql_algebra/predicates/range_inclusion_predicate.rb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/sql_algebra/predicates/relation_inclusion_predicate.rb b/lib/sql_algebra/predicates/relation_inclusion_predicate.rb new file mode 100644 index 0000000000..5881a85d99 --- /dev/null +++ b/lib/sql_algebra/predicates/relation_inclusion_predicate.rb @@ -0,0 +1,11 @@ +class RelationInclusionPredicate < Predicate + attr_reader :attribute, :relation + + def initialize(attribute, relation) + @attribute, @relation = attribute, relation + end + + def ==(other) + super and attribute == other.attribute and relation == other.relation + end +end \ No newline at end of file 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/predicates/binary_predicate.rb b/lib/sql_algebra/relations/predicates/binary_predicate.rb deleted file mode 100644 index d7f4cb20e7..0000000000 --- a/lib/sql_algebra/relations/predicates/binary_predicate.rb +++ /dev/null @@ -1,12 +0,0 @@ -class BinaryPredicate < Predicate - attr_reader :attribute1, :attribute2 - - def initialize(attribute1, attribute2) - @attribute1, @attribute2 = attribute1, attribute2 - end - - def ==(other) - super and - (attribute1.eql?(other.attribute1) and attribute2.eql?(other.attribute2)) - end -end \ No newline at end of file diff --git a/lib/sql_algebra/relations/predicates/equality_predicate.rb b/lib/sql_algebra/relations/predicates/equality_predicate.rb deleted file mode 100644 index 2d206e6c12..0000000000 --- a/lib/sql_algebra/relations/predicates/equality_predicate.rb +++ /dev/null @@ -1,7 +0,0 @@ -class EqualityPredicate < BinaryPredicate - def ==(other) - self.class == other.class and - ((attribute1.eql?(other.attribute1) and attribute2.eql?(other.attribute2)) or - (attribute1.eql?(other.attribute2) and attribute2.eql?(other.attribute1))) - end -end \ No newline at end of file diff --git a/lib/sql_algebra/relations/predicates/greater_than_or_equal_to_predicate.rb b/lib/sql_algebra/relations/predicates/greater_than_or_equal_to_predicate.rb deleted file mode 100644 index 49127c312c..0000000000 --- a/lib/sql_algebra/relations/predicates/greater_than_or_equal_to_predicate.rb +++ /dev/null @@ -1,2 +0,0 @@ -class GreaterThanOrEqualToPredicate < BinaryPredicate -end \ No newline at end of file diff --git a/lib/sql_algebra/relations/predicates/greater_than_predicate.rb b/lib/sql_algebra/relations/predicates/greater_than_predicate.rb deleted file mode 100644 index 03aecaed62..0000000000 --- a/lib/sql_algebra/relations/predicates/greater_than_predicate.rb +++ /dev/null @@ -1,2 +0,0 @@ -class GreaterThanPredicate < BinaryPredicate -end \ No newline at end of file diff --git a/lib/sql_algebra/relations/predicates/less_than_or_equal_to_predicate.rb b/lib/sql_algebra/relations/predicates/less_than_or_equal_to_predicate.rb deleted file mode 100644 index fee6ea7f35..0000000000 --- a/lib/sql_algebra/relations/predicates/less_than_or_equal_to_predicate.rb +++ /dev/null @@ -1,2 +0,0 @@ -class LessThanOrEqualToPredicate < BinaryPredicate -end \ No newline at end of file diff --git a/lib/sql_algebra/relations/predicates/less_than_predicate.rb b/lib/sql_algebra/relations/predicates/less_than_predicate.rb deleted file mode 100644 index 03cbdcf000..0000000000 --- a/lib/sql_algebra/relations/predicates/less_than_predicate.rb +++ /dev/null @@ -1,2 +0,0 @@ -class LessThanPredicate < BinaryPredicate -end \ No newline at end of file diff --git a/lib/sql_algebra/relations/predicates/match_predicate.rb b/lib/sql_algebra/relations/predicates/match_predicate.rb deleted file mode 100644 index 90a13090d4..0000000000 --- a/lib/sql_algebra/relations/predicates/match_predicate.rb +++ /dev/null @@ -1,7 +0,0 @@ -class MatchPredicate < Predicate - attr_reader :attribute, :regexp - - def initialize(attribute, regexp) - @attribute, @regexp = attribute, regexp - end -end \ No newline at end of file diff --git a/lib/sql_algebra/relations/predicates/predicate.rb b/lib/sql_algebra/relations/predicates/predicate.rb deleted file mode 100644 index 4c395a3fdc..0000000000 --- a/lib/sql_algebra/relations/predicates/predicate.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Predicate - def ==(other) - self.class == other.class - end -end \ No newline at end of file diff --git a/lib/sql_algebra/relations/predicates/range_inclusion_predicate.rb b/lib/sql_algebra/relations/predicates/range_inclusion_predicate.rb deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/sql_algebra/relations/predicates/relation_inclusion_predicate.rb b/lib/sql_algebra/relations/predicates/relation_inclusion_predicate.rb deleted file mode 100644 index 5881a85d99..0000000000 --- a/lib/sql_algebra/relations/predicates/relation_inclusion_predicate.rb +++ /dev/null @@ -1,11 +0,0 @@ -class RelationInclusionPredicate < Predicate - attr_reader :attribute, :relation - - def initialize(attribute, relation) - @attribute, @relation = attribute, relation - end - - def ==(other) - super and attribute == other.attribute and relation == other.relation - 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 -- cgit v1.2.3