Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

order().by(key) returns the elements without the key, which TinkerPop leaves out

クローズ
#5,107 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #5108 @porunov による — マージ済み

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
15/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
elasticsearch, java
領域
databases

調査の方向性

Start by running the Groovy reproduction against inmemory storage and comparing it with TinkerGraph. The fold logic is in HasStepFolder.foldInOrder and validJanusGraphOrder, which feed JanusGraphStep, GraphCentricQueryBuilder.orderBy and OrderList, and the vertex-step path through BaseVertexCentricQueryBuilder.orderBy and BasicVertexCentricQueryBuilder.loadRelationsFromCache. Done means the counts and orders match TinkerGraph for each case, and the AssertionError and IllegalArgumentException no longer occur. PR #5108 already addresses this, so coordinate with it first.

索引モデルが issue の本文から書いたものです。

説明

JanusGraph folds a traversal's order().by(key) into its query, and the query returns the elements which have no value of the key as well, after the others. TinkerPop leaves such an element out: a by() modulator which yields no value filters the traverser, so TinkerGraph returns only the elements which have the key.

Reproduction (inmemory storage; the same with a mixed index on kind and name, on Lucene or Elasticsearch):

g.addV().property('kind', 'p').property('name', 'c').iterate()
g.addV().property('kind', 'p').property('name', 'a').iterate()
g.addV().property('kind', 'p').iterate()
g.addV().property('kind', 'p').property('name', 'b').iterate()

g.V().has('kind', 'p').order().by('name').count()   // TinkerGraph: 3, JanusGraph: 4
g.V().has('kind', 'p').order().by('name')           // JanusGraph: a, b, c, then the vertex without a name

The same happens wherever JanusGraph folds the order in:

  • in a query which a mixed index sorts, one whose results a composite index gives and JanusGraph sorts, and one which no index answers;
  • for the vertices and edges which a transaction added or changed;
  • in an order of the edges or properties of a vertex, such as g.V(v).local(outE('link').order().by('weight').limit(2)). Descending, the edges without a weight come first there.

Related problems in the same code

  1. order().by('name', shuffle) throws an AssertionError from Order.convert: HasStepFolder.validJanusGraphOrder lets the order through.
  2. Of several order() steps in a row, such as order().by('age').order().by('name'), JanusGraph drops all but the last. So the elements without an age stay, and the ties of name aren't ordered by age, as TinkerPop's sorts, which keep the order of ties, order them. An earlier order by a traversal, such as order().by(values('age').is(gt(2))), is dropped too.
  3. g.V(v).local(outE('link').order().by('weight').by('uid')) throws IllegalArgumentException: Only a single sort order is supported on vertex queries.
  4. With query.batch.enabled, which is the default, g.V(v).local(outE('link').order().by('weight').limit(2)) returns the edges in the order in which the storage backend holds them, rather than by weight, where no vertex-centric index sorts the label's edges by weight. An ordered JanusGraphMultiVertexQuery, such as tx.multiQuery(v).labels('link').orderBy('weight', asc).edges(), returns them in that order too.
  5. With the deprecated ProductiveByStrategy, which makes by('name') yield null where a vertex has no name, TinkerPop places those vertices first when ascending, while JanusGraph folds the order in and places them last.

Cause

  • HasStepFolder.foldInOrder folds the keys of the order into the step. JanusGraphStep passes them to GraphCentricQueryBuilder.orderBy, whose query keeps an element without a value and places it last (OrderList). JanusGraphVertexStep and JanusGraphPropertiesStep do the same for a vertex's relations, which RelationComparator places last when ascending and first when descending.
  • validJanusGraphOrder takes any Order, shuffle included, and a by(key) whose ValueTraversal has a bypass traversal.
  • foldInOrder removes every order() step before the last, whatever its modulators.
  • BaseVertexCentricQueryBuilder.orderBy takes one key, while foldInOrder folds every key of the order into a vertex step.
  • BasicVertexCentricQueryBuilder.loadRelationsFromCache returns the relations which a multi-query loaded as they are when each subquery is cached and fitted, whether or not the backend sorts it by the query's order.
主要言語
Java
スター
5.9k
フォーク
1.2k
平均マージ
2日 6時間
マージ済み PR(30日)
77

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

JanusGraph/janusgraph のほかの issue

JanusGraph/janusgraph の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。