Load a ArrowProperty graph from a certain data source. The data source can be vineyard serialized files, graphar serialized files, or other data sources supported by graphscope. Args: uri (str): URI contains the description of the data source or p
(cls, uri, sess=None, **kwargs)
| 1191 | |
| 1192 | @classmethod |
| 1193 | def load_from(cls, uri, sess=None, **kwargs): |
| 1194 | """Load a ArrowProperty graph from a certain data source. The data source |
| 1195 | can be vineyard serialized files, graphar serialized files, or other data |
| 1196 | sources supported by graphscope. |
| 1197 | |
| 1198 | Args: |
| 1199 | uri (str): URI contains the description of the data source or |
| 1200 | path contains the serialization files, |
| 1201 | example: "graphar+file:///tmp/graphar/xxx" |
| 1202 | sess (`graphscope.Session`): The target session that the graph |
| 1203 | will be construct, if None, use the default session. |
| 1204 | selector (dict, optional): the selector to select the data to read. |
| 1205 | graphar_store_in_local (bool, optional): whether store graphar format in local, default is False. |
| 1206 | Returns: |
| 1207 | `Graph`: A new graph object. |
| 1208 | """ |
| 1209 | from graphscope.client.session import get_default_session |
| 1210 | |
| 1211 | def _check_load_options(load_options): |
| 1212 | for k, v in load_options.items(): |
| 1213 | if k == "selector": |
| 1214 | if not isinstance(v, dict): |
| 1215 | raise ValueError( |
| 1216 | "selector should be a dict, but got {}".format(type(v)) |
| 1217 | ) |
| 1218 | elif k == "graphar_store_in_local": |
| 1219 | if not isinstance(v, bool): |
| 1220 | raise ValueError( |
| 1221 | "graphar_store_in_local should be a bool, but got {}".format( |
| 1222 | v |
| 1223 | ) |
| 1224 | ) |
| 1225 | |
| 1226 | if sess is None: |
| 1227 | sess = get_default_session() |
| 1228 | uri_str = uri |
| 1229 | uri = urlparse(uri) |
| 1230 | if uri.scheme and "+" in uri.scheme: |
| 1231 | source = uri.scheme.split("+")[0] |
| 1232 | if uri.scheme.split("+")[-1] not in ["file", "s3", "oss", "hdfs"]: |
| 1233 | raise ValueError( |
| 1234 | "Unknown file system %s, currently only support file, s3, oss and hdfs" |
| 1235 | % uri.scheme.split("+")[-1] |
| 1236 | ) |
| 1237 | path = uri.scheme.split("+")[-1] + "://" + uri.netloc + uri.path |
| 1238 | if source == "graphar": |
| 1239 | _check_load_options(kwargs) |
| 1240 | return cls._load_from_graphar(path, sess, **kwargs) |
| 1241 | else: |
| 1242 | raise ValueError("Unknown source %s with uri $s:" % source, uri_str) |
| 1243 | else: |
| 1244 | # not a uri string, assume it is a path for deserialization |
| 1245 | op = dag_utils.deserialize_graph(uri_str, sess, **kwargs) |
| 1246 | return sess._wrapper(GraphDAGNode(sess, op)) |
| 1247 | |
| 1248 | def save_to( |
| 1249 | self, |