Skip to content

Commit 757fcbd

Browse files
committed
Support string oid for graphar
Committed-by: acezen from Dev container
1 parent 54ddef3 commit 757fcbd

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

python/graphscope/framework/dag_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ def gremlin_to_subgraph(
10281028
return op
10291029

10301030

1031-
def archive_graph(graph, path):
1031+
def save_to_graphar(graph, path):
10321032
"""Archive a graph to gar format with a path.
10331033
10341034
Args:

python/graphscope/framework/graph.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1074,9 +1074,10 @@ def _check_unmodified(self):
10741074
def _load_from_graphar(path, sess, **kwargs):
10751075
# graphar now only support global vertex map.
10761076
vertex_map = utils.vertex_map_type_to_enum("global")
1077+
oid_type = utils.get_oid_type_from_graph_info(path)
10771078
config = {
10781079
types_pb2.OID_TYPE: utils.s_to_attr(
1079-
"int64_t"
1080+
oid_type
10801081
), # grahar use vertex index as oid, so it always be int64_t
10811082
types_pb2.VID_TYPE: utils.s_to_attr("uint64_t"),
10821083
types_pb2.IS_FROM_VINEYARD_ID: utils.b_to_attr(False),

python/graphscope/framework/utils.py

+33
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,36 @@ def PbDataType2InfoType(str):
803803
with open(graph_info_path, "w") as f:
804804
yaml.dump(graph_info, f, Dumper=Dumper, default_flow_style=False)
805805
return graph_info_path
806+
807+
def get_oid_type_from_graph_info(path):
808+
if "file://" in path:
809+
path = path.replace("file://", "")
810+
with open(path, "r") as f:
811+
graph_info = yaml.safe_load(f)
812+
if "vertices" not in graph_info:
813+
raise ValueError("Invalid graph info file, no vertices found.")
814+
vertex_info_path = graph_info["vertices"][0]
815+
if "prefix" in graph_info:
816+
prefix = graph_info["prefix"]
817+
else:
818+
prefix = os.path.dirname(path)
819+
with open(os.path.join(prefix, vertex_info_path), "r") as f:
820+
vertex_info = yaml.safe_load(f)
821+
property_groups = vertex_info["property_groups"]
822+
if len(property_groups) == 0:
823+
raise ValueError("Invalid vertex info file, no property groups found.")
824+
data_type = None
825+
for property_group in property_groups:
826+
properties = property_group["properties"]
827+
if len(properties) == 0:
828+
raise ValueError("Invalid vertex info file, no properties found.")
829+
for property in properties:
830+
if property["is_primary"]:
831+
data_type = property["data_type"]
832+
break
833+
if data_type == "int64":
834+
return "int64_t"
835+
elif data_type == "string":
836+
return "std::string"
837+
else:
838+
raise ValueError("Invalid vertex info file, primary key is not int64 or string.")

0 commit comments

Comments
 (0)