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

Trouble with order of params in graph.getVertices when using index #7375

Closed
karolmie1 opened this issue Apr 27, 2017 · 1 comment
Closed
Assignees
Labels
Milestone

Comments

@karolmie1
Copy link

karolmie1 commented Apr 27, 2017

OrientDB Version: 2.2.18

Java Version: 8

OS: linux

Expected behavior

I perform a query for Tasks. Task is created as:

CREATE CLASS Task extends V
CREATE PROPERTY Task.projectId STRING (MANDATORY TRUE, NOTNULL, MAX 20)
CREATE PROPERTY Task.seq SHORT ( MANDATORY TRUE, NOTNULL, MIN 0)

CREATE INDEX TaskPK ON Task (projectId, seq) UNIQUE

I performed a query in "wrong" (not index) order (yeah, I don't intend for it to stay this way)

graph.getVertices(Task.CLASS, arrayOf(Task.SEQ, Task.PROJECT_ID), arrayOf(taskId.seq, taskId.projectId))

OrientDb decides to use index here anyway. That would not be a problem, except that the order or keys is switched. This causes orientdb to try to cast taskId to String, and projectId to Short. That obviously causes the error.

Querry works perfectly after changing the order of parameters.
graph.getVertices(Task.CLASS, arrayOf(Task.SEQ, Task.PROJECT_ID), arrayOf(taskId.projectId, taskId.seq))

In my original code, I will switch the order of Ikeys to correspond to Index, so that is not a problem for me in the slightest. I just wanted to share with you this oddity.

This would be bad if both of my parameters were of type string - then It would cause strange querry results, and would make the problem hard to pinpoint. I would better have an exception instead of this weird result.

Problem is here:

      Set<OIndex<?>> indexes = clazz.getInvolvedIndexes(Arrays.asList(iKey)); //finds index correctly
      Iterator<OIndex<?>> iterator = indexes.iterator();  // iterate over it randomly, not caring about order of parameters
      while (iterator.hasNext()) {
...
          List<Object> keys = Arrays.asList(convertKeys(idx, iValue)); //and cast (the place that originally have thrown the error)
...

Steps to reproduce

I will branch out my project if anyone finds this worth investigating.

@karolmie1 karolmie1 changed the title Reversed order of params in graph.getVertices Trouble with order of params in graph.getVertices when using index Apr 27, 2017
@luigidellaquila
Copy link
Member

Hi @karolmie1

Thank you very much for reporting, I just pushed a fix for this on branch 2.2.x

Thanks

Luigi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants