Beispiel #1
0
    def _resolve_op(self, incoming_data):
        # Don't import the :code:`NXGraph` in top-level statements to improve the
        # performance of :code:`import graphscope`.
        from graphscope import nx

        if incoming_data is None:
            # create dag node of empty graph
            self._op = self._construct_op_of_empty_graph()
        elif isinstance(incoming_data, Operation):
            self._op = incoming_data
            if self._op.type == types_pb2.PROJECT_TO_SIMPLE:
                self._graph_type = graph_def_pb2.ARROW_PROJECTED
        elif isinstance(incoming_data, nx.classes.graph._GraphBase):
            self._op = self._from_nx_graph(incoming_data)
        elif isinstance(incoming_data, Graph):
            self._op = dag_utils.copy_graph(incoming_data)
            self._graph_type = incoming_data.graph_type
        elif isinstance(incoming_data, GraphDAGNode):
            if incoming_data.session_id != self.session_id:
                raise RuntimeError("{0} not in the same session.".formar(incoming_data))
            raise NotImplementedError
        elif vineyard is not None and isinstance(
            incoming_data, (vineyard.Object, vineyard.ObjectID, vineyard.ObjectName)
        ):
            self._op = self._from_vineyard(incoming_data)
        else:
            raise RuntimeError("Not supported incoming data.")
Beispiel #2
0
    def _copy_from(self, incoming_graph):
        """Copy a graph.

        Args:
            incoming_graph (:class:`Graph`): Source graph to be copied from

        Returns:
            :class:`Graph`: An identical graph, but with a new vineyard id.
        """
        check_argument(incoming_graph.graph_type == types_pb2.ARROW_PROPERTY)
        check_argument(incoming_graph.loaded())
        return dag_utils.copy_graph(incoming_graph)
Beispiel #3
0
    def reverse(self, copy=True):
        self._convert_arrow_to_dynamic()

        if not copy:
            g = reverse_view(self)
            g._op = self._op
            g._key = self._key
            g._schema = deepcopy(self._schema)
            g._is_client_view = True
        else:
            g = self.__class__(create_empty_in_engine=False)
            g.graph = self.graph
            g.name = self.name
            op = copy_graph(self, "reverse")
            g._op = op
            graph_def = op.eval(leaf=False)
            g._key = graph_def.key
            g.cache.warmup()
        g._session = self._session
        return g
Beispiel #4
0
    def reverse(self, copy=True):
        """Returns the reverse of the graph.

        The reverse is a graph with the same nodes and edges
        but with the directions of the edges reversed.

        Parameters
        ----------
        copy : bool optional (default=True)
            If True, return a new DiGraph holding the reversed edges.
            If False, the reverse graph is created using a view of
            the original graph.
        """
        if not copy:
            return reverse_view(self)
        g = self.__class__(create_empty_in_engine=False)
        g.graph = self.graph
        g.name = self.name
        g._op = self._op
        op = copy_graph(self, "reverse")
        graph_def = op.eval()
        g._key = graph_def.key
        g._schema = deepcopy(self._schema)
        return g