@@ -24,7 +24,6 @@ limitations under the License.
24
24
#include " gar/graph_info.h"
25
25
#include " gar/utils/data_type.h"
26
26
#include " gar/utils/filesystem.h"
27
- #include " gar/utils/reader_utils.h"
28
27
#include " gar/utils/result.h"
29
28
#include " gar/utils/status.h"
30
29
#include " gar/utils/utils.h"
@@ -52,18 +51,22 @@ class VertexPropertyArrowChunkReader {
52
51
VertexPropertyArrowChunkReader (const VertexInfo& vertex_info,
53
52
const PropertyGroup& property_group,
54
53
const std::string& prefix,
55
- IdType chunk_index = 0 )
54
+ IdType chunk_index = 0 ,
55
+ const utils::FilterOptions& options = {})
56
56
: vertex_info_(vertex_info),
57
57
property_group_ (property_group),
58
58
chunk_index_(chunk_index),
59
59
seek_id_(chunk_index * vertex_info.GetChunkSize()),
60
- chunk_table_(nullptr ) {
60
+ chunk_table_(nullptr ),
61
+ filter_options_(options) {
61
62
GAR_ASSIGN_OR_RAISE_ERROR (fs_, FileSystemFromUriOrPath (prefix, &prefix_));
62
63
GAR_ASSIGN_OR_RAISE_ERROR (auto pg_path_prefix,
63
64
vertex_info.GetPathPrefix (property_group));
64
65
std::string base_dir = prefix_ + pg_path_prefix;
65
66
GAR_ASSIGN_OR_RAISE_ERROR (chunk_num_,
66
67
utils::GetVertexChunkNum (prefix_, vertex_info));
68
+ GAR_ASSIGN_OR_RAISE_ERROR (vertex_num_,
69
+ utils::GetVertexNum (prefix_, vertex_info_));
67
70
}
68
71
69
72
/* *
@@ -126,14 +129,32 @@ class VertexPropertyArrowChunkReader {
126
129
*/
127
130
IdType GetChunkNum () const noexcept { return chunk_num_; }
128
131
132
+ /* *
133
+ * @brief Apply the row filter to the table. No parameter call Filter() will
134
+ * clear the filter.
135
+ *
136
+ * @param filter Predicate expression to filter rows.
137
+ */
138
+ void Filter (utils::Filter filter = nullptr );
139
+
140
+ /* *
141
+ * @brief Apply the projection to the table to be read. No parameter call
142
+ * Select() will clear the projection.
143
+ *
144
+ * @param column_names The name of columns to be selected.
145
+ */
146
+ void Select (utils::ColumnNames column_names = std::nullopt);
147
+
129
148
private:
130
149
VertexInfo vertex_info_;
131
150
PropertyGroup property_group_;
132
151
std::string prefix_;
133
152
IdType chunk_index_;
134
153
IdType seek_id_;
135
154
IdType chunk_num_;
155
+ IdType vertex_num_;
136
156
std::shared_ptr<arrow::Table> chunk_table_;
157
+ utils::FilterOptions filter_options_;
137
158
std::shared_ptr<FileSystem> fs_;
138
159
};
139
160
@@ -227,7 +248,8 @@ class AdjListArrowChunkReader {
227
248
}
228
249
229
250
/* *
230
- * @brief Return the current chunk of chunk position indicator as arrow::Table
251
+ * @brief Return the current chunk of chunk position indicator as
252
+ * arrow::Table
231
253
*/
232
254
Result<std::shared_ptr<arrow::Table>> GetChunk () noexcept ;
233
255
@@ -420,7 +442,8 @@ class AdjListPropertyArrowChunkReader {
420
442
* @brief Initialize the AdjListPropertyArrowChunkReader.
421
443
*
422
444
* @param edge_info The edge info that describes the edge type.
423
- * @param property_group The property group that describes the property group.
445
+ * @param property_group The property group that describes the property
446
+ * group.
424
447
* @param adj_list_type The adj list type for the edges.
425
448
* @param prefix The absolute prefix.
426
449
* @param vertex_chunk_index The vertex chunk index, default is 0.
@@ -429,15 +452,17 @@ class AdjListPropertyArrowChunkReader {
429
452
const PropertyGroup& property_group,
430
453
AdjListType adj_list_type,
431
454
const std::string prefix,
432
- IdType vertex_chunk_index = 0 )
455
+ IdType vertex_chunk_index = 0 ,
456
+ const utils::FilterOptions& options = {})
433
457
: edge_info_(edge_info),
434
458
property_group_ (property_group),
435
459
adj_list_type_(adj_list_type),
436
460
prefix_(prefix),
437
461
vertex_chunk_index_(vertex_chunk_index),
438
462
chunk_index_(0 ),
439
463
seek_offset_(0 ),
440
- chunk_table_(nullptr ) {
464
+ chunk_table_(nullptr ),
465
+ filter_options_(options) {
441
466
GAR_ASSIGN_OR_RAISE_ERROR (fs_, FileSystemFromUriOrPath (prefix, &prefix_));
442
467
GAR_ASSIGN_OR_RAISE_ERROR (
443
468
auto pg_path_prefix,
@@ -463,6 +488,7 @@ class AdjListPropertyArrowChunkReader {
463
488
chunk_index_(other.chunk_index_),
464
489
seek_offset_(other.seek_offset_),
465
490
chunk_table_(nullptr ),
491
+ filter_options_(other.filter_options_),
466
492
vertex_chunk_num_(other.vertex_chunk_num_),
467
493
chunk_num_(other.chunk_num_),
468
494
base_dir_(other.base_dir_),
@@ -506,7 +532,8 @@ class AdjListPropertyArrowChunkReader {
506
532
}
507
533
508
534
/* *
509
- * @brief Return the current chunk of chunk position indicator as arrow::Table
535
+ * @brief Return the current chunk of chunk position indicator as
536
+ * arrow::Table
510
537
*/
511
538
Result<std::shared_ptr<arrow::Table>> GetChunk () noexcept ;
512
539
@@ -564,6 +591,22 @@ class AdjListPropertyArrowChunkReader {
564
591
return Status::OK ();
565
592
}
566
593
594
+ /* *
595
+ * @brief Apply the row filter to the table. No parameter call Filter() will
596
+ * clear the filter.
597
+ *
598
+ * @param filter Predicate expression to filter rows.
599
+ */
600
+ void Filter (utils::Filter filter = nullptr );
601
+
602
+ /* *
603
+ * @brief Apply the projection to the table to be read. No parameter call
604
+ * Select() will clear the projection.
605
+ *
606
+ * @param column_names The name of columns to be selected.
607
+ */
608
+ void Select (utils::ColumnNames column_names = std::nullopt);
609
+
567
610
private:
568
611
EdgeInfo edge_info_;
569
612
PropertyGroup property_group_;
@@ -572,6 +615,7 @@ class AdjListPropertyArrowChunkReader {
572
615
IdType vertex_chunk_index_, chunk_index_;
573
616
IdType seek_offset_;
574
617
std::shared_ptr<arrow::Table> chunk_table_;
618
+ utils::FilterOptions filter_options_;
575
619
IdType vertex_chunk_num_, chunk_num_;
576
620
std::string base_dir_;
577
621
std::shared_ptr<FileSystem> fs_;
@@ -587,15 +631,16 @@ class AdjListPropertyArrowChunkReader {
587
631
static inline Result<VertexPropertyArrowChunkReader>
588
632
ConstructVertexPropertyArrowChunkReader (
589
633
const GraphInfo& graph_info, const std::string& label,
590
- const PropertyGroup& property_group) noexcept {
634
+ const PropertyGroup& property_group,
635
+ const utils::FilterOptions& options = {}) noexcept {
591
636
VertexInfo vertex_info;
592
637
GAR_ASSIGN_OR_RAISE (vertex_info, graph_info.GetVertexInfo (label));
593
638
if (!vertex_info.ContainPropertyGroup (property_group)) {
594
639
return Status::KeyError (" No property group " , property_group, " in vertex " ,
595
640
label, " ." );
596
641
}
597
642
return VertexPropertyArrowChunkReader (vertex_info, property_group,
598
- graph_info.GetPrefix ());
643
+ graph_info.GetPrefix (), 0 , options );
599
644
}
600
645
601
646
/* *
@@ -663,12 +708,11 @@ ConstructAdjListOffsetArrowChunkReader(const GraphInfo& graph_info,
663
708
* @param adj_list_type The adj list type for the edges.
664
709
*/
665
710
static inline Result<AdjListPropertyArrowChunkReader>
666
- ConstructAdjListPropertyArrowChunkReader (const GraphInfo& graph_info,
667
- const std::string& src_label,
668
- const std::string& edge_label,
669
- const std::string& dst_label,
670
- const PropertyGroup& property_group,
671
- AdjListType adj_list_type) noexcept {
711
+ ConstructAdjListPropertyArrowChunkReader (
712
+ const GraphInfo& graph_info, const std::string& src_label,
713
+ const std::string& edge_label, const std::string& dst_label,
714
+ const PropertyGroup& property_group, AdjListType adj_list_type,
715
+ const utils::FilterOptions& options = {}) noexcept {
672
716
EdgeInfo edge_info;
673
717
GAR_ASSIGN_OR_RAISE (edge_info,
674
718
graph_info.GetEdgeInfo (src_label, edge_label, dst_label));
@@ -683,7 +727,8 @@ ConstructAdjListPropertyArrowChunkReader(const GraphInfo& graph_info,
683
727
AdjListTypeToString (adj_list_type), " ." );
684
728
}
685
729
return AdjListPropertyArrowChunkReader (edge_info, property_group,
686
- adj_list_type, graph_info.GetPrefix ());
730
+ adj_list_type, graph_info.GetPrefix (),
731
+ 0 , options);
687
732
}
688
733
689
734
} // namespace GAR_NAMESPACE_INTERNAL
0 commit comments