|
36 | 36 | #include "arrow/status.h" |
37 | 37 | #include "arrow/type.h" |
38 | 38 | #include "arrow/type_fwd.h" |
| 39 | +#include "arrow/util/checked_cast.h" |
39 | 40 | #include "arrow/util/logging_internal.h" |
40 | 41 | #include "arrow/util/task_group.h" |
41 | 42 |
|
42 | 43 | namespace arrow { |
43 | 44 |
|
| 45 | +using internal::checked_pointer_cast; |
44 | 46 | using internal::TaskGroup; |
45 | 47 |
|
46 | 48 | namespace csv { |
47 | 49 |
|
48 | 50 | class BlockParser; |
49 | 51 |
|
50 | | -class ConcreteColumnBuilder : public ColumnBuilder { |
| 52 | +class ConcreteColumnBuilder : public ColumnBuilder, |
| 53 | + public std::enable_shared_from_this<ConcreteColumnBuilder> { |
51 | 54 | public: |
52 | 55 | explicit ConcreteColumnBuilder(MemoryPool* pool, std::shared_ptr<TaskGroup> task_group, |
53 | 56 | int32_t col_index = -1) |
@@ -152,15 +155,17 @@ void NullColumnBuilder::Insert(int64_t block_index, |
152 | 155 | const int32_t num_rows = parser->num_rows(); |
153 | 156 | DCHECK_GE(num_rows, 0); |
154 | 157 |
|
155 | | - task_group_->Append([this, block_index, num_rows]() -> Status { |
156 | | - std::unique_ptr<ArrayBuilder> builder; |
157 | | - RETURN_NOT_OK(MakeBuilder(pool_, type_, &builder)); |
158 | | - std::shared_ptr<Array> res; |
159 | | - RETURN_NOT_OK(builder->AppendNulls(num_rows)); |
160 | | - RETURN_NOT_OK(builder->Finish(&res)); |
161 | | - |
162 | | - return SetChunk(block_index, res); |
163 | | - }); |
| 158 | + // `self` keeps us alive, `this` allows easy access to derived / protected member vars |
| 159 | + task_group_->Append( |
| 160 | + [self = shared_from_this(), this, block_index, num_rows]() -> Status { |
| 161 | + std::unique_ptr<ArrayBuilder> builder; |
| 162 | + RETURN_NOT_OK(MakeBuilder(pool_, type_, &builder)); |
| 163 | + std::shared_ptr<Array> res; |
| 164 | + RETURN_NOT_OK(builder->AppendNulls(num_rows)); |
| 165 | + RETURN_NOT_OK(builder->Finish(&res)); |
| 166 | + |
| 167 | + return SetChunk(block_index, res); |
| 168 | + }); |
164 | 169 | } |
165 | 170 |
|
166 | 171 | ////////////////////////////////////////////////////////////////////////// |
@@ -202,7 +207,7 @@ void TypedColumnBuilder::Insert(int64_t block_index, |
202 | 207 | ReserveChunks(block_index); |
203 | 208 |
|
204 | 209 | // We're careful that all references in the closure outlive the Append() call |
205 | | - task_group_->Append([this, parser, block_index]() -> Status { |
| 210 | + task_group_->Append([self = shared_from_this(), this, parser, block_index]() -> Status { |
206 | 211 | return SetChunk(block_index, converter_->Convert(*parser, col_index_)); |
207 | 212 | }); |
208 | 213 | } |
@@ -257,7 +262,9 @@ Status InferringColumnBuilder::UpdateType() { |
257 | 262 | } |
258 | 263 |
|
259 | 264 | void InferringColumnBuilder::ScheduleConvertChunk(int64_t chunk_index) { |
260 | | - task_group_->Append([this, chunk_index]() { return TryConvertChunk(chunk_index); }); |
| 265 | + task_group_->Append([self = shared_from_this(), this, chunk_index]() { |
| 266 | + return TryConvertChunk(chunk_index); |
| 267 | + }); |
261 | 268 | } |
262 | 269 |
|
263 | 270 | Status InferringColumnBuilder::TryConvertChunk(int64_t chunk_index) { |
|
0 commit comments