@@ -2088,6 +2088,7 @@ class Table
20882088 Table (std::shared_ptr<arrow::Table> table, uint64_t offset = 0 )
20892089 : mTable (table),
20902090 mOffset (offset),
2091+ mSize{table->num_rows ()},
20912092 mEnd {table->num_rows ()}
20922093 {
20932094 if (mTable ->num_rows () == 0 ) {
@@ -2105,6 +2106,30 @@ class Table
21052106 }
21062107 }
21072108
2109+ // / Construct a view over a sub-range of an existing table without
2110+ // / calling arrow::Table::Slice (zero heap allocations).
2111+ Table (std::shared_ptr<arrow::Table> table, uint64_t offset, uint64_t count)
2112+ : mTable (table),
2113+ mOffset (0 ),
2114+ mSize{static_cast <int64_t >(count)},
2115+ mEnd {static_cast <int64_t >(offset + count)}
2116+ {
2117+ if (count == 0 ) {
2118+ for (size_t ci = 0 ; ci < framework::pack_size (columns_t {}); ++ci) {
2119+ mColumnChunks [ci] = nullptr ;
2120+ }
2121+ mBegin = mEnd ;
2122+ } else {
2123+ auto lookups = [this ]<typename ... C>(framework::pack<C...>) -> std::array<arrow::ChunkedArray*, framework::pack_size (columns_t {})> { return {lookupColumn<C>()...}; }(columns_t {});
2124+ for (size_t ci = 0 ; ci < framework::pack_size (columns_t {}); ++ci) {
2125+ mColumnChunks [ci] = lookups[ci];
2126+ }
2127+ mBegin = unfiltered_iterator{mColumnChunks , {static_cast <int64_t >(offset + count), 0 }};
2128+ mBegin .setCursor (offset);
2129+ mBegin .bindInternalIndices (this );
2130+ }
2131+ }
2132+
21082133 Table (std::vector<std::shared_ptr<arrow::Table>>&& tables, uint64_t offset = 0 )
21092134 requires (ref.origin_hash != " CONC" _h)
21102135 : Table(ArrowHelpers::joinTables(std::move(tables), std::span{originalLabels}), offset)
@@ -2201,7 +2226,7 @@ class Table
22012226 // / Size of the table, in rows.
22022227 [[nodiscard]] int64_t size () const
22032228 {
2204- return mTable -> num_rows () ;
2229+ return mSize ;
22052230 }
22062231
22072232 [[nodiscard]] int64_t tableSize () const
@@ -2287,12 +2312,12 @@ class Table
22872312
22882313 auto rawSlice (uint64_t start, uint64_t end) const
22892314 {
2290- return self_t {mTable -> Slice ( start, end - start + 1 ), start };
2315+ return self_t {mTable , start, end - start + 1 };
22912316 }
22922317
22932318 auto emptySlice () const
22942319 {
2295- return self_t {mTable -> Slice ( 0 , 0 ) , 0 };
2320+ return self_t {mTable , 0 , 0 };
22962321 }
22972322
22982323 private:
@@ -2308,6 +2333,7 @@ class Table
23082333 }
23092334 std::shared_ptr<arrow::Table> mTable = nullptr ;
23102335 uint64_t mOffset = 0 ;
2336+ int64_t mSize = 0 ;
23112337 // Cached pointers to the ChunkedArray associated to a column
23122338 arrow::ChunkedArray* mColumnChunks [framework::pack_size(columns_t {})];
23132339 RowViewSentinel mEnd ;
@@ -3470,6 +3496,13 @@ struct Join : Table<o2::aod::Hash<"JOIN"_h>, o2::aod::Hash<"JOIN/0"_h>, o2::aod:
34703496 bindInternalIndicesTo (this );
34713497 }
34723498 }
3499+ Join (std::shared_ptr<arrow::Table> table, uint64_t offset, uint64_t count)
3500+ : base{table, offset, count}
3501+ {
3502+ if (count != 0 ) {
3503+ bindInternalIndicesTo (this );
3504+ }
3505+ }
34733506 using base::bindExternalIndices;
34743507 using base::bindInternalIndicesTo;
34753508 static constexpr const uint32_t binding_origin = base::binding_origin;
@@ -3539,12 +3572,12 @@ struct Join : Table<o2::aod::Hash<"JOIN"_h>, o2::aod::Hash<"JOIN/0"_h>, o2::aod:
35393572
35403573 auto rawSlice (uint64_t start, uint64_t end) const
35413574 {
3542- return self_t {{ this ->asArrowTable ()-> Slice ( start, end - start + 1 )}, start };
3575+ return self_t {this ->asArrowTable (), start, end - start + 1 };
35433576 }
35443577
35453578 auto emptySlice () const
35463579 {
3547- return self_t {{ this ->asArrowTable ()-> Slice ( 0 , 0 )} , 0 };
3580+ return self_t {this ->asArrowTable (), 0 , 0 };
35483581 }
35493582
35503583 template <typename T>
0 commit comments