This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-30
Channels
- # babashka (46)
- # beginners (234)
- # bristol-clojurians (4)
- # cider (7)
- # clj-kondo (39)
- # cljdoc (8)
- # cljs-dev (10)
- # cljsjs (10)
- # cljsrn (24)
- # clojure (84)
- # clojure-brasil (7)
- # clojure-europe (12)
- # clojure-germany (4)
- # clojure-italy (3)
- # clojure-nl (41)
- # clojure-spec (17)
- # clojure-uk (66)
- # clojurescript (64)
- # conjure (161)
- # cursive (12)
- # data-science (45)
- # datomic (20)
- # devops (11)
- # docker (2)
- # duct (9)
- # events (7)
- # figwheel (1)
- # figwheel-main (20)
- # fulcro (32)
- # graalvm (5)
- # helix (82)
- # jackdaw (9)
- # jobs-discuss (19)
- # kaocha (11)
- # local-first-clojure (1)
- # malli (6)
- # meander (3)
- # nrepl (12)
- # off-topic (2)
- # other-lisps (15)
- # pathom (14)
- # rdf (6)
- # re-frame (8)
- # reactive (1)
- # reagent (5)
- # reitit (4)
- # rum (3)
- # shadow-cljs (77)
- # spacemacs (3)
- # sql (9)
- # test-check (31)
- # tools-deps (13)
- # vim (62)
- # xtdb (18)
Is there a way to specify in a query that a document does not have a certain trait. ie: some docs might have a trait :dependencies, and some may not, is there a way to query for the ones that don't?"
edit: didn't realize that {:where [[(not [e :my-trait])]]}
worked. Obvious thing is obvious when made apparent.
edit2: for any other noobs (like me) who see this, use the tests as a way to see queries that work (or don't work): https://github.com/juxt/crux/blob/master/crux-test/test/crux/query_test.clj
Hey - glad you found the answer so quickly π but you're 100% right the tests are by far the best way to sanity check what's possible or not. And Datalog certainly has a learning curve...I spent most of last Saturday thinking about how to efficiently do the equivalent of a FULL OUTER JOIN
in a single efficient Datalog without repeating a bunch of (or (not-join ...
work. I've reluctantly had to give up thinking about it for now π
Thanks. For some reason, Iβll spend a bunch of time looking for something, decide I should just ask, then after asking, figure out a way to find the answer. I might need to order one of those rubber ducks after all... I might try my hand at some docs for the various Datalog operators with examples if you think itβd be helpful. edit: if only for learning purposes
Aha, we would never turn down an offer of writing docs! Another tutorial instalment to cover this area is also warranted.
Awesome to see Crux working already π We use it for all our BI needs in the company π
Yep π the screenshot is showing Metabase talking to Crux via our work-in-progress SQL JDBC driver, powered by Apache Calcite. Metabase was able to figure everything out by itself and I was able to very simply create the join in the UI across the Datalog-backed "tables" that Calcite dynamically exposes - the generated SQL join then gets pushed down into a single Datalog query, so it's a pretty efficient abstraction.
neat, Metabase looks like it's come on a fair way since I last used it - which wasn't long ago, and it was good then π
Is there a facility for subqueries? Or is it the sort of thing that's really unnecessary given the nature of it?
Or, not-join and various rules will already execute as subqueries under the hood. There's no explicit concept of subquery though. What situations are you thinking about?
Also there's really no penalty when running multiple queries from Clojure if everything is in-process and you use open-db
I was running into issues with querying entities with multiple values for a key:
{:crux.db/id :entity
:dependencies {:dep-1 :dep2}}
Let's say you want entities that only depend on :dep-1. This doesn't work:
{:find [e]
:where [[(== #{:dep-1} d)]
[e :dependencies d]
[e :dependencies d2]
[(!= #{:dep2} d2)]]}
And neither did a few others, always either returning entity when they shouldn't (like the below). Or returning nothing (like the above).
{:find [e]
:where [[(== #{:dep-1} d)]
[e :dependencies d]
(not-join [e]
[e :dependencies d2]
[(!= #{:dep-1} d2)])]}
Eventually this other one did work:
{:find '[e]
:where [(depends e)
(not (doesn't-depend e))]
:rules [[(depends e)
[e :dependencies d1]
[(== deps d1)]]
[(doesn't-depend e)
[e :dependencies d2]
[(!= deps d2)]]]
:args [{'deps #{:dep-1}]}
I think it's because the rules in the last one create subsets of the entity, rather than creating subsets of tuples of the entity and a dependency, like the ones that didn't work. Hence the question about sub-queries. I'm guessing that each rule generates a subset on it's own, and then the final query is the intersection of the various tuples?
In that first snippet are you missing a #
? Is that value for :dependencies
supposed to be a set?
...assuming so, I think you should be able to do this:
{:find [e]
:where [[e :dependencies :dep1]
(not [e :dependencies :dep2])}
@US65YEL1M (just making sure you don't miss this response!)