24 #include <unordered_map>
27 #include "graphar/fwd.h"
37 std::shared_ptr<DataType> type;
41 explicit Property(
const std::string& name,
42 const std::shared_ptr<DataType>& type =
nullptr,
43 bool is_primary =
false,
bool is_nullable =
true)
46 is_primary(is_primary),
47 is_nullable(!is_primary && is_nullable) {}
70 explicit PropertyGroup(
const std::vector<Property>& properties,
71 FileType file_type,
const std::string& prefix =
"");
80 bool HasProperty(
const std::string& property_name)
const;
92 inline const std::string&
GetPrefix()
const {
return prefix_; }
99 friend std::ostream& operator<<(std::ostream& stream,
101 for (
size_t i = 0; i < pg.properties_.size(); ++i) {
102 stream << pg.properties_[i].name;
103 if (i != pg.properties_.size() - 1) {
111 std::vector<Property> properties_;
116 bool operator==(
const PropertyGroup& lhs,
const PropertyGroup& rhs);
132 explicit AdjacentList(AdjListType type, FileType file_type,
133 const std::string& prefix =
"");
140 inline AdjListType
GetType()
const {
return type_; }
154 inline const std::string&
GetPrefix()
const {
return prefix_; }
187 explicit VertexInfo(
const std::string& label, IdType chunk_size,
188 const PropertyGroupVector& property_groups,
189 const std::string& prefix =
"",
190 std::shared_ptr<const InfoVersion>
version =
nullptr);
200 std::shared_ptr<PropertyGroup> property_group)
const;
207 const std::string&
GetLabel()
const;
228 const std::shared_ptr<const InfoVersion>&
version()
const;
249 const std::string& property_name)
const;
267 const std::string& property_name)
const;
275 bool HasProperty(
const std::string& property_name)
const;
283 Status Save(
const std::string& file_name)
const;
291 Result<std::string>
Dump()
const noexcept;
299 bool IsPrimaryKey(
const std::string& property_name)
const;
317 const std::shared_ptr<PropertyGroup>& property_group)
const;
327 Result<std::string>
GetFilePath(std::shared_ptr<PropertyGroup> property_group,
328 IdType chunk_index)
const;
338 std::shared_ptr<PropertyGroup> property_group)
const;
361 static Result<std::shared_ptr<VertexInfo>>
Load(std::shared_ptr<Yaml> yaml);
369 static Result<std::shared_ptr<VertexInfo>>
Load(
const std::string& input);
373 std::unique_ptr<Impl> impl_;
401 explicit EdgeInfo(
const std::string& src_label,
const std::string& edge_label,
402 const std::string& dst_label, IdType chunk_size,
403 IdType src_chunk_size, IdType dst_chunk_size,
bool directed,
404 const AdjacentListVector& adjacent_lists,
405 const PropertyGroupVector& property_groups,
406 const std::string& prefix =
"",
407 std::shared_ptr<const InfoVersion>
version =
nullptr);
419 std::shared_ptr<AdjacentList> adj_list)
const;
427 std::shared_ptr<PropertyGroup> property_group)
const;
481 const std::shared_ptr<const InfoVersion>&
version()
const;
498 bool HasProperty(
const std::string& property_name)
const;
504 const std::shared_ptr<PropertyGroup>& property_group)
const;
506 std::shared_ptr<AdjacentList> GetAdjacentList(
507 AdjListType adj_list_type)
const;
527 const std::string& property)
const;
555 AdjListType adj_list_type)
const;
565 IdType edge_chunk_index,
566 AdjListType adj_list_type)
const;
585 AdjListType adj_list_type)
const;
607 const std::shared_ptr<PropertyGroup>& property_group,
608 AdjListType adj_list_type, IdType vertex_chunk_index,
609 IdType edge_chunk_index)
const;
620 const std::shared_ptr<PropertyGroup>& property_group,
621 AdjListType adj_list_type)
const;
631 const std::string& property_name)
const;
638 bool IsPrimaryKey(
const std::string& property_name)
const;
654 Status Save(
const std::string& file_name)
const;
662 Result<std::string>
Dump()
const noexcept;
672 static Result<std::shared_ptr<EdgeInfo>>
Load(std::shared_ptr<Yaml> yaml);
680 static Result<std::shared_ptr<EdgeInfo>>
Load(
const std::string& input);
684 std::unique_ptr<Impl> impl_;
703 const std::string& graph_name, VertexInfoVector vertex_infos,
704 EdgeInfoVector edge_infos,
const std::string& prefix =
"./",
705 std::shared_ptr<const InfoVersion>
version =
nullptr,
706 const std::unordered_map<std::string, std::string>& extra_info = {});
716 static Result<std::shared_ptr<GraphInfo>>
Load(
const std::string& path);
725 static Result<std::shared_ptr<GraphInfo>>
Load(
726 const std::string& input,
const std::string& relative_path);
736 Result<std::shared_ptr<GraphInfo>>
AddVertex(
737 std::shared_ptr<VertexInfo> vertex_info)
const;
747 Result<std::shared_ptr<GraphInfo>>
AddEdge(
748 std::shared_ptr<EdgeInfo> edge_info)
const;
754 const std::string&
GetName()
const;
767 const std::shared_ptr<const InfoVersion>&
version()
const;
774 const std::unordered_map<std::string, std::string>&
GetExtraInfo()
const;
781 std::shared_ptr<VertexInfo>
GetVertexInfo(
const std::string& label)
const;
791 std::shared_ptr<EdgeInfo>
GetEdgeInfo(
const std::string& src_label,
792 const std::string& edge_label,
793 const std::string& dst_label)
const;
805 const std::string& edge_label,
806 const std::string& dst_label)
const;
862 Result<std::string>
Dump()
const;
873 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 label,...
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< 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::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
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.
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 ...
IdType GetSrcChunkSize() const
const std::string & GetSrcLabel() const
const PropertyGroupVector & GetPropertyGroups() const
Get the property groups.
const std::string & GetDstLabel() const
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.
const std::string & GetEdgeLabel() const
EdgeInfo(const std::string &src_label, const std::string &edge_label, const std::string &dst_label, 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.
int GetVertexInfoIndex(const std::string &label) const
Get the vertex info index with the given label.
const EdgeInfoVector & GetEdgeInfos() const
Get the edge infos of graph info.
std::shared_ptr< EdgeInfo > GetEdgeInfo(const std::string &src_label, const std::string &edge_label, const std::string &dst_label) const
Get the edge info with the given source vertex label, edge label, and destination vertex label.
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.
int GetEdgeInfoIndex(const std::string &src_label, const std::string &edge_label, const std::string &dst_label) const
Get the edge info index with the given source vertex label, edge label, and destination label.
Result< std::string > Dump() const
int EdgeInfoNum() const
Get the number of edge infos.
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 VertexInfoNum() const
Get the number of vertex infos.
const std::string & GetName() const
Get the name of the graph.
GraphInfo(const std::string &graph_name, VertexInfoVector vertex_infos, EdgeInfoVector edge_infos, 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.
const std::shared_ptr< const InfoVersion > & version() const
Get the version info of the graph info object.
std::shared_ptr< VertexInfo > GetVertexInfo(const std::string &label) const
Get the vertex info with the given label.
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 label,...
std::shared_ptr< PropertyGroup > GetPropertyGroup(const std::string &property_name) const
Result< std::string > GetPathPrefix(std::shared_ptr< PropertyGroup > property_group) 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
const std::string & GetPrefix() const
const std::string & GetLabel() const
Result< std::string > GetVerticesNumFilePath() const
VertexInfo(const std::string &label, IdType chunk_size, const PropertyGroupVector &property_groups, const std::string &prefix="", std::shared_ptr< const InfoVersion > version=nullptr)
Result< std::shared_ptr< DataType > > GetPropertyType(const std::string &property_name) const
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