def update_from_graph_def(self, graph_def): if graph_def.graph_type == graph_def_pb2.ARROW_FLATTENED: self._graph_node._graph_type = graph_def_pb2.ARROW_FLATTENED check_argument( self._graph_node.graph_type == graph_def.graph_type, "Graph type doesn't match {} versus {}".format( self._graph_node.graph_type, graph_def.graph_type ), ) self._key = graph_def.key self._directed = graph_def.directed self._is_multigraph = graph_def.is_multigraph vy_info = graph_def_pb2.VineyardInfoPb() graph_def.extension.Unpack(vy_info) self._vineyard_id = vy_info.vineyard_id self._oid_type = data_type_to_cpp(vy_info.oid_type) self._generate_eid = vy_info.generate_eid self._schema_path = vy_info.schema_path self._schema.from_graph_def(graph_def) self._v_labels = self._schema.vertex_labels self._e_labels = self._schema.edge_labels self._e_relationships = self._schema.edge_relationships # init saved_signature (must be after init schema) self._saved_signature = self.signature # create gremlin server pod asynchronously if self._session.eager() and gs_config.initializing_interactive_engine: self._interactive_instance_launching_thread = threading.Thread( target=self._launch_interactive_instance_impl, args=() ) self._interactive_instance_launching_thread.start()
def _from_vineyard(self, graph_def): vy_info = graph_def_pb2.VineyardInfoPb() graph_def.extension.Unpack(vy_info) self._oid_type = vy_info.oid_type self._vid_type = vy_info.vid_type # simple graph schema. if vy_info.vdata_type: self._vdata_type = unify_type(vy_info.vdata_type) if vy_info.edata_type: self._edata_type = unify_type(vy_info.edata_type) # property graph schema if vy_info.property_schema_json: try: schema = json.loads(vy_info.property_schema_json) if schema: for item in schema["types"]: def add_common_attributes(entry, item): for prop in item["propertyDefList"]: entry.add_property( prop["name"], unify_type(prop["data_type"])) entry._valid_props = item["valid_properties"] if item["type"] == "VERTEX": entry = VertexLabel(item["label"], item["id"]) assert entry.id == len(self._vertex_labels) add_common_attributes(entry, item) self._vertex_labels.append(entry) self._v_label_index[entry.label] = entry.id elif item["type"] == "EDGE": entry = EdgeLabel(item["label"], item["id"]) assert entry.id == len(self._edge_labels) for rel in item["rawRelationShips"]: entry.source( rel["srcVertexLabel"]).destination( rel["dstVertexLabel"]) add_common_attributes(entry, item) self._edge_labels.append(entry) self._e_label_index[entry.label] = entry.id self._valid_vertices = schema["valid_vertices"] self._valid_edges = schema["valid_edges"] except Exception as e: raise ValueError("Invalid property graph schema") from e return self