nathanmarz / cascalog

Data processing on Hadoop without the hassle.
Other
1.38k stars 178 forks source link

Add expand-query macro #237

Closed Gerrrr closed 10 years ago

Gerrrr commented 10 years ago

Implementation for https://github.com/nathanmarz/cascalog/issues/27

sritchie commented 10 years ago

Nice! Want to add an example expansion to the issue? Then we can move this over to the documentation. Awesome work.

danoyoung commented 10 years ago

This is great! An example would be awesome.

Regards,

Dano On Mar 8, 2014 10:26 AM, "Sam Ritchie" notifications@github.com wrote:

Nice! Want to add an example expansion to the issue? Then we can move this over to the documentation. Awesome work.

Reply to this email directly or view it on GitHubhttps://github.com/nathanmarz/cascalog/pull/237#issuecomment-37103620 .

Gerrrr commented 10 years ago

Thanks for the warm feedback.

Example with query taken from introduction tutorial:

user> (expand-query [?person ?a2] (age ?person ?age)
                    (< ?age 30) (* 2 ?age :> ?a2))
{:fields ["?person" "?a2"],
 :predicates
 ({:op
   [["alice" 28]
    ["bob" 33]
    ["chris" 40]
    ["david" 25]
    ["emily" 25]
    ["george" 31]
    ["gary" 28]
    ["kumar" 27]
    ["luanne" 36]],
   :input nil,
   :output ["?person" "?age"]}
  {:op #<core$_LT_ clojure.core$_LT_@55c0c66a>,
   :input ("?age" 30),
   :output []}
  {:op #<core$_STAR_ clojure.core$_STAR_@61415858>,
   :input (2 "?age"),
   :output ["?a2"]}),
 :options
 {:trap nil,
  :spill-threshold nil,
  :reverse nil,
  :sort nil,
  :distinct false,
  :reducers nil}}
sritchie commented 10 years ago

Awesome. I think if you use print vs pprint, these custom printers will take hold:

https://github.com/Gerrrr/cascalog/blob/feature/expand_query/cascalog-core/src/clj/cascalog/logic/predicate.clj#L48

And you'll see an expanded version of the query without the explicit op, input, output. I like the way this looks, though.

Gerrrr commented 10 years ago

So, now it looks like that:

user> (expand-query [?person ?a2] (age ?person ?age)
              (< ?age 30) (* 2 ?age :> ?a2))
(<- [?person ?a2]
    (#'cascalog.playground/age  :> ?person ?age)
    (#'clojure.core/< ?age 30)
    (#'clojure.core/* 2 ?age :> ?a2)
    )
sorenmacbeth commented 10 years ago

very nice!

On Sat, Mar 8, 2014 at 3:15 PM, Aleksandr Sorokoumov < notifications@github.com> wrote:

So, now it looks like that:

user> (expand-query [?person ?a2](age ?person ?age) (< ?age 30) (* 2 ?age :> ?a2)) (<- [?person ?a2](#'cascalog.playground/age :> ?person ?age) (#'clojure.core/< ?age 30) (#'clojure.core/* 2 ?age :> ?a2) )

Reply to this email directly or view it on GitHubhttps://github.com/nathanmarz/cascalog/pull/237#issuecomment-37113059 .

http://about.me/soren

danoyoung commented 10 years ago

Sweet! On Mar 8, 2014 4:15 PM, "Aleksandr Sorokoumov" notifications@github.com wrote:

So, now it looks like that:

user> (expand-query [?person ?a2](age ?person ?age) (< ?age 30) (* 2 ?age :> ?a2))(<- [?person ?a2](#'cascalog.playground/age :> ?person ?age) (#'clojure.core/< ?age 30) (#'clojure.core/* 2 ?age :> ?a2) )

Reply to this email directly or view it on GitHubhttps://github.com/nathanmarz/cascalog/pull/237#issuecomment-37113059 .

sritchie commented 10 years ago

It gets better when you start to include predicate macros and other sugary delicacies.

sorenmacbeth commented 10 years ago

LGTM