Open obi1kenobi opened 8 years ago
It was written following: http://orientdb.com/docs/2.0/orientdb.wiki/SQL-Where.html
... where 'contains' takes a conditional expression.
I've never used - and therefore don't really understand - the semantics of embedded types in OrientDB (nor, for that matter, linked class types), so I'm not sure how much I'll be able to help, except to naively guess that maybe 'contains' should only be callable on LinkedClassProperty types and to allow a different 'in' syntax for embedded data?
Looks like it's impossible to overload python's 'in' keyword: __contains__
return value is always coerced to bool, and overloading __bool__
to return a non-bool will trigger a TypeError :(
From the description of CONTAINS in the same document you cited: "Condition can be a single item: in this case the behaviour is like the IN operator"
This definitely means the pyorient behavior is a bug. I also don't see an IN operator in pyorient's operators file.
Any thoughts on how best to proceed?
Hm, for some reason I didn't notice that bit.
This latest commit (https://github.com/OuterPlaypen/pyorient/commit/69475faab91c0bb747d42e64771629b3ae8f3191) is my proposal: since it behaves like IN, and IN looks like it was featured in earlier versions than CONTAINS, we might as well use it - and as a happy coincidence this gets around needing to define some ugly reverse-polish style in_(<value>,<collection>)
notation.
I don't have strong opinions on how this is implemented under the hood, so long as it works -- and it would be nice to have some test coverage to make sure it actually stays working in the future.
That said, it looks a little strange that a 'contains' is being rewritten with 'in' on the wire, when 'contains' was added before the 1.0 release. I don't think pyorient supports any version that early, and the code may be simpler if both paths use 'contains'.
Scratch that, please use in
instead of the supposedly equivalent contains
-- just checked on OrientDB 2.1.3 and they do not behave identically. in
returns the correct result while contains
returns no elements, when querying a FULLTEXT indexed field, even when it's the only predicate clause.
Another update: contains(X)
does not work when X is a primitive, but contains X
does.
Can i close?
I think this is still at least a documentation issue -- it's unclear to me whether the contains
method in pyorient is allowed to take a collection type or not, and whether that will be correctly handled by the code. So I'd say it's still an open issue, but it's of course your decision in the end.
There don't seem to be any tests that use the .contains method on an embedded data property (EmbeddedSet etc.) and I can't figure out how to use it without getting weird errors. Consider the following code:
This fails with the following trace:
Specifically, this line seems to be the problem, and I don't understand why it recursively calls
filter_string
on the right-hand side. Can the RHS be an expression? I would have expected it to always be a variable, because I don't see how one of these data structures could be tested for containing the result of an expression.