Skip to content

Commit d27cf1d

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

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
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;

janusgraph-core/src/main/java/org/janusgraph/graphdb/tinkerpop/optimize/step/HasStepFolder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.apache.tinkerpop.gremlin.process.traversal.util.AndP;
3838
import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP;
3939
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
40-
import org.janusgraph.core.Cardinality;
40+
//import org.janusgraph.core.Cardinality;
4141
import org.janusgraph.core.JanusGraphTransaction;
4242
import org.janusgraph.core.PropertyKey;
4343
import org.janusgraph.graphdb.query.JanusGraphPredicateUtils;
@@ -121,7 +121,8 @@ static boolean validJanusGraphOrder(OrderGlobalStep orderGlobalStep, Traversal r
121121
final PropertyKey pKey = tx.getPropertyKey(key);
122122
if (pKey == null
123123
|| !(Comparable.class.isAssignableFrom(pKey.dataType()))
124-
|| (isVertexOrder && pKey.cardinality() != Cardinality.SINGLE)) {
124+
//|| (isVertexOrder && pKey.cardinality() != Cardinality.SINGLE)) {
125+
) {
125126
return false;
126127
}
127128
}

janusgraph-lucene/src/main/java/org/janusgraph/diskstorage/lucene/LuceneIndex.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ private List<IndexableField> buildIndexFields(final Document doc, final KeyInfor
513513
continue;
514514
}
515515
KeyInformation ki = information.get(getOrigFieldName(fieldName));
516-
boolean isPossibleSortIndex = ki.getCardinality() == Cardinality.SINGLE;
516+
//boolean isPossibleSortIndex = ki.getCardinality() == Cardinality.SINGLE;
517+
boolean isPossibleSortIndex = true;
517518
Class<?> dataType = ki.getDataType();
518519
if (AttributeUtils.isWholeNumber(dataType)) {
519520
long value = field.numericValue().longValue();

0 commit comments

Comments
 (0)