Add vertices to the graph, and return a new graph. Args: vertices (Union[str, Loader]): Vertex data source. label (str, optional): Vertex label name. Defaults to "_". properties (list[str], optional): List of column names loaded as properties. Defaults to
(
self, vertices, label="_", properties=None, vid_field: Union[int, str] = 0
)
| 475 | return graph_dag_node |
| 476 | |
| 477 | def add_vertices( |
| 478 | self, vertices, label="_", properties=None, vid_field: Union[int, str] = 0 |
| 479 | ): |
| 480 | """Add vertices to the graph, and return a new graph. |
| 481 | |
| 482 | Args: |
| 483 | vertices (Union[str, Loader]): Vertex data source. |
| 484 | label (str, optional): Vertex label name. Defaults to "_". |
| 485 | properties (list[str], optional): List of column names loaded as properties. Defaults to None. |
| 486 | vid_field (int or str, optional): Column index or property name used as id field. Defaults to 0. |
| 487 | |
| 488 | Raises: |
| 489 | ValueError: If the given value is invalid or conflict with current graph. |
| 490 | |
| 491 | Returns: |
| 492 | :class:`graphscope.framework.graph.GraphDAGNode`: |
| 493 | A new graph with vertex added, evaluated in eager mode. |
| 494 | """ |
| 495 | if self._vertex_map == graph_def_pb2.LOCAL_VERTEX_MAP: |
| 496 | raise ValueError( |
| 497 | "Cannot incrementally add vertices to graphs with local vertex map, " |
| 498 | "please use `graphscope.load_from()` instead." |
| 499 | ) |
| 500 | if self._compact_edges: |
| 501 | raise ValueError( |
| 502 | "Cannot incrementally add vertices to graphs with compacted edges, " |
| 503 | "please use `graphscope.load_from()` instead." |
| 504 | ) |
| 505 | if not self._v_labels and self._e_labels: |
| 506 | raise ValueError("Cannot manually add vertices after inferred vertices.") |
| 507 | # currently not support local_vertex_map |
| 508 | if label in self._v_labels: |
| 509 | self._extend_label_data = 1 |
| 510 | warnings.warn( |
| 511 | f"Label {label} already existed in graph" |
| 512 | ", origin label data will be extend." |
| 513 | ) |
| 514 | unsealed_vertices_and_edges = deepcopy(self._unsealed_vertices_and_edges) |
| 515 | vertex_label = VertexLabel( |
| 516 | label=label, |
| 517 | loader=vertices, |
| 518 | properties=properties, |
| 519 | vid_field=vid_field, |
| 520 | id_type=self._oid_type, |
| 521 | session_id=self._session.session_id, |
| 522 | ) |
| 523 | unsealed_vertices_and_edges.append((self.op.key, vertex_label)) |
| 524 | v_labels = deepcopy(self._v_labels) |
| 525 | if self._extend_label_data == 0: |
| 526 | v_labels.append(label) |
| 527 | # generate and add a loader op to dag |
| 528 | loader_op = dag_utils.create_loader(vertex_label) |
| 529 | self._session.dag.add_op(loader_op) |
| 530 | # construct add label op |
| 531 | op = dag_utils.add_labels_to_graph(self, loader_op) |
| 532 | # construct dag node |
| 533 | graph_dag_node = GraphDAGNode( |
| 534 | self._session, |
nothing calls this directly
no test coverage detected