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;
215 const std::string&
GetType()
const;
236 const std::shared_ptr<const InfoVersion>&
version()
const;
242 const std::vector<std::string>&
GetLabels()
const;
263 const std::string& property_name)
const;
281 const std::string& property_name)
const;
283 Result<Cardinality> GetPropertyCardinality(
284 const std::string& property_name)
const;
291 bool HasProperty(
const std::string& property_name)
const;
299 Status Save(
const std::string& file_name)
const;
307 Result<std::string>
Dump()
const noexcept;
315 bool IsPrimaryKey(
const std::string& property_name)
const;
333 const std::shared_ptr<PropertyGroup>& property_group)
const;
343 Result<std::string>
GetFilePath(std::shared_ptr<PropertyGroup> property_group,
344 IdType chunk_index)
const;
354 std::shared_ptr<PropertyGroup> property_group)
const;
377 static Result<std::shared_ptr<VertexInfo>>
Load(std::shared_ptr<Yaml> yaml);
385 static Result<std::shared_ptr<VertexInfo>>
Load(
const std::string& input);
389 std::unique_ptr<Impl> impl_;
417 explicit EdgeInfo(
const std::string& src_type,
const std::string& edge_type,
418 const std::string& dst_type, IdType chunk_size,
419 IdType src_chunk_size, IdType dst_chunk_size,
bool directed,
420 const AdjacentListVector& adjacent_lists,
421 const PropertyGroupVector& property_groups,
422 const std::string& prefix =
"",
423 std::shared_ptr<const InfoVersion>
version =
nullptr);
435 std::shared_ptr<AdjacentList> adj_list)
const;
443 std::shared_ptr<PropertyGroup> property_group)
const;
497 const std::shared_ptr<const InfoVersion>&
version()
const;
514 bool HasProperty(
const std::string& property_name)
const;
520 const std::shared_ptr<PropertyGroup>& property_group)
const;
522 std::shared_ptr<AdjacentList> GetAdjacentList(
523 AdjListType adj_list_type)
const;
543 const std::string& property)
const;
571 AdjListType adj_list_type)
const;
581 IdType edge_chunk_index,
582 AdjListType adj_list_type)
const;
601 AdjListType adj_list_type)
const;
623 const std::shared_ptr<PropertyGroup>& property_group,
624 AdjListType adj_list_type, IdType vertex_chunk_index,
625 IdType edge_chunk_index)
const;
636 const std::shared_ptr<PropertyGroup>& property_group,
637 AdjListType adj_list_type)
const;
647 const std::string& property_name)
const;
654 bool IsPrimaryKey(
const std::string& property_name)
const;
670 Status Save(
const std::string& file_name)
const;
678 Result<std::string>
Dump()
const noexcept;
688 static Result<std::shared_ptr<EdgeInfo>>
Load(std::shared_ptr<Yaml> yaml);
696 static Result<std::shared_ptr<EdgeInfo>>
Load(
const std::string& input);
700 std::unique_ptr<Impl> impl_;
720 const std::string& graph_name, VertexInfoVector vertex_infos,
721 EdgeInfoVector edge_infos,
const std::vector<std::string>& labels = {},
722 const std::string& prefix =
"./",
723 std::shared_ptr<const InfoVersion>
version =
nullptr,
724 const std::unordered_map<std::string, std::string>& extra_info = {});
734 static Result<std::shared_ptr<GraphInfo>>
Load(
const std::string& path);
743 static Result<std::shared_ptr<GraphInfo>>
Load(
744 const std::string& input,
const std::string& relative_path);
754 Result<std::shared_ptr<GraphInfo>>
AddVertex(
755 std::shared_ptr<VertexInfo> vertex_info)
const;
765 Result<std::shared_ptr<GraphInfo>>
AddEdge(
766 std::shared_ptr<EdgeInfo> edge_info)
const;
772 const std::string&
GetName()
const;
778 const std::vector<std::string>&
GetLabels()
const;
791 const std::shared_ptr<const InfoVersion>&
version()
const;
798 const std::unordered_map<std::string, std::string>&
GetExtraInfo()
const;
805 std::shared_ptr<VertexInfo>
GetVertexInfo(
const std::string& type)
const;
815 std::shared_ptr<EdgeInfo>
GetEdgeInfo(
const std::string& src_type,
816 const std::string& edge_type,
817 const std::string& dst_type)
const;
829 const std::string& edge_type,
830 const std::string& dst_type)
const;
886 Result<std::string>
Dump()
const;
897 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< 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
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.
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
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