Fork me on GitHub
#crux
<
2020-02-04
>
dotemacs17:02:03

How do you create a query which will return all the entity IDs that have :foo key but that don’t have the :bar key? Thanks

taylor.jeremydavid17:02:20

Hi again@ - this should do it:

{:find [?e]
 :where [[?e :crux.db/id _]
         [?e :foo _]
         (not [?e :bar _])]}

taylor.jeremydavid17:02:41

unfortunately query_test.clj is still the best source of guidance on all the query options and syntax: https://github.com/juxt/crux/blob/master/crux-test/test/crux/query_test.clj

hairfire18:02:10

Strictly speaking, this is probably not a Crux question, but ... when I execute my unit tests that use a standalone in-memory Crux node I get lots of log messages within the test output that clutter it up: Testing my-system.crux-test Feb 04, 2020 12:51:38 PM clojure.tools.logging$eval1342$fn__1345 invoke WARNING: Using fsync on MemKv has no effect. Feb 04, 2020 12:51:38 PM clojure.tools.logging$eval1342$fn__1345 invoke WARNING: Using fsync on MemKv has no effect. Can someone point me in the direction of information on how to redirect the logs to '/dev/null' or a file?

taylor.jeremydavid19:02:22

We have an open issue to clarify & clean up the MemKv warnings in particular: https://github.com/juxt/crux/issues/605 In general though, you can configure a logback.xml to suppress warnings (`level="ERROR"`). You need to add a logback-classic dependency to your project.clj / deps.edn and then create a logback.xml file. There are quite a few examples in the Crux repo which might help: https://github.com/juxt/crux/search?p=2&amp;q=logback&amp;unscoped_q=logback https://github.com/juxt/crux/blob/0ac595a6df9efcde57e85356e0edfccf00e85248/crux-bench/logback.xml

hairfire21:02:56

I'll check it out. Thanks!

hairfire23:02:29

Worked perfectly, once I put the logback.xml file in the test directory. I've never attempted to wrangle Java/Clojure logging before. I'll have to do some research to see if one can do this in "pure" Clojure, without the logback.xml file (timbre?).

taylor.jeremydavid00:02:29

Excellent, I'm glad it worked. Unfortunately that's the limit of my logging knowledge though!

hairfire23:02:22

If I understand :crux.tx/cas properly then something like the following: [:crux.tx/cas nil {:crux.db/id eid k-entity k-entity-type k-type-name valid-name}] will fail if the eid already exists within Crux. Does it make sense to ask if there's some kind of transaction that allows one to execute an arbitrary predicate and only continue if the predicate returns truthy? Perhaps something like: [:crux.tx/cas (my-fn-that-checks-for-crux-state eid) {:crux.db/id eid k-entity k-entity-type k-type-name valid-name}]

taylor.jeremydavid00:02:51

This topic overlaps with transaction functions, which has a whole issue thread covering a lot of detail... but the short story is that Crux relies on transaction operations executing consistently regardless of whether documents have been evicted or not. Any operation that peeks inside a given document will inevitably evaluate differently on a second run (e.g. by another node, or during re-index) if that document gets evicted in the meantime, and therefore nodes can easily arrive at inconsistent states. If you're careful and confident in how you combine these things then it can work, but for now we have hidden transaction functions behind a feature flag

taylor.jeremydavid00:02:18

Predicates get a specific mention too as a possible option in the design space: https://github.com/juxt/crux/issues/121

hairfire13:02:18

Yes, at thorny issue indeed!