23 #include "graphar/chunk_info_reader.h"
24 #include "graphar/filesystem.h"
25 #include "graphar/graph_info.h"
26 #include "graphar/reader_util.h"
27 #include "graphar/result.h"
28 #include "graphar/types.h"
29 #include "graphar/util.h"
34 const std::shared_ptr<VertexInfo>& vertex_info,
35 const std::shared_ptr<PropertyGroup>& property_group,
36 const std::string& prefix)
37 : vertex_info_(std::move(vertex_info)),
38 property_group_(std::move(property_group)),
43 GAR_ASSIGN_OR_RAISE_ERROR(
auto fs,
44 FileSystemFromUriOrPath(prefix, &base_dir));
45 GAR_ASSIGN_OR_RAISE_ERROR(
auto pg_path_prefix,
46 vertex_info->GetPathPrefix(property_group));
47 base_dir += pg_path_prefix;
48 GAR_ASSIGN_OR_RAISE_ERROR(chunk_num_,
49 util::GetVertexChunkNum(prefix_, vertex_info_));
53 chunk_index_ =
id / vertex_info_->GetChunkSize();
54 if (chunk_index_ >= chunk_num_) {
56 chunk_num_ * vertex_info_->GetChunkSize(),
57 ") of vertex ", vertex_info_->GetLabel());
63 GAR_ASSIGN_OR_RAISE(
auto chunk_file_path,
64 vertex_info_->GetFilePath(property_group_, chunk_index_));
65 return prefix_ + chunk_file_path;
69 if (++chunk_index_ >= chunk_num_) {
71 "vertex chunk index ", chunk_index_,
" is out-of-bounds for vertex ",
72 vertex_info_->GetLabel(),
" chunk num ", chunk_num_);
77 Result<std::shared_ptr<VertexPropertyChunkInfoReader>>
79 const std::shared_ptr<VertexInfo>& vertex_info,
80 const std::shared_ptr<PropertyGroup>& property_group,
81 const std::string& prefix) {
82 return std::make_shared<VertexPropertyChunkInfoReader>(
83 vertex_info, property_group, prefix);
86 Result<std::shared_ptr<VertexPropertyChunkInfoReader>>
88 const std::shared_ptr<GraphInfo>& graph_info,
const std::string& label,
89 const std::shared_ptr<PropertyGroup>& property_group) {
90 auto vertex_info = graph_info->GetVertexInfo(label);
94 return Make(vertex_info, property_group, graph_info->GetPrefix());
97 Result<std::shared_ptr<VertexPropertyChunkInfoReader>>
99 const std::shared_ptr<GraphInfo>& graph_info,
const std::string& label,
100 const std::string& property_name) {
101 auto vertex_info = graph_info->GetVertexInfo(label);
105 auto property_group = vertex_info->GetPropertyGroup(property_name);
106 if (!property_group) {
108 " doesn't exist in vertex ", label,
".");
110 return Make(vertex_info, property_group, graph_info->GetPrefix());
114 const std::shared_ptr<EdgeInfo>& edge_info, AdjListType adj_list_type,
115 const std::string& prefix)
116 : edge_info_(std::move(edge_info)),
117 adj_list_type_(adj_list_type),
119 vertex_chunk_index_(0),
121 GAR_ASSIGN_OR_RAISE_ERROR(fs_, FileSystemFromUriOrPath(prefix, &base_dir_));
122 GAR_ASSIGN_OR_RAISE_ERROR(
auto adj_list_path_prefix,
123 edge_info->GetAdjListPathPrefix(adj_list_type));
124 base_dir_ = prefix_ + adj_list_path_prefix;
125 GAR_ASSIGN_OR_RAISE_ERROR(
127 util::GetVertexChunkNum(prefix_, edge_info_, adj_list_type_));
128 GAR_ASSIGN_OR_RAISE_ERROR(
129 chunk_num_, util::GetEdgeChunkNum(prefix_, edge_info_, adj_list_type_,
130 vertex_chunk_index_));
134 if (adj_list_type_ != AdjListType::unordered_by_source &&
135 adj_list_type_ != AdjListType::ordered_by_source) {
137 edge_info_->GetEdgeLabel(),
" reader with ",
138 AdjListTypeToString(adj_list_type_),
" type.");
141 IdType new_vertex_chunk_index =
id / edge_info_->GetSrcChunkSize();
142 if (new_vertex_chunk_index >= vertex_chunk_num_) {
144 "The source internal id ",
id,
" is out of range [0,",
145 edge_info_->GetSrcChunkSize() * vertex_chunk_num_,
") of edge ",
146 edge_info_->GetEdgeLabel(),
" reader.");
148 if (vertex_chunk_index_ != new_vertex_chunk_index) {
149 vertex_chunk_index_ = new_vertex_chunk_index;
151 chunk_num_, util::GetEdgeChunkNum(prefix_, edge_info_, adj_list_type_,
152 vertex_chunk_index_));
155 if (adj_list_type_ == AdjListType::unordered_by_source) {
158 GAR_ASSIGN_OR_RAISE(
auto offset_pair,
159 util::GetAdjListOffsetOfVertex(edge_info_, prefix_,
160 adj_list_type_,
id));
161 return seek(offset_pair.first);
167 if (adj_list_type_ != AdjListType::unordered_by_dest &&
168 adj_list_type_ != AdjListType::ordered_by_dest) {
170 edge_info_->GetEdgeLabel(),
" reader with ",
171 AdjListTypeToString(adj_list_type_),
" type.");
174 IdType new_vertex_chunk_index =
id / edge_info_->GetDstChunkSize();
175 if (new_vertex_chunk_index >= vertex_chunk_num_) {
177 "The destination internal id ",
id,
" is out of range [0,",
178 edge_info_->GetDstChunkSize() * vertex_chunk_num_,
") of edge ",
179 edge_info_->GetEdgeLabel(),
" reader.");
181 if (vertex_chunk_index_ != new_vertex_chunk_index) {
182 vertex_chunk_index_ = new_vertex_chunk_index;
184 chunk_num_, util::GetEdgeChunkNum(prefix_, edge_info_, adj_list_type_,
185 vertex_chunk_index_));
188 if (adj_list_type_ == AdjListType::unordered_by_dest) {
191 GAR_ASSIGN_OR_RAISE(
auto range,
192 util::GetAdjListOffsetOfVertex(edge_info_, prefix_,
193 adj_list_type_,
id));
194 return seek(range.first);
199 chunk_index_ = index / edge_info_->GetChunkSize();
200 if (chunk_index_ >= chunk_num_) {
202 edge_info_->GetChunkSize() * chunk_num_,
203 "), edge type: ", edge_info_->GetEdgeLabel());
209 GAR_ASSIGN_OR_RAISE(
auto chunk_file_path,
210 edge_info_->GetAdjListFilePath(
211 vertex_chunk_index_, chunk_index_, adj_list_type_));
212 return prefix_ + chunk_file_path;
217 while (chunk_index_ >= chunk_num_) {
218 ++vertex_chunk_index_;
219 if (vertex_chunk_index_ >= vertex_chunk_num_) {
221 " is out-of-bounds for vertex chunk num ",
225 GAR_ASSIGN_OR_RAISE_ERROR(
226 chunk_num_, util::GetEdgeChunkNum(prefix_, edge_info_, adj_list_type_,
227 vertex_chunk_index_));
233 const std::shared_ptr<EdgeInfo>& edge_info, AdjListType adj_list_type,
234 const std::string& prefix) {
235 if (!edge_info->HasAdjacentListType(adj_list_type)) {
237 "The adjacent list type ", AdjListTypeToString(adj_list_type),
238 " doesn't exist in edge ", edge_info->GetEdgeLabel(),
".");
240 return std::make_shared<AdjListChunkInfoReader>(edge_info, adj_list_type,
245 const std::shared_ptr<GraphInfo>& graph_info,
const std::string& src_label,
246 const std::string& edge_label,
const std::string& dst_label,
247 AdjListType adj_list_type) {
248 auto edge_info = graph_info->GetEdgeInfo(src_label, edge_label, dst_label);
251 dst_label,
" doesn't exist.");
253 return Make(edge_info, adj_list_type, graph_info->GetPrefix());
257 const std::shared_ptr<EdgeInfo>& edge_info, AdjListType adj_list_type,
258 const std::string& prefix)
259 : edge_info_(std::move(edge_info)),
260 adj_list_type_(adj_list_type),
263 std::string base_dir;
264 GAR_ASSIGN_OR_RAISE_ERROR(
auto fs,
265 FileSystemFromUriOrPath(prefix, &base_dir));
266 GAR_ASSIGN_OR_RAISE_ERROR(
auto dir_path,
267 edge_info->GetOffsetPathPrefix(adj_list_type));
268 base_dir = prefix_ + dir_path;
269 if (adj_list_type == AdjListType::ordered_by_source ||
270 adj_list_type == AdjListType::ordered_by_dest) {
271 GAR_ASSIGN_OR_RAISE_ERROR(
273 util::GetVertexChunkNum(prefix_, edge_info_, adj_list_type_));
274 vertex_chunk_size_ = adj_list_type == AdjListType::ordered_by_source
275 ? edge_info_->GetSrcChunkSize()
276 : edge_info_->GetDstChunkSize();
278 std::string err_msg =
"Invalid adj list type " +
279 std::string(AdjListTypeToString(adj_list_type)) +
280 " to construct AdjListOffsetReader.";
281 throw std::runtime_error(err_msg);
286 chunk_index_ =
id / vertex_chunk_size_;
287 if (chunk_index_ >= vertex_chunk_num_) {
289 vertex_chunk_num_ * vertex_chunk_size_,
297 auto chunk_file_path,
298 edge_info_->GetAdjListOffsetFilePath(chunk_index_, adj_list_type_));
299 return prefix_ + chunk_file_path;
303 if (++chunk_index_ >= vertex_chunk_num_) {
305 " is out-of-bounds for vertex, chunk_num ",
311 Result<std::shared_ptr<AdjListOffsetChunkInfoReader>>
313 AdjListType adj_list_type,
314 const std::string& prefix) {
315 if (!edge_info->HasAdjacentListType(adj_list_type)) {
317 "The adjacent list type ", AdjListTypeToString(adj_list_type),
318 " doesn't exist in edge ", edge_info->GetEdgeLabel(),
".");
320 return std::make_shared<AdjListOffsetChunkInfoReader>(edge_info,
321 adj_list_type, prefix);
324 Result<std::shared_ptr<AdjListOffsetChunkInfoReader>>
326 const std::string& src_label,
327 const std::string& edge_label,
328 const std::string& dst_label,
329 AdjListType adj_list_type) {
330 auto edge_info = graph_info->GetEdgeInfo(src_label, edge_label, dst_label);
333 dst_label,
" doesn't exist.");
335 return Make(edge_info, adj_list_type, graph_info->GetPrefix());
339 const std::shared_ptr<EdgeInfo>& edge_info,
340 const std::shared_ptr<PropertyGroup>& property_group,
341 AdjListType adj_list_type,
const std::string prefix)
342 : edge_info_(std::move(edge_info)),
343 property_group_(std::move(property_group)),
344 adj_list_type_(adj_list_type),
346 vertex_chunk_index_(0),
348 GAR_ASSIGN_OR_RAISE_ERROR(fs_, FileSystemFromUriOrPath(prefix, &base_dir_));
349 GAR_ASSIGN_OR_RAISE_ERROR(
351 edge_info->GetPropertyGroupPathPrefix(property_group, adj_list_type));
352 base_dir_ = prefix_ + pg_path_prefix;
353 GAR_ASSIGN_OR_RAISE_ERROR(
355 util::GetVertexChunkNum(prefix_, edge_info_, adj_list_type_));
356 GAR_ASSIGN_OR_RAISE_ERROR(
357 chunk_num_, util::GetEdgeChunkNum(prefix_, edge_info_, adj_list_type_,
358 vertex_chunk_index_));
362 if (adj_list_type_ != AdjListType::unordered_by_source &&
363 adj_list_type_ != AdjListType::ordered_by_source) {
365 edge_info_->GetEdgeLabel(),
" reader with ",
366 AdjListTypeToString(adj_list_type_),
" type.");
369 IdType new_vertex_chunk_index =
id / edge_info_->GetSrcChunkSize();
370 if (new_vertex_chunk_index >= vertex_chunk_num_) {
372 "The source internal id ",
id,
" is out of range [0,",
373 edge_info_->GetSrcChunkSize() * vertex_chunk_num_,
") of edge ",
374 edge_info_->GetEdgeLabel(),
" reader.");
376 if (vertex_chunk_index_ != new_vertex_chunk_index) {
377 vertex_chunk_index_ = new_vertex_chunk_index;
379 chunk_num_, util::GetEdgeChunkNum(prefix_, edge_info_, adj_list_type_,
380 vertex_chunk_index_));
382 if (adj_list_type_ == AdjListType::unordered_by_source) {
385 GAR_ASSIGN_OR_RAISE(
auto range,
386 util::GetAdjListOffsetOfVertex(edge_info_, prefix_,
387 adj_list_type_,
id));
388 return seek(range.first);
394 if (adj_list_type_ != AdjListType::unordered_by_dest &&
395 adj_list_type_ != AdjListType::ordered_by_dest) {
397 edge_info_->GetEdgeLabel(),
" reader with ",
398 AdjListTypeToString(adj_list_type_),
" type.");
401 IdType new_vertex_chunk_index =
id / edge_info_->GetDstChunkSize();
402 if (new_vertex_chunk_index >= vertex_chunk_num_) {
404 "The destination internal id ",
id,
" is out of range [0,",
405 edge_info_->GetDstChunkSize() * vertex_chunk_num_,
") of edge ",
406 edge_info_->GetEdgeLabel(),
" reader.");
408 if (vertex_chunk_index_ != new_vertex_chunk_index) {
409 vertex_chunk_index_ = new_vertex_chunk_index;
411 chunk_num_, util::GetEdgeChunkNum(prefix_, edge_info_, adj_list_type_,
412 vertex_chunk_index_));
415 if (adj_list_type_ == AdjListType::unordered_by_dest) {
418 GAR_ASSIGN_OR_RAISE(
auto range,
419 util::GetAdjListOffsetOfVertex(edge_info_, prefix_,
420 adj_list_type_,
id));
421 return seek(range.first);
426 chunk_index_ = offset / edge_info_->GetChunkSize();
427 if (chunk_index_ >= chunk_num_) {
429 " is out of range [0,",
430 edge_info_->GetChunkSize() * chunk_num_,
431 "), edge label: ", edge_info_->GetEdgeLabel());
438 auto chunk_file_path,
439 edge_info_->GetPropertyFilePath(property_group_, adj_list_type_,
440 vertex_chunk_index_, chunk_index_));
441 return prefix_ + chunk_file_path;
446 while (chunk_index_ >= chunk_num_) {
447 ++vertex_chunk_index_;
448 if (vertex_chunk_index_ >= vertex_chunk_num_) {
450 "vertex chunk index ", vertex_chunk_index_,
451 " is out-of-bounds for vertex chunk num ", vertex_chunk_num_,
452 " of edge ", edge_info_->GetEdgeLabel(),
" of adj list type ",
453 AdjListTypeToString(adj_list_type_),
", property group ",
454 property_group_,
".");
457 GAR_ASSIGN_OR_RAISE_ERROR(
458 chunk_num_, util::GetEdgeChunkNum(prefix_, edge_info_, adj_list_type_,
459 vertex_chunk_index_));
464 Result<std::shared_ptr<AdjListPropertyChunkInfoReader>>
466 const std::shared_ptr<EdgeInfo>& edge_info,
467 const std::shared_ptr<PropertyGroup>& property_group,
468 AdjListType adj_list_type,
const std::string& prefix) {
469 if (!edge_info->HasAdjacentListType(adj_list_type)) {
471 "The adjacent list type ", AdjListTypeToString(adj_list_type),
472 " doesn't exist in edge ", edge_info->GetEdgeLabel(),
".");
474 return std::make_shared<AdjListPropertyChunkInfoReader>(
475 edge_info, property_group, adj_list_type, prefix);
478 Result<std::shared_ptr<AdjListPropertyChunkInfoReader>>
480 const std::shared_ptr<GraphInfo>& graph_info,
const std::string& src_label,
481 const std::string& edge_label,
const std::string& dst_label,
482 const std::shared_ptr<PropertyGroup>& property_group,
483 AdjListType adj_list_type) {
484 auto edge_info = graph_info->GetEdgeInfo(src_label, edge_label, dst_label);
487 dst_label,
" doesn't exist.");
489 return Make(edge_info, property_group, adj_list_type,
490 graph_info->GetPrefix());
493 Result<std::shared_ptr<AdjListPropertyChunkInfoReader>>
495 const std::shared_ptr<GraphInfo>& graph_info,
const std::string& src_label,
496 const std::string& edge_label,
const std::string& dst_label,
497 const std::string& property_name, AdjListType adj_list_type) {
498 auto edge_info = graph_info->GetEdgeInfo(src_label, edge_label, dst_label);
501 dst_label,
" doesn't exist.");
503 auto property_group = edge_info->GetPropertyGroup(property_name);
504 if (!property_group) {
506 " doesn't exist in edge ", src_label,
" ",
507 edge_label,
" ", dst_label,
".");
509 return Make(edge_info, property_group, adj_list_type,
510 graph_info->GetPrefix());
Status seek_dst(IdType id)
Sets chunk position indicator for reader by destination internal vertex id.
Status seek(IdType index)
Sets chunk position indicator for reader by edge index.
Status seek_src(IdType id)
Sets chunk position indicator for reader by source internal vertex id.
Result< std::string > GetChunk()
static Result< std::shared_ptr< AdjListChunkInfoReader > > Make(const std::shared_ptr< EdgeInfo > &edge_info, AdjListType adj_list_type, const std::string &prefix)
Create an AdjListChunkInfoReader instance from edge info.
AdjListChunkInfoReader(const std::shared_ptr< EdgeInfo > &edge_info, AdjListType adj_list_type, const std::string &prefix)
Initialize the AdjListChunkInfoReader.
Status seek(IdType id)
Sets chunk position indicator for reader by source internal vertex id.
AdjListOffsetChunkInfoReader(const std::shared_ptr< EdgeInfo > &edge_info, AdjListType adj_list_type, const std::string &prefix)
Initialize the AdjListOffsetChunkInfoReader.
Result< std::string > GetChunk() const
Return the current chunk file path of chunk position indicator.
static Result< std::shared_ptr< AdjListOffsetChunkInfoReader > > Make(const std::shared_ptr< EdgeInfo > &edge_info, AdjListType adj_list_type, const std::string &prefix)
Create an AdjListOffsetChunkInfoReader instance from edge info.
Status seek(IdType offset)
Sets chunk position indicator for reader by edge index.
Status seek_src(IdType id)
Sets chunk position indicator for reader by source vertex id.
static Result< std::shared_ptr< AdjListPropertyChunkInfoReader > > Make(const std::shared_ptr< EdgeInfo > &edge_info, const std::shared_ptr< PropertyGroup > &property_group, AdjListType adj_list_type, const std::string &prefix)
Create an AdjListPropertyChunkInfoReader instance from edge info.
AdjListPropertyChunkInfoReader(const std::shared_ptr< EdgeInfo > &edge_info, const std::shared_ptr< PropertyGroup > &property_group, AdjListType adj_list_type, const std::string prefix)
Initialize the AdjListPropertyChunkInfoReader.
Result< std::string > GetChunk() const
Status seek_dst(IdType id)
Sets chunk position indicator for reader by destination vertex id.
Status outcome object (success or error)
static Status IndexError(Args &&... args)
static Status KeyError(Args &&... args)
static Status Invalid(Args &&... args)
static Result< std::shared_ptr< VertexPropertyChunkInfoReader > > Make(const std::shared_ptr< VertexInfo > &vertex_info, const std::shared_ptr< PropertyGroup > &property_group, const std::string &prefix)
Create a VertexPropertyChunkInfoReader instance from vertex info.
Status seek(IdType id)
Sets chunk position indicator for reader by internal vertex id. If internal vertex id is not found,...
VertexPropertyChunkInfoReader(const std::shared_ptr< VertexInfo > &vertex_info, const std::shared_ptr< PropertyGroup > &property_group, const std::string &prefix)
Initialize the VertexPropertyChunkInfoReader.
Result< std::string > GetChunk() const
Return the current chunk file path of chunk position indicator.