Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negation and Disjunction from datomic #50

Closed
narma opened this issue Jan 18, 2015 · 16 comments
Closed

Negation and Disjunction from datomic #50

narma opened this issue Jan 18, 2015 · 16 comments

Comments

@narma
Copy link

@narma narma commented Jan 18, 2015

Hello! Thanks for a very good project. Got rid of lots of pain at client-side.

There is blogpost about new enchancements in queries, for example disunction (or) without using rules and negation, via the new not and not-join clauses.

I found it very useful and seems it's not too hard to achieve this in datascript.

What do you think about adding this functionality to datascript?

@tonsky

This comment has been minimized.

Copy link
Owner

@tonsky tonsky commented Jan 19, 2015

Sure, eventually :)

@sparkofreason

This comment has been minimized.

Copy link

@sparkofreason sparkofreason commented Jan 19, 2015

+1

@bahulneel

This comment has been minimized.

Copy link

@bahulneel bahulneel commented Nov 13, 2015

Is there any progress on this as it would be extremely useful for me?

@terinjokes

This comment has been minimized.

Copy link

@terinjokes terinjokes commented Feb 24, 2016

Disjoins seem to be implemented, at least as part of 0.15, but I can't get them to work. When I try the following code, adapted from test/query_or.cljc, I get the error "Query for unknown vars: [?e]".

var db = ds.db_with(ds.empty_db(), [
  {":db/id": 1, ":name": "Ivan", ":age": 10},
  {":db/id": 2, ":name": "Ivan", ":age": 20},
  {":db/id": 3, ":name": "Oleg", ":age": 10},
  {":db/id": 4, ":name": "Oleg", ":age": 20},
  {":db/id": 5, ":name": "Ivan", ":age": 10},
  {":db/id": 6, ":name": "Ivan", ":age": 20}
]);
ds.q('[:find ?e :where [(or [?e ":name" "Oleg"] [?e ":age" 10])]]', db);

Am I doing something wrong, or are "or"s still not ready?

@bahulneel

This comment has been minimized.

Copy link

@bahulneel bahulneel commented Feb 24, 2016

There's an experimental query namespace called v3 that negation and joins work on, some other things don't though so your mileage may vary.

@tonsky

This comment has been minimized.

Copy link
Owner

@tonsky tonsky commented Feb 24, 2016

That’s right, it’s a rewrite of a query engine, it’s not used by default
because it doesn’t do rules, fn/pred calls and probably something else.

On Wed, Feb 24, 2016 at 2:44 PM Bahul Neel Upadhyaya <
notifications@github.com> wrote:

There's an experimental query namespace called v3 that negation and joins
work on, some other things don't though so your mileage may vary.


Reply to this email directly or view it on GitHub
#50 (comment).

@bahulneel

This comment has been minimized.

Copy link

@bahulneel bahulneel commented Feb 24, 2016

If you just need a disjoint you can can the same effect with two rules with the same head.

@terinjokes

This comment has been minimized.

Copy link

@terinjokes terinjokes commented Feb 24, 2016

As far as I can tell, query_v3 doesn't get exposed via the JS interop layer. Just to be clear, negation and disjoins only work in it?

@bahulneel Thanks, I saw disjoins were possible beforehand in the blog post linked above. I'm new to datalog (just started 12 hours ago or so), so haven't quite figured how to do write a or-equivalent rule just yet. I'll look into it today.

@bahulneel

This comment has been minimized.

Copy link

@bahulneel bahulneel commented Feb 24, 2016

Based on your example you could create a rule called (name-or-age ?name ?age) with two bodies e.g.:

[[(name-or-age ?e ?name ?age)
  [?e :name ?name]]
 [(name-or-age ?e ?name ?age)
  [?e :age ?age]]]

Then in the query:

ds.q('[:find ?e :in $ % :where (name-or-age ?e "Oleg" 10)]', db, rules);

(not sure what the js native way of making the rules data structure is)

@terinjokes

This comment has been minimized.

Copy link

@terinjokes terinjokes commented Feb 24, 2016

@bahulneel You put it in quotes like that. 😄

@tonsky

This comment has been minimized.

Copy link
Owner

@tonsky tonsky commented Feb 24, 2016

As far as I can tell, query_v3 doesn't get exposed via the JS interop
layer. Just to be clear, negation and disjoins only work in it?

Yes. It’s not considered part of DS API in Clojure either. It’s just where
development happens.

On Wed, Feb 24, 2016 at 11:26 PM Terin Stock notifications@github.com
wrote:

@bahulneel https://github.com/bahulneel You put it in quotes like that. [image:
😄]


Reply to this email directly or view it on GitHub
#50 (comment).

@atroche

This comment has been minimized.

Copy link

@atroche atroche commented Aug 6, 2016

Hi guys,

I just posted a $USD300 bounty for this issue. Feel free to pitch in with cash or, y'know, claim the bounty =)

@bahulneel

This comment has been minimized.

Copy link

@bahulneel bahulneel commented Mar 20, 2018

I've shown a method of achieving both using some custom predicates in this ticket: #238

@comnik

This comment has been minimized.

Copy link

@comnik comnik commented Jul 17, 2018

Sorry for reviving this, but I'd be up for taking a stab at this. @tonsky does it make more sense to wait for / contribute to query_v3 or add negation and disjunction to the current version of the query engine?

@tonsky

This comment has been minimized.

Copy link
Owner

@tonsky tonsky commented Jul 20, 2018

I doubt I’ll be able to revive query_v3 any time soon, so more realistic approach would be to add those to the current query impl

@tonsky

This comment has been minimized.

Copy link
Owner

@tonsky tonsky commented Dec 13, 2018

Phew. Issue from 2015. Finally implemented not/or/not-join/or-join in 0.17.1. Enjoy!

@tonsky tonsky closed this Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.