MCPcopy Create free account
hub / github.com/alibaba/GraphScope / add_labels_to_graph

Function add_labels_to_graph

python/graphscope/framework/dag_utils.py:177–229  ·  view source on GitHub ↗

Add new labels to existed graph. Args: graph (:class:`Graph`): A graph instance. May not be fully loaded. i.e. it's in a building procedure. loader_op (:class:`graphscope.framework.operation.Operation`): Operation of loader. Raises:

(graph, loader_op)

Source from the content-addressed store, hash-verified

175
176
177def add_labels_to_graph(graph, loader_op):
178 """Add new labels to existed graph.
179
180 Args:
181 graph (:class:`Graph`): A graph instance.
182 May not be fully loaded. i.e. it's in a building
183 procedure.
184 loader_op (:class:`graphscope.framework.operation.Operation`):
185 Operation of loader.
186
187 Raises:
188 NotImplementedError: When encountered not supported graph type.
189
190 Returns:
191 The operation.
192
193 Notes:
194 Since we don't want to trigger the loading, we must not use
195 any api that can trigger the loading process implicitly.
196 """
197 from graphscope.framework.graph import GraphDAGNode
198
199 assert isinstance(graph, GraphDAGNode)
200 inputs = [graph.op, loader_op]
201 # vid_type is fixed
202 config = {
203 types_pb2.GRAPH_TYPE: utils.graph_type_to_attr(graph._graph_type),
204 types_pb2.DIRECTED: utils.b_to_attr(graph._directed),
205 types_pb2.EXTEND_LABEL_DATA: utils.i_to_attr(graph._extend_label_data),
206 types_pb2.OID_TYPE: utils.s_to_attr(graph._oid_type),
207 types_pb2.VID_TYPE: utils.s_to_attr(graph._vid_type),
208 types_pb2.GENERATE_EID: utils.b_to_attr(graph._generate_eid),
209 types_pb2.RETAIN_OID: utils.b_to_attr(graph._retain_oid),
210 types_pb2.VERTEX_MAP_TYPE: utils.i_to_attr(graph._vertex_map),
211 types_pb2.COMPACT_EDGES: utils.b_to_attr(graph._compact_edges),
212 types_pb2.USE_PERFECT_HASH: utils.b_to_attr(graph._use_perfect_hash),
213 types_pb2.IS_FROM_VINEYARD_ID: utils.b_to_attr(False),
214 types_pb2.IS_FROM_GAR: utils.b_to_attr(False),
215 }
216 # inferred from the context of the dag.
217 config.update({types_pb2.GRAPH_NAME: utils.s_to_attr("")})
218 if graph._graph_type != graph_def_pb2.ARROW_PROPERTY:
219 raise NotImplementedError(
220 f"Add vertices or edges is not supported yet on graph type {graph._graph_type}"
221 )
222 op = Operation(
223 graph._session.session_id,
224 types_pb2.ADD_LABELS,
225 inputs=inputs,
226 config=config,
227 output_types=types_pb2.GRAPH,
228 )
229 return op
230
231
232def consolidate_columns(

Callers

nothing calls this directly

Calls 2

OperationClass · 0.90
updateMethod · 0.45

Tested by

no test coverage detected