Skip to content

Commit

Permalink
Fix index usage on getVertices() when property order is inverted
Browse files Browse the repository at this point in the history
Resolves: #7375
  • Loading branch information
luigidellaquila committed May 2, 2017
1 parent 5499f44 commit 6fe392e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,9 @@ public Vertex getVertexByKey(final String iKey, Object iValue) {
* @return Vertices as Iterable
*/
public Iterable<Vertex> getVertices(final String label, final String[] iKey, Object[] iValue) {
if (iKey.length != iValue.length) {
throw new IllegalArgumentException("key names and values must be arrays of the same size");
}
makeActive();
final OClass clazz = getDatabase().getMetadata().getImmutableSchemaSnapshot().getClass(label);
if (clazz != null) {
Expand All @@ -911,7 +914,12 @@ public Iterable<Vertex> getVertices(final String label, final String[] iKey, Obj
if ("lucene".equalsIgnoreCase(idx.getAlgorithm())) {
continue;
}
List<Object> keys = Arrays.asList(convertKeys(idx, iValue));
Object[] sortedParams = new Object[iValue.length];
List<String> indexFields = idx.getDefinition().getFields();
for (int i = 0; i < iKey.length; i++) {
sortedParams[indexFields.indexOf(iKey[i])] = iValue[i];
}
List<Object> keys = Arrays.asList(convertKeys(idx, sortedParams));
Object key;
if (keys.size() == 1) {
key = keys.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
import com.orientechnologies.orient.test.domain.business.Account;
import com.orientechnologies.orient.test.domain.whiz.Profile;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
import com.tinkerpop.blueprints.impls.orient.*;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Optional;
Expand Down Expand Up @@ -2205,6 +2203,26 @@ public void testNullValuesCountHashNotUniqueTwo() {
Assert.assertEquals(index.getSize(), 2);
}

@Test
public void testParamsOrder() {

OrientBaseGraph graph = new OrientGraphNoTx("memory:IndexTest_testParamsOrder", "admin", "admin");

graph.command(new OCommandSQL("CREATE CLASS Task extends V")).execute();
graph.command(new OCommandSQL("CREATE PROPERTY Task.projectId STRING (MANDATORY TRUE, NOTNULL, MAX 20)")).execute();
graph.command(new OCommandSQL("CREATE PROPERTY Task.seq SHORT ( MANDATORY TRUE, NOTNULL, MIN 0)")).execute();
graph.command(new OCommandSQL("CREATE INDEX TaskPK ON Task (projectId, seq) UNIQUE")).execute();

graph.command(new OCommandSQL("INSERT INTO Task (projectId, seq) values ( 'foo', 2)")).execute();
graph.command(new OCommandSQL("INSERT INTO Task (projectId, seq) values ( 'bar', 3)")).execute();
Iterable<Vertex> x = graph.getVertices("Task", new String[] { "seq", "projectId" }, new Object[] { (short) 2, "foo" });
Iterator<Vertex> iter = x.iterator();
Assert.assertTrue(iter.hasNext());
iter.next();
Assert.assertFalse(iter.hasNext());
graph.drop();
}

private static void checkIndexKeys(OrientGraph graph, String indexName) {
Iterable<ODocument> indexDataDocs = (Iterable<ODocument>) graph.getRawGraph()
.query(new OSQLSynchQuery<ODocument>("select from index:" + indexName));
Expand Down

0 comments on commit 6fe392e

Please sign in to comment.