4

如果 marko 存在,我编写了一个 JUnit 测试来检查generate-modern.groovy图。
我的小鬼查询是

"gV().has('name','marko')";

正如您在generate-modern.groovy文件中看到的那样,索引已应用于人员的 name 属性。我后来做了以下

query.force-index=true

dynamodb.properties文件中的属性 true会阻止整个图形扫描,从而强制索引。但是它给我带来了以下异常

org.janusgraph.core.JanusGraphException: Could not find a suitable index to answer graph query and graph scans are disabled: [(name = marko)]:VERTEX

上述异常是从以下 StandardJanusGraphTx 类的方法引发的

    @Override
    public Iterator<JanusGraphElement> execute(final GraphCentricQuery query, final JointIndexQuery indexQuery, final Object exeInfo, final QueryProfiler profiler) {
        Iterator<JanusGraphElement> iter;
        if (!indexQuery.isEmpty()) {
            List<QueryUtil.IndexCall<Object>> retrievals = new ArrayList<QueryUtil.IndexCall<Object>>();
            for (int i = 0; i < indexQuery.size(); i++) {
                final JointIndexQuery.Subquery subquery = indexQuery.getQuery(i);

                retrievals.add(new QueryUtil.IndexCall<Object>() {
                    @Override
                    public Collection<Object> call(int limit) {
                        final JointIndexQuery.Subquery adjustedQuery = subquery.updateLimit(limit);
                        try {
                            return indexCache.get(adjustedQuery, new Callable<List<Object>>() {
                                @Override
                                public List<Object> call() throws Exception {
                                    return QueryProfiler.profile(subquery.getProfiler(), adjustedQuery, q -> indexSerializer.query(q, txHandle));
                                }
                            });
                        } catch (Exception e) {
                            throw new JanusGraphException("Could not call index", e.getCause());
                        }
                    }
                });
            }


            List<Object> resultSet = QueryUtil.processIntersectingRetrievals(retrievals, indexQuery.getLimit());
            iter = com.google.common.collect.Iterators.transform(resultSet.iterator(), getConversionFunction(query.getResultType()));
        } else {
            if (config.hasForceIndexUsage()) throw new JanusGraphException("Could not find a suitable index to answer graph query and graph scans are disabled: " + query);
            log.warn("Query requires iterating over all vertices [{}]. For better performance, use indexes", query.getCondition());

            QueryProfiler sub = profiler.addNested("scan");
            sub.setAnnotation(QueryProfiler.QUERY_ANNOTATION,indexQuery);
            sub.setAnnotation(QueryProfiler.FULLSCAN_ANNOTATION,true);
            sub.setAnnotation(QueryProfiler.CONDITION_ANNOTATION,query.getResultType());

            switch (query.getResultType()) {
                case VERTEX:
                    return (Iterator) getVertices().iterator();

                case EDGE:
                    return (Iterator) getEdges().iterator();

                case PROPERTY:
                    return new VertexCentricEdgeIterable(getInternalVertices(),RelationCategory.PROPERTY).iterator();

                default:
                    throw new IllegalArgumentException("Unexpected type: " + query.getResultType());
            }
        }

        return iter;
    }

};

从方法中可以看出,当 JointIndexQuery 对象为空(arrayList 为空)并且强制索引为 true 时引发异常。
问题是为什么列表是空的?当我们在从 JUnit 测试查询时针对generate-modern.groovy中的 name 属性指定索引查询时。这工作正常意味着当相同的数据被预加载到具有相同文件的 gremlin 服务器中时列表不为空。

4

1 回答 1

1

personByName 索引定义使用标签约束。

def personByName = mgmt.buildIndex("personByName", Vertex.class).addKey(name).indexOnly(person).buildCompositeIndex()

为了利用该索引,您必须使用标签和属性。例如:

g.V().has('person', 'name', 'marko')

您可以在 JanusGraph 文档http://docs.janusgraph.org/latest/indexes.html#_label_constraint中阅读更多相关信息

于 2017-08-03T19:10:33.613 回答