24 #include <unordered_map> 
   27 #include "graphar/fwd.h" 
   37   std::shared_ptr<DataType> type;  
 
   45   explicit Property(
const std::string& name,
 
   46                     const std::shared_ptr<DataType>& type = 
nullptr,
 
   47                     bool is_primary = 
false, 
bool is_nullable = 
true,
 
   48                     Cardinality cardinality = Cardinality::SINGLE)
 
   51         is_primary(is_primary),
 
   52         is_nullable(!is_primary && is_nullable),
 
   53         cardinality(cardinality) {}
 
   76   explicit PropertyGroup(
const std::vector<Property>& properties,
 
   77                          FileType file_type, 
const std::string& prefix = 
"");
 
   86   bool HasProperty(
const std::string& property_name) 
const;
 
   98   inline const std::string& 
GetPrefix()
 const { 
return prefix_; }
 
  105   friend std::ostream& operator<<(std::ostream& stream,
 
  107     for (
size_t i = 0; i < pg.properties_.size(); ++i) {
 
  108       stream << pg.properties_[i].name;
 
  109       if (i != pg.properties_.size() - 1) {
 
  117   std::vector<Property> properties_;
 
  122 bool operator==(
const PropertyGroup& lhs, 
const PropertyGroup& rhs);
 
  138   explicit AdjacentList(AdjListType type, FileType file_type,
 
  139                         const std::string& prefix = 
"");
 
  146   inline AdjListType 
GetType()
 const { 
return type_; }
 
  160   inline const std::string& 
GetPrefix()
 const { 
return prefix_; }
 
  194   explicit VertexInfo(
const std::string& type, IdType chunk_size,
 
  195                       const PropertyGroupVector& property_groups,
 
  196                       const std::vector<std::string>& labels = {},
 
  197                       const std::string& prefix = 
"",
 
  198                       std::shared_ptr<const InfoVersion> 
version = 
nullptr);
 
  208       std::shared_ptr<PropertyGroup> property_group) 
const;
 
  218       std::shared_ptr<PropertyGroup> property_group) 
const;
 
  225   const std::string& 
GetType() 
const;
 
  246   const std::shared_ptr<const InfoVersion>& 
version() 
const;
 
  252   const std::vector<std::string>& 
GetLabels() 
const;
 
  273       const std::string& property_name) 
const;
 
  291       const std::string& property_name) 
const;
 
  293   Result<Cardinality> GetPropertyCardinality(
 
  294       const std::string& property_name) 
const;
 
  301   bool HasProperty(
const std::string& property_name) 
const;
 
  309   Status Save(
const std::string& file_name) 
const;
 
  317   Result<std::string> 
Dump() 
const noexcept;
 
  325   bool IsPrimaryKey(
const std::string& property_name) 
const;
 
  343       const std::shared_ptr<PropertyGroup>& property_group) 
const;
 
  353   Result<std::string> 
GetFilePath(std::shared_ptr<PropertyGroup> property_group,
 
  354                                   IdType chunk_index) 
const;
 
  364       std::shared_ptr<PropertyGroup> property_group) 
const;
 
  387   static Result<std::shared_ptr<VertexInfo>> 
Load(std::shared_ptr<Yaml> yaml);
 
  395   static Result<std::shared_ptr<VertexInfo>> 
Load(
const std::string& input);
 
  399   std::unique_ptr<Impl> impl_;
 
  427   explicit EdgeInfo(
const std::string& src_type, 
const std::string& edge_type,
 
  428                     const std::string& dst_type, IdType chunk_size,
 
  429                     IdType src_chunk_size, IdType dst_chunk_size, 
bool directed,
 
  430                     const AdjacentListVector& adjacent_lists,
 
  431                     const PropertyGroupVector& property_groups,
 
  432                     const std::string& prefix = 
"",
 
  433                     std::shared_ptr<const InfoVersion> 
version = 
nullptr);
 
  445       std::shared_ptr<AdjacentList> adj_list) 
const;
 
  455       std::shared_ptr<AdjacentList> adj_list) 
const;
 
  463       std::shared_ptr<PropertyGroup> property_group) 
const;
 
  473       std::shared_ptr<PropertyGroup> property_group) 
const;
 
  527   const std::shared_ptr<const InfoVersion>& 
version() 
const;
 
  544   bool HasProperty(
const std::string& property_name) 
const;
 
  550       const std::shared_ptr<PropertyGroup>& property_group) 
const;
 
  552   std::shared_ptr<AdjacentList> GetAdjacentList(
 
  553       AdjListType adj_list_type) 
const;
 
  573       const std::string& property) 
const;
 
  601                                           AdjListType adj_list_type) 
const;
 
  611                                          IdType edge_chunk_index,
 
  612                                          AdjListType adj_list_type) 
const;
 
  631                                                AdjListType adj_list_type) 
const;
 
  653       const std::shared_ptr<PropertyGroup>& property_group,
 
  654       AdjListType adj_list_type, IdType vertex_chunk_index,
 
  655       IdType edge_chunk_index) 
const;
 
  666       const std::shared_ptr<PropertyGroup>& property_group,
 
  667       AdjListType adj_list_type) 
const;
 
  677       const std::string& property_name) 
const;
 
  684   bool IsPrimaryKey(
const std::string& property_name) 
const;
 
  700   Status Save(
const std::string& file_name) 
const;
 
  708   Result<std::string> 
Dump() 
const noexcept;
 
  718   static Result<std::shared_ptr<EdgeInfo>> 
Load(std::shared_ptr<Yaml> yaml);
 
  726   static Result<std::shared_ptr<EdgeInfo>> 
Load(
const std::string& input);
 
  730   std::unique_ptr<Impl> impl_;
 
  750       const std::string& graph_name, VertexInfoVector vertex_infos,
 
  751       EdgeInfoVector edge_infos, 
const std::vector<std::string>& labels = {},
 
  752       const std::string& prefix = 
"./",
 
  753       std::shared_ptr<const InfoVersion> 
version = 
nullptr,
 
  754       const std::unordered_map<std::string, std::string>& extra_info = {});
 
  764   static Result<std::shared_ptr<GraphInfo>> 
Load(
const std::string& path);
 
  773   static Result<std::shared_ptr<GraphInfo>> 
Load(
 
  774       const std::string& input, 
const std::string& relative_path);
 
  784   Result<std::shared_ptr<GraphInfo>> 
AddVertex(
 
  785       std::shared_ptr<VertexInfo> vertex_info) 
const;
 
  795       std::shared_ptr<VertexInfo> vertex_info) 
const;
 
  805   Result<std::shared_ptr<GraphInfo>> 
AddEdge(
 
  806       std::shared_ptr<EdgeInfo> edge_info) 
const;
 
  815   Result<std::shared_ptr<GraphInfo>> 
RemoveEdge(
 
  816       std::shared_ptr<EdgeInfo> edge_info) 
const;
 
  822   const std::string& 
GetName() 
const;
 
  828   const std::vector<std::string>& 
GetLabels() 
const;
 
  841   const std::shared_ptr<const InfoVersion>& 
version() 
const;
 
  848   const std::unordered_map<std::string, std::string>& 
GetExtraInfo() 
const;
 
  855   std::shared_ptr<VertexInfo> 
GetVertexInfo(
const std::string& type) 
const;
 
  865   std::shared_ptr<EdgeInfo> 
GetEdgeInfo(
const std::string& src_type,
 
  866                                         const std::string& edge_type,
 
  867                                         const std::string& dst_type) 
const;
 
  879                        const std::string& edge_type,
 
  880                        const std::string& dst_type) 
const;
 
  936   Result<std::string> 
Dump() 
const;
 
  947   std::unique_ptr<Impl> impl_;
 
const std::string & GetPrefix() const
Get the prefix of adjacent list.
 
FileType GetFileType() const
Get the file type of adjacent list.
 
AdjListType GetType() const
Get the type of adjacent list.
 
AdjacentList(AdjListType type, FileType file_type, const std::string &prefix="")
 
EdgeInfo is a class to describe the edge information, including the source vertex type,...
 
const std::string & GetEdgeType() const
 
static Result< std::shared_ptr< EdgeInfo > > Load(std::shared_ptr< Yaml > yaml)
 
Result< std::string > GetAdjListFilePath(IdType vertex_chunk_index, IdType edge_chunk_index, AdjListType adj_list_type) const
Get the file path of adj list topology chunk.
 
Status Save(const std::string &file_name) const
 
Result< std::shared_ptr< EdgeInfo > > RemovePropertyGroup(std::shared_ptr< PropertyGroup > property_group) const
Removes a property group from the EdgeInfo instance and returns a new EdgeInfo.
 
Result< std::shared_ptr< DataType > > GetPropertyType(const std::string &property_name) const
 
const std::string & GetPrefix() const
 
Result< std::string > GetEdgesNumFilePath(IdType vertex_chunk_index, AdjListType adj_list_type) const
 
Result< std::string > GetPropertyGroupPathPrefix(const std::shared_ptr< PropertyGroup > &property_group, AdjListType adj_list_type) const
 
bool IsPrimaryKey(const std::string &property_name) const
 
Result< std::string > GetAdjListOffsetFilePath(IdType vertex_chunk_index, AdjListType adj_list_type) const
Get the adjacency list offset chunk file path of vertex chunk the offset chunks is aligned with the v...
 
IdType GetChunkSize() const
 
bool HasProperty(const std::string &property_name) const
Returns whether the edge info contains the given property.
 
Result< std::shared_ptr< EdgeInfo > > AddAdjacentList(std::shared_ptr< AdjacentList > adj_list) const
 
Result< std::shared_ptr< EdgeInfo > > RemoveAdjacentList(std::shared_ptr< AdjacentList > adj_list) const
Removes an adjacency list from the EdgeInfo instance and returns a new EdgeInfo.
 
Result< std::string > Dump() const noexcept
 
bool IsNullableKey(const std::string &property_name) const
 
std::shared_ptr< PropertyGroup > GetPropertyGroupByIndex(int index) const
Get the property group at the specified index.
 
bool HasPropertyGroup(const std::shared_ptr< PropertyGroup > &property_group) const
Returns whether the edge info contains the given property group.
 
const std::shared_ptr< const InfoVersion > & version() const
 
Result< std::shared_ptr< EdgeInfo > > AddPropertyGroup(std::shared_ptr< PropertyGroup > property_group) const
 
const std::string & GetSrcType() const
 
bool HasAdjacentListType(AdjListType adj_list_type) const
 
Result< std::string > GetOffsetPathPrefix(AdjListType adj_list_type) const
 
Result< std::string > GetAdjListPathPrefix(AdjListType adj_list_type) const
Get the path prefix of the adjacency list topology chunk for the given adjacency list type.
 
EdgeInfo(const std::string &src_type, const std::string &edge_type, const std::string &dst_type, IdType chunk_size, IdType src_chunk_size, IdType dst_chunk_size, bool directed, const AdjacentListVector &adjacent_lists, const PropertyGroupVector &property_groups, const std::string &prefix="", std::shared_ptr< const InfoVersion > version=nullptr)
Construct an EdgeInfo object with the given information and property groups.
 
IdType GetDstChunkSize() const
 
Result< std::string > GetPropertyFilePath(const std::shared_ptr< PropertyGroup > &property_group, AdjListType adj_list_type, IdType vertex_chunk_index, IdType edge_chunk_index) const
Get the chunk file path of adj list property group the property group chunks is aligned with the adj ...
 
const std::string & GetDstType() const
 
IdType GetSrcChunkSize() const
 
const PropertyGroupVector & GetPropertyGroups() const
Get the property groups.
 
Result< std::string > GetVerticesNumFilePath(AdjListType adj_list_type) const
Get the file path for the number of vertices.
 
std::shared_ptr< PropertyGroup > GetPropertyGroup(const std::string &property) const
Get the property group containing the given property.
 
int PropertyGroupNum() const
Get the number of property groups.
 
int GetVertexInfoIndex(const std::string &type) const
Get the vertex info index with the given type.
 
const EdgeInfoVector & GetEdgeInfos() const
Get the edge infos of graph info.
 
GraphInfo(const std::string &graph_name, VertexInfoVector vertex_infos, EdgeInfoVector edge_infos, const std::vector< std::string > &labels={}, const std::string &prefix="./", std::shared_ptr< const InfoVersion > version=nullptr, const std::unordered_map< std::string, std::string > &extra_info={})
Constructs a GraphInfo instance.
 
Status Save(const std::string &path) const
 
const std::shared_ptr< VertexInfo > GetVertexInfoByIndex(int index) const
Get the vertex info at the specified index.
 
Result< std::shared_ptr< GraphInfo > > AddVertex(std::shared_ptr< VertexInfo > vertex_info) const
Adds a vertex info to the GraphInfo instance and returns a new GraphInfo.
 
const std::string & GetPrefix() const
Get the absolute path prefix of the chunk files.
 
static Result< std::shared_ptr< GraphInfo > > Load(const std::string &path)
Loads the input file as a GraphInfo instance.
 
Result< std::string > Dump() const
 
std::shared_ptr< EdgeInfo > GetEdgeInfo(const std::string &src_type, const std::string &edge_type, const std::string &dst_type) const
Get the edge info with the given source vertex type, edge type, and destination vertex type.
 
int EdgeInfoNum() const
Get the number of edge infos.
 
std::shared_ptr< VertexInfo > GetVertexInfo(const std::string &type) const
Get the vertex info with the given type.
 
const std::vector< std::string > & GetLabels() const
Get the vertex labels of the graph.
 
Result< std::shared_ptr< GraphInfo > > AddEdge(std::shared_ptr< EdgeInfo > edge_info) const
Adds an edge info to the GraphInfo instance and returns a new GraphInfo.
 
const VertexInfoVector & GetVertexInfos() const
Get the vertex infos of graph info.
 
const std::unordered_map< std::string, std::string > & GetExtraInfo() const
Get the extra metadata of the graph info object.
 
int GetEdgeInfoIndex(const std::string &src_type, const std::string &edge_type, const std::string &dst_type) const
Get the edge info index with the given source vertex type, edge type, and destination type.
 
int VertexInfoNum() const
Get the number of vertex infos.
 
const std::string & GetName() const
Get the name of the graph.
 
Result< std::shared_ptr< GraphInfo > > RemoveEdge(std::shared_ptr< EdgeInfo > edge_info) const
Removes an edge info from the GraphInfo instance and returns a new GraphInfo.
 
Result< std::shared_ptr< GraphInfo > > RemoveVertex(std::shared_ptr< VertexInfo > vertex_info) const
Removes a vertex info from the GraphInfo instance and returns a new GraphInfo.
 
const std::shared_ptr< const InfoVersion > & version() const
Get the version info of the graph info object.
 
const std::shared_ptr< EdgeInfo > GetEdgeInfoByIndex(int index) const
Get the edge info at the specified index.
 
const std::string & GetPrefix() const
 
FileType GetFileType() const
 
PropertyGroup(const std::vector< Property > &properties, FileType file_type, const std::string &prefix="")
 
const std::vector< Property > & GetProperties() const
 
Status outcome object (success or error)
 
VertexInfo is a class to describe the vertex information, including the vertex type,...
 
const std::string & GetType() const
 
std::shared_ptr< PropertyGroup > GetPropertyGroup(const std::string &property_name) const
 
Result< std::string > GetPathPrefix(std::shared_ptr< PropertyGroup > property_group) const
 
const std::vector< std::string > & GetLabels() const
 
IdType GetChunkSize() const
 
const std::shared_ptr< const InfoVersion > & version() const
 
Result< std::shared_ptr< VertexInfo > > AddPropertyGroup(std::shared_ptr< PropertyGroup > property_group) const
 
bool HasProperty(const std::string &property_name) const
 
bool HasPropertyGroup(const std::shared_ptr< PropertyGroup > &property_group) const
 
Result< std::string > GetFilePath(std::shared_ptr< PropertyGroup > property_group, IdType chunk_index) const
 
bool IsPrimaryKey(const std::string &property_name) const
 
int PropertyGroupNum() const
 
Result< std::shared_ptr< VertexInfo > > RemovePropertyGroup(std::shared_ptr< PropertyGroup > property_group) const
Removes a property group from the VertexInfo instance and returns a new VertexInfo.
 
const std::string & GetPrefix() const
 
Result< std::string > GetVerticesNumFilePath() const
 
Result< std::shared_ptr< DataType > > GetPropertyType(const std::string &property_name) const
 
VertexInfo(const std::string &type, IdType chunk_size, const PropertyGroupVector &property_groups, const std::vector< std::string > &labels={}, const std::string &prefix="", std::shared_ptr< const InfoVersion > version=nullptr)
 
bool IsNullableKey(const std::string &property_name) const
 
Result< std::string > Dump() const noexcept
 
static Result< std::shared_ptr< VertexInfo > > Load(std::shared_ptr< Yaml > yaml)
 
std::shared_ptr< PropertyGroup > GetPropertyGroupByIndex(int index) const
 
Status Save(const std::string &file_name) const
 
const PropertyGroupVector & GetPropertyGroups() const