Skip to content

Commit 8bce386

Browse files
committed
[~] allow ordering list properties via index
Signed-off-by: pm-osc <pm2.osc@gmail.com>
1 parent 1b92960 commit 8bce386

File tree

4 files changed

+148
-61
lines changed

4 files changed

+148
-61
lines changed

janusgraph-backend-testutils/src/main/java/org/janusgraph/graphdb/JanusGraphIndexTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4434,4 +4434,31 @@ public void testGetIndexInfo() throws DecoderException {
44344434
assertEquals(1, indexInfo.getCompositeIndexType().getInlineFieldKeys().length);
44354435
assertEquals("id", indexInfo.getCompositeIndexType().getInlineFieldKeys()[0]);
44364436
}
4437+
4438+
@Test
4439+
public void testOrderingListProperty() {
4440+
PropertyKey strSingle = mgmt.makePropertyKey("strSingle").dataType(String.class).cardinality(Cardinality.SINGLE)
4441+
.make();
4442+
PropertyKey strList = mgmt.makePropertyKey("strList").dataType(String.class).cardinality(Cardinality.LIST)
4443+
.make();
4444+
4445+
mgmt.buildIndex("mixedStrSingle", Vertex.class).addKey(strSingle, Mapping.STRING.asParameter())
4446+
.buildMixedIndex(INDEX);
4447+
mgmt.buildIndex("mixedStrList", Vertex.class).addKey(
4448+
strList, Mapping.STRING.asParameter())
4449+
.buildMixedIndex(INDEX);
4450+
finishSchema();
4451+
4452+
tx.addVertex("strSingle", "val1", "strList", "val1");
4453+
tx.addVertex("strSingle", "val2");
4454+
tx.addVertex("strList", "val3");
4455+
tx.addVertex("strSingle", "val4", "strList", "val4", "strList", "val5", "strList", "val6");
4456+
tx.addVertex("strSingle", "val7", "strList", "val7");
4457+
tx.commit();
4458+
4459+
clopen(option(FORCE_INDEX_USAGE), false);
4460+
4461+
assertEquals(4, tx.traversal().V().has("strSingle").order().by("strSingle").count().next());
4462+
assertEquals(4, tx.traversal().V().has("strList").order().by("strList").count().next());
4463+
}
44374464
}

janusgraph-core/src/main/java/org/janusgraph/graphdb/query/graph/GraphCentricQueryBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package org.janusgraph.graphdb.query.graph;
1616

1717
import com.google.common.base.Preconditions;
18-
import org.janusgraph.core.Cardinality;
18+
//import org.janusgraph.core.Cardinality;
1919
import org.janusgraph.core.JanusGraphEdge;
2020
import org.janusgraph.core.JanusGraphElement;
2121
import org.janusgraph.core.JanusGraphQuery;
@@ -201,8 +201,8 @@ public GraphCentricQueryBuilder orderBy(String keyName, org.apache.tinkerpop.gr
201201
Preconditions.checkArgument(key!=null && order!=null,"Need to specify and key and an order");
202202
Preconditions.checkArgument(Comparable.class.isAssignableFrom(key.dataType()),
203203
"Can only order on keys with comparable data type. [%s] has datatype [%s]", key.name(), key.dataType());
204-
Preconditions.checkArgument(key.cardinality()== Cardinality.SINGLE,
205-
"Ordering is undefined on multi-valued key [%s]", key.name());
204+
//Preconditions.checkArgument(key.cardinality()== Cardinality.SINGLE,
205+
// "Ordering is undefined on multi-valued key [%s]", key.name());
206206
Preconditions.checkArgument(!orders.containsKey(key), "orders [%s] already contains key [%s]", orders, key);
207207
orders.add(key, Order.convert(order));
208208
return this;

0 commit comments

Comments
 (0)