From 2fe585328d6a24df310d3e60059c9c7b05b64bac Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Tue, 27 May 2008 14:19:59 -0700 Subject: performing in memory joins --- lib/arel/algebra/relations/row.rb | 4 ++++ lib/arel/engines/memory/relations/operations.rb | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'lib') diff --git a/lib/arel/algebra/relations/row.rb b/lib/arel/algebra/relations/row.rb index 2d63498452..3731dd9696 100644 --- a/lib/arel/algebra/relations/row.rb +++ b/lib/arel/algebra/relations/row.rb @@ -17,5 +17,9 @@ module Arel def bind(relation) Row.new(relation, tuple) end + + def combine(other, relation) + Row.new(relation, tuple + other.tuple) + end end end \ No newline at end of file diff --git a/lib/arel/engines/memory/relations/operations.rb b/lib/arel/engines/memory/relations/operations.rb index 8e03aca7b1..e35fbe3234 100644 --- a/lib/arel/engines/memory/relations/operations.rb +++ b/lib/arel/engines/memory/relations/operations.rb @@ -37,4 +37,25 @@ module Arel raise NotImplementedError end end + + class Alias < Compound + def eval + unoperated_rows + end + end + + class Join < Relation + def eval + result = [] + relation1.eval.each do |row1| + relation2.eval.each do |row2| + combined_row = row1.combine(row2, self) + if predicates.all? { |p| p.eval(combined_row) } + result << combined_row + end + end + end + result + end + end end \ No newline at end of file -- cgit v1.2.3