Class GqlRow

java.lang.Object
org.apache.tinkerpop.gremlin.gql.GqlRow

public final class GqlRow extends Object
One complete match produced by a GqlExecutor. A row is an immutable value: once built it cannot be changed, and it never shares mutable state with the arrays, maps or lists it was built from.

Every binding in a row is addressed by variable index, the position of the variable in GqlMatchPlan.getVariables(). The seed variable is at index GqlMatchPlan.getSeedVariableIndex(), and size() equals GqlMatchPlan.getVariableCount() for the plan that produced the row. Variables whose names start with GqlMatchPlan.ANON_VAR_PREFIX are anonymous pattern elements. They occupy an index but are not surfaced to the traversal.

Each index holds at most one kind of binding:

  • Scalar: a single graph Element, read with getScalar(int). Node variables and non-quantified edge variables are scalars.
  • Group: an ordered List<Edge>, read with getGroup(int). The edge variable of a quantified (variable-length) relationship such as (a)-[r:knows]->{1,3}(b) is a group. The list holds the edges of the walk in pattern order, left to right in the MATCH pattern regardless of which endpoint the walk started from, and is never empty for a matched walk. A group edge variable is a list even when the walk has a single edge.

An index with neither binding is unbound: getScalar(int) and getGroup(int) both return null, and the variable is omitted from the traversal result.

Rows have value semantics: two rows are equal when they have the same size and the same scalar and group bindings at every index.

Executors build rows with of(Element[], Map).

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    getGroup(int index)
    Returns the unmodifiable, ordered edge list bound to the variable index, or null if the index is unbound or holds a scalar.
    getScalar(int index)
    Returns the scalar Element bound to the variable index, or null if the index is unbound or holds a group.
    int
     
    boolean
    isGroup(int index)
    Returns true if the variable index holds a group (edge list) binding.
    static GqlRow
    of(Element[] scalars, Map<Integer,List<Edge>> groups)
    Creates a row from scalar and group bindings, both keyed by variable index.
    int
    Returns the number of variable indices in this row, equal to the length of the scalar array the row was built from.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • of

      public static GqlRow of(Element[] scalars, Map<Integer,List<Edge>> groups)
      Creates a row from scalar and group bindings, both keyed by variable index.

      The scalars array is copied, and the groups map and each of its lists are copied into unmodifiable collections, so later changes to the arguments do not affect the row. For an index that is a group, the matching scalars slot must be null.

      Parameters:
      scalars - scalar bindings; scalars[i] is the Element bound to variable index i, or null. Its length is the row size().
      groups - group edge-variable bindings from variable index to the ordered edges of the walk; use an empty map when the row has no group variables
      Returns:
      the new row
      Throws:
      NullPointerException - if scalars, groups, a key of groups, a group list, or an edge in a group list is null
      IllegalArgumentException - if a group index is outside [0, scalars.length), the same index also has a non-null scalar binding, or a group list is empty
    • size

      public int size()
      Returns the number of variable indices in this row, equal to the length of the scalar array the row was built from.
    • getScalar

      public Element getScalar(int index)
      Returns the scalar Element bound to the variable index, or null if the index is unbound or holds a group.
      Throws:
      IndexOutOfBoundsException - if index is outside [0, size())
    • getGroup

      public List<Edge> getGroup(int index)
      Returns the unmodifiable, ordered edge list bound to the variable index, or null if the index is unbound or holds a scalar.
      Throws:
      IndexOutOfBoundsException - if index is outside [0, size())
    • isGroup

      public boolean isGroup(int index)
      Returns true if the variable index holds a group (edge list) binding.
      Throws:
      IndexOutOfBoundsException - if index is outside [0, size())
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object