Ejemplo n.º 1
0
 def __init__(self, parent: GraphTraversal, key: str, value: Any):
     UnaryTraversal.__init__(self, parent)
     if isinstance(value, ColumnPredicate):
         self._pred = value
     else:
         # Not a predicate ==> Transform to "vertex[key] == value"
         self._pred = Within(value)
     self._pred.modulate(iter(itertools.repeat(key)))
Ejemplo n.º 2
0
 def __init__(self, parent: GraphTraversal,
              subqueries: Sequence[GraphTraversal]):
     """
     :param parent: Input to the `coalesce` step
     :param subqueries: Sub-traversals to run in this step.
     """
     UnaryTraversal.__init__(self, parent)
     for s in subqueries:
         found_double_underscore, _ = find_double_underscore(s)
         if not found_double_underscore:
             raise NotImplementedError("union without __ not implemented")
     self._subqueries = subqueries
Ejemplo n.º 3
0
 def __init__(self, parent: GraphTraversal, selected_aliases: Tuple[str]):
     """
     :param parent: Previous element of the traversal
     :param selected_aliases: List of aliases mentioned as direct arguments
         to `select()`
     """
     UnaryTraversal.__init__(self, parent)
     if 0 == len(selected_aliases):
         raise ValueError("Must select at least one alias")
     self._selected_aliases = selected_aliases
     # List to be populated by self.by()
     self._by_list = []  # Type: List[str]
     # DataFrame or Series representation of the last element of self.paths
     self._paths_tail = None  # Type: Union[pd.DataFrame, pd.Series]
Ejemplo n.º 4
0
    def __init__(self, parent: GraphTraversal, groups: Sequence[str],
                 aggregates: Sequence[Tuple[str, str, str]]):
        """
        See `GraphTraversal.groupBy()` for parameter info.
        """
        all_agg_aliases = set([a[2] for a in aggregates])
        if len(all_agg_aliases.intersection(groups)) > 0:
            raise ValueError(f"Grouping keys and aggregate names contain "
                             f"duplicate names: "
                             f"{all_agg_aliases.intersection(groups)}")

        UnaryTraversal.__init__(self, parent)
        self._groups = groups
        self._aggregates = aggregates
Ejemplo n.º 5
0
    def __init__(self, parent: GraphTraversal, value: Any, step_type: str):
        """
        :param parent: Traversal that produces inputs to this one

        :param value: Constant value that is appended to all paths on the input
        of this traversal.

        :param step_type: Element type string that is appended to the
        `step_types` output of this step. See `step_types` for more
        information.
        """
        UnaryTraversal.__init__(self, parent)
        # TODO: Validate that value and step_type are compatible and raise
        #  an error here instead of downstream if there is a problem.
        self._value = value
        self._step_type = step_type
Ejemplo n.º 6
0
 def __init__(self, parent: GraphTraversal, names: Tuple[str]):
     UnaryTraversal.__init__(self, parent)
     self._names = names
Ejemplo n.º 7
0
 def __init__(self, parent: GraphTraversal, field_name: str):
     UnaryTraversal.__init__(self, parent)
     self._field_name = field_name
Ejemplo n.º 8
0
 def __init__(self, parent: GraphTraversal):
     UnaryTraversal.__init__(self, parent)
Ejemplo n.º 9
0
    def __init__(self,
                 parent: GraphTraversal,
                 loop_body: GraphTraversal = None,
                 emit_pred: VertexPredicate = None,
                 until_pred: VertexPredicate = None):
        """
        This initializer is called from `repeat()`, `emit()`, and `until()`.
        Note that `emit` and `until` modulators can come before `repeat`.

        :param parent: Previous step in the traversal
        :param loop_body: Argument to the `repeat` step if called from the
        `repeat` step itself; otherwise `None`.
        :param emit_pred: Argument to the `emit` modulator, if present;
        otherwise None.
        :param until_pred: Argument to the `until` modulator, if present;
        otherwise None.
        """
        # Look at earlier steps for information about the pieces of the repeat
        # step.
        prev_loop_body = prev_emit_pred = prev_until_pred = None
        non_repeat_parent = parent  # Last step before entire repeat "clause"
        if isinstance(parent, RepeatTraversal):
            prev_loop_body = parent._loop_body
            prev_emit_pred = parent._init_emit_pred
            prev_until_pred = parent._init_until_pred
            while isinstance(non_repeat_parent, RepeatTraversal):
                non_repeat_parent = non_repeat_parent.parent

        # Note that we initialize the parent pointer to the step before the
        # entire repeat "clause".
        UnaryTraversal.__init__(self, non_repeat_parent)

        self._loop_body = \
            self._non_null_value(loop_body, prev_loop_body, "loop body")
        self._init_emit_pred = \
            self._non_null_value(emit_pred, prev_emit_pred, "emit predicate")
        self._init_until_pred = \
            self._non_null_value(until_pred, prev_until_pred, "until predicate")

        # Convert None in any of the predicate fields to default value for the
        # purposes of self.compute()
        self._emit_pred = (self._init_emit_pred if self._init_emit_pred
                           is not None else FalsePredicate())
        self._until_pred = (self._until_pred if self._init_until_pred
                            is not None else TruePredicate())

        # The semantics of repeat() are different depending on whether the emit
        # and until modulators come before or after.
        if loop_body is None and prev_loop_body is None:
            # No loop body at this point or before.
            self._emit_before_repeat = None
            self._until_before_repeat = None
        elif loop_body is None and prev_loop_body is not None:
            # Modulator that comes comes after the repeat step
            self._emit_before_repeat = parent._emit_before_repeat
            self._until_before_repeat = parent._until_before_repeat
        elif loop_body is not None:
            # The repeat step itself
            self._emit_before_repeat = (prev_emit_pred is not None)
            self._until_before_repeat = (prev_until_pred is not None)
        else:
            raise ValueError("This code should be unreachable")
Ejemplo n.º 10
0
 def __init__(self, parent: GraphTraversal, edge_types: Tuple[str]):
     UnaryTraversal.__init__(self, parent)
     self._edge_types = edge_types
Ejemplo n.º 11
0
 def __init__(self, parent):
     UnaryTraversal.__init__(self, parent)
     self._key = None  # Type: str
     self._value = None  # Type: AggregateTraversal
Ejemplo n.º 12
0
 def __init__(self, parent):
     UnaryTraversal.__init__(self, parent)
Ejemplo n.º 13
0
 def __init__(self, parent: GraphTraversal, pred: "VertexPredicate"):
     UnaryTraversal.__init__(self, parent)
     self._pred = pred
     self._by_args = []
Ejemplo n.º 14
0
 def __init__(self, parent: GraphTraversal, subquery: GraphTraversal):
     UnaryTraversal.__init__(self, parent)
     self._subquery = subquery