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

Class _FetchHandler

python/graphscope/client/session.py:83–213  ·  view source on GitHub ↗

Handler for structured fetches. This class takes care of extracting a sub-DAG as targets for a user-provided structure for fetches, which can be used for a low level `run` call of grpc_client. Given the results of the low level run call, this class can also rebuild a result structure ma

Source from the content-addressed store, hash-verified

81
82
83class _FetchHandler(object):
84 """Handler for structured fetches.
85 This class takes care of extracting a sub-DAG as targets for a user-provided structure for fetches,
86 which can be used for a low level `run` call of grpc_client.
87
88 Given the results of the low level run call, this class can also rebuild a result structure matching
89 the user-provided structure for fetches, but containing the corresponding results.
90 """
91
92 def __init__(self, dag, fetches):
93 self._fetches = fetches
94 self._ops = list()
95 self._unpack = False
96 if not isinstance(self._fetches, (list, tuple)):
97 self._fetches = [self._fetches]
98 self._unpack = True
99 for fetch in self._fetches:
100 if hasattr(fetch, "op"):
101 fetch = fetch.op
102 if not isinstance(fetch, Operation):
103 raise ValueError("Expect an `Operation` in sess run method.")
104 self._ops.append(fetch)
105 # extract sub dag
106 self._sub_dag = dag.extract_subdag_for(self._ops)
107 if "GRAPHSCOPE_DEBUG" in os.environ:
108 logger.info("sub_dag: %s", self._sub_dag)
109
110 @property
111 def targets(self):
112 return self._sub_dag
113
114 def _rebuild_graph(self, seq, op_result: op_def_pb2.OpResult):
115 if isinstance(self._fetches[seq], Operation):
116 # for nx Graph
117 return op_result.graph_def
118 # get graph dag node as base
119 graph_dag_node = self._fetches[seq]
120 # construct graph
121 g = Graph(graph_dag_node)
122 # update graph flied from graph_def
123 g.update_from_graph_def(op_result.graph_def)
124 return g
125
126 def _rebuild_app(self, seq, op_result: op_def_pb2.OpResult):
127 from graphscope.framework.app import App
128
129 # get app dag node as base
130 app_dag_node = self._fetches[seq]
131 # construct app
132 app = App(app_dag_node, op_result.result.decode("utf-8", errors="ignore"))
133 return app
134
135 def _rebuild_context(self, seq, op_result: op_def_pb2.OpResult):
136 from graphscope.framework.context import Context
137
138 # get context dag node as base
139 context_dag_node = self._fetches[seq]
140 ret = json.loads(op_result.result.decode("utf-8", errors="ignore"))

Callers 1

run_fetchesMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected