dkubb / axiom

Simplifies querying of structured data using relational algebra
https://github.com/dkubb/axiom
MIT License
459 stars 22 forks source link

Relation#sort should sort on all attributes in the header #58

Open snusnu opened 9 years ago

snusnu commented 9 years ago

I was under the impression that the issue title describes the expected behavior. However, when i do some_base_relation_gateway.sort.drop(1).take(1), neither ORDER BY nor OFFSET/LIMIT clauses get pushed down to the underlying (postgres) adapter. The result being that the operations are ("silently") handled in memory, while performing (potentially) slow queries.

snusnu commented 9 years ago

I should maybe clarify a bit. It seems like Relation#sort actually fulfills its promise, but it does so "in memory" only. The actual operations do not get pushed down to a (sql) backend.

dkubb commented 9 years ago

@snusnu can you work out a minimal test case that demonstrates the problem? This sounds like a bug and is not at all what was intended.

snusnu commented 9 years ago

@dkubb seems like the following change to axiom-do-adapter fixes this issue:

diff --git a/lib/axiom/relation/gateway.rb b/lib/axiom/relation/gateway.rb
index 7274cc3..27d0430 100644
--- a/lib/axiom/relation/gateway.rb
+++ b/lib/axiom/relation/gateway.rb
@@ -10,7 +10,7 @@ module Axiom

       # remove methods so they can be proxied
       undef_method(*DECORATED_CLASS.public_instance_methods(false).map(&:to_s) - %w[materialize])
-      undef_method(:project, :remove, :extend, :rename, :restrict, :sort_by, :reverse, :drop, :take)
+      undef_method(:project, :remove, :extend, :rename, :restrict, :sort, :sort_by, :reverse, :drop, :take)

       # The adapter the gateway will use to fetch results
       #
snusnu commented 9 years ago

@dkubb anything i can do to further help with this one?