{"action":"created","issue":{"url":"https://api.github.com/repos/tinkerpop/tinkerpop3/issues/130","labels_url":"https://api.github.com/repos/tinkerpop/tinkerpop3/issues/130/labels{/name}","comments_url":"https://api.github.com/repos/tinkerpop/tinkerpop3/issues/130/comments","events_url":"https://api.github.com/repos/tinkerpop/tinkerpop3/issues/130/events","html_url":"https://github.com/tinkerpop/tinkerpop3/issues/130","id":42905393,"number":130,"title":"Provide support for has() ANDing and ORing.","user":{"login":"okram","id":148925,"avatar_url":"https://avatars.githubusercontent.com/u/148925?v=3","gravatar_id":"","url":"https://api.github.com/users/okram","html_url":"https://github.com/okram","followers_url":"https://api.github.com/users/okram/followers","following_url":"https://api.github.com/users/okram/following{/other_user}","gists_url":"https://api.github.com/users/okram/gists{/gist_id}","starred_url":"https://api.github.com/users/okram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/okram/subscriptions","organizations_url":"https://api.github.com/users/okram/orgs","repos_url":"https://api.github.com/users/okram/repos","events_url":"https://api.github.com/users/okram/events{/privacy}","received_events_url":"https://api.github.com/users/okram/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tinkerpop/tinkerpop3/labels/enhancement","name":"enhancement","color":"009800"},{"url":"https://api.github.com/repos/tinkerpop/tinkerpop3/labels/process","name":"process","color":"bfdadc"}],"state":"open","locked":false,"assignee":{"login":"okram","id":148925,"avatar_url":"https://avatars.githubusercontent.com/u/148925?v=3","gravatar_id":"","url":"https://api.github.com/users/okram","html_url":"https://github.com/okram","followers_url":"https://api.github.com/users/okram/followers","following_url":"https://api.github.com/users/okram/following{/other_user}","gists_url":"https://api.github.com/users/okram/gists{/gist_id}","starred_url":"https://api.github.com/users/okram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/okram/subscriptions","organizations_url":"https://api.github.com/users/okram/orgs","repos_url":"https://api.github.com/users/okram/repos","events_url":"https://api.github.com/users/okram/events{/privacy}","received_events_url":"https://api.github.com/users/okram/received_events","type":"User","site_admin":false},"milestone":null,"comments":19,"created_at":"2014-09-16T16:54:50Z","updated_at":"2015-01-29T19:03:39Z","closed_at":null,"body":"By TP3 GA we should have support for ANDing and ORing on has() steps (and ultimately, via propagation to XXXGraphStep, support for complex index lookups).\r\n\r\nCurrently we can do this:\r\n\r\n```groovy\r\ng.V.has('name','marko').has('age',T.lt,34)  // chaining ANDs\r\ng.V.has('name', Contains.IN, ['marko','daniel'])  // ORing on a single property\r\n```\r\n\r\nWe need to support arbitrary ANDing and ORing. Is the following proposal sufficient?\r\n\r\n```groovy\r\ng.V.has('name','marko',T.or,'age',T.lt,34)  // name = marko || age < 34\r\ng.V.has('name','marko').has('age',T.lt,34,T.or,'weight',T.lt,150)  // name = marko && (age < 34 || weight < 150)\r\n```\r\n\r\nIn the above model, `has(Object...)` which is not good from an API standpoint and the parsing would be lots of `if(object[i] instanceof BiPredicate)`, `if(object[i] instanceof Or)` to generate the HasContainers. The HasContainers would then need to be represented in a nested list to expose the clauses.\r\n\r\nHowever, is the above proposal sufficient? What about `(name = marko && age < 34) || (name = daniel && weight < 150)`, where chaining is an OR, not an AND.\r\n\r\n```groovy\r\ng.V.has('name','marko',T.and,'age',T.lt,34).orHas('name','daniel',T.and,'weight',T.lt,150)\r\n```\r\n\r\nIn this model, each `has()` is a clause. and you can either `andHas()` or `orHas()` clauses together, where `andHas()` can simply call `has()`, but is provided so chaining predicate is obvious. \r\n\r\nHow would you interpret the following expression?\r\n\r\n```groovy\r\ng.V.has('label','person')\r\n     .andHas('name','marko',T.and,'age',T.lt,34)\r\n     .orHas('name','daniel',T.and,'weight',T.lt,150).blah()\r\n==>\r\n(label = person) AND ((name = marko AND age < 34) OR (name = daniel AND weight < 150))\r\n```\r\n\r\nThe problem here is then can Daniel not be a person? To which I would say \"no\". The first `has()` checks if the element is a person. The next checks if the element is `name=marko AND age < 34`. If the `andHas()` is true, the traverser jumps to `blah()` else it goes through `orHas()` which is simply a predicate check like any old `has()`. The \"jump\" is what simulates the 'or'. \r\n\r\nIf you don't care if Daniel is a \"person\" then you do:\r\n\r\n```groovy\r\ng.V.has(Element.LABEL,'person',T.and,'name','marko',T.and,'age',T.lt,34)\r\n     .orHas(T.and,'name','daniel',T.and,'weight',T.lt,150)\r\n==>\r\n(label = person AND name = marko AND age < 34) OR (name = daniel AND weight < 150)\r\n```\r\n\r\nHow do you do more complex nestings?\r\n\r\n```groovy\r\ng.V.has('name','marko').orHas('name','daniel').andHas('age',T.lt,34).orHas('weight',T.lt,150).blah()\r\n==>\r\ng.V.has('name','marko').orHas('name','daniel').andHas('age',T.lt,34,T.or,'weight',T.lt,150).blah()\r\n==>\r\nname = marko OR (name = daniel AND (age < 34 OR weight < 150))\r\n```\r\n\r\n. Is the name marko? If so, you are done and jump to `blah()`.\r\n. Is the name daniel? If so, continue, else kill traverser.\r\n. Is the age of daniel < 34? If so, jump to `blah()`.\r\n. Is the weight of daniel < 150? If so, continue, else kill the traverser.\r\n\r\nIn essence, each `orHas()` and `andHas()` generates a new clause. However, I don't believe this is fully generic.\r\n\r\nI'm not happy with any of this right now so other proposals are greatly appreciated.\r\n  @dkuppitz @mbroecheler @rjbriody @pietermartin @spmallette @joshsh "},"comment":{"url":"https://api.github.com/repos/tinkerpop/tinkerpop3/issues/comments/72083445","html_url":"https://github.com/tinkerpop/tinkerpop3/issues/130#issuecomment-72083445","issue_url":"https://api.github.com/repos/tinkerpop/tinkerpop3/issues/130","id":72083445,"user":{"login":"mbroecheler","id":758061,"avatar_url":"https://avatars.githubusercontent.com/u/758061?v=3","gravatar_id":"","url":"https://api.github.com/users/mbroecheler","html_url":"https://github.com/mbroecheler","followers_url":"https://api.github.com/users/mbroecheler/followers","following_url":"https://api.github.com/users/mbroecheler/following{/other_user}","gists_url":"https://api.github.com/users/mbroecheler/gists{/gist_id}","starred_url":"https://api.github.com/users/mbroecheler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbroecheler/subscriptions","organizations_url":"https://api.github.com/users/mbroecheler/orgs","repos_url":"https://api.github.com/users/mbroecheler/repos","events_url":"https://api.github.com/users/mbroecheler/events{/privacy}","received_events_url":"https://api.github.com/users/mbroecheler/received_events","type":"User","site_admin":false},"created_at":"2015-01-29T19:03:39Z","updated_at":"2015-01-29T19:03:39Z","body":"@rjbriody Technically, it could but if each vendor has to write code to deconstruct such nested traversals it'll get ugly. We should provide have a syntax-tree representation in TinkerPop for this."}}