Scan a chunk from the read state.
242252 {
242253 auto &state = global_state.Cast<ReadFileGlobalState>();
242254 if (done ||
file_list_idx.GetIndex() >= state.file_list->GetTotalFileCount()) {
242255 return AsyncResult(SourceResultType::FINISHED);
242256 }
242257
242258 auto files = state.file_list;
242259
242260 auto &fs = FileSystem::GetFileSystem(context);
242261 const idx_t out_idx = 0;
242262
242263
242264 unique_ptr<FileHandle> file_handle = nullptr;
242265
242266
242267 if (state.requires_file_open) {
242271 }
242272 flags.SetCachingMode(CachingMode::CACHE_REMOTE_ONLY);
242273 file_handle = fs.OpenFile(
file, flags);
242274 } else {
242275
242276
242278 output.SetCardinality(0);
242279 done = true;
242280 return SourceResultType::FINISHED;
242281 }
242282 }
242283
242284 for (
idx_t col_idx = 0; col_idx < state.column_ids.size(); col_idx++) {
242285
242286 auto proj_idx = state.column_ids[col_idx];
242288 continue;
242289 }
242290 try {
242291 switch (proj_idx) {
242292 case ReadFileBindData::FILE_NAME_COLUMN: {
242293 auto &file_name_vector = output.data[col_idx];
242295 FlatVector::GetData<string_t>(file_name_vector)[out_idx] = file_name_string;
242296 } break;
242297 case ReadFileBindData::FILE_CONTENT_COLUMN: {
242298 const auto file_size = file_handle->GetFileSize();
242299 AssertMaxFileSize(
file.path, file_size);
242300
242301
242302 if (!state.stream) {
242303 state.stream = make_uniq<MemoryStream>(BufferAllocator::Get(context), NextPowerOfTwo(file_size));
242304 }
242305 state.stream->Rewind();
242306
242307
242308 constexpr idx_t MAX_READ_SIZE = 128LL * 1024 * 1024;
242309 auto remaining_bytes = file_handle->IsPipe() ? MAX_READ_SIZE : file_size;
242310 while (remaining_bytes > 0) {
242311 const auto bytes_to_read = MinValue(remaining_bytes, MAX_READ_SIZE);
242312 state.stream->GrowCapacity(bytes_to_read);
242313 idx_t actually_read = NumericCast<idx_t>(
242314 file_handle->Read(state.stream->GetData() + state.stream->GetPosition(), bytes_to_read));
242315 state.stream->SetPosition(state.stream->GetPosition() + actually_read);
242316 AssertMaxFileSize(
file.path, state.stream->GetPosition());
242317
242318 if (file_handle->IsPipe()) {
242319 if (actually_read == 0) {
242320 remaining_bytes = 0;
242321 }
242322 continue;
242323 }
242324
242325 if (actually_read == 0) {
242326
242327 throw IOException(
"Failed to read file '%s' at offset %lu, unexpected EOF",
file.path,
242328 file_size - remaining_bytes);
242329 }
242330 remaining_bytes -= actually_read;
242331 }
242332
242333 auto &file_content_vector = output.data[col_idx];
242334 auto &content_string = FlatVector::GetData<string_t>(file_content_vector)[out_idx];
242335 content_string = string_t(char_ptr_cast(state.stream->GetData()),
242336 NumericCast<uint32_t>(state.stream->GetPosition()));
242337
242338 if (type == LogicalType::VARCHAR) {
242339 VERIFY(
file.path, content_string);
242340 }
242341 } break;
242342 case ReadFileBindData::FILE_SIZE_COLUMN: {
242343 auto &file_size_vector = output.data[col_idx];
242344 FlatVector::GetData<int64_t>(file_size_vector)[out_idx] =
242345 NumericCast<int64_t>(file_handle->GetFileSize());
242346 } break;
242347 case ReadFileBindData::FILE_LAST_MODIFIED_COLUMN: {
242348 auto &last_modified_vector = output.data[col_idx];
242349
242350
242351 try {
242352 const auto timestamp_seconds = fs.GetLastModifiedTime(*file_handle);
242353 FlatVector::GetData<timestamp_tz_t>(last_modified_vector)[out_idx] =
242354 timestamp_tz_t(timestamp_seconds);
242355 } catch (std::exception &ex) {
242356 ErrorData error(ex);
242357 if (error.Type() == ExceptionType::CONVERSION) {
242358 FlatVector::SetNull(last_modified_vector, out_idx, true);
242359 } else {
242360 throw;
242361 }
242362 }
242363 } break;
242364 default:
242365 break;
242366 }
242367 }
242368
242369
242370 catch (std::exception &ex) {
242371 ErrorData error(ex);
242372 if (error.Type() == ExceptionType::NOT_IMPLEMENTED) {
242373 FlatVector::SetNull(output.data[col_idx], out_idx, true);
242374 } else {
242375 throw;
242376 }
242377 }
242378 }
242379 output.SetCardinality(1);
242380 done = true;
242381 return AsyncResult(SourceResultType::HAVE_MORE_OUTPUT);
242382}
OpenFileInfo file
The file we are reading.
Definition duckdb.cpp:80254
static constexpr FileOpenFlags FILE_FLAGS_READ
Open file with read access.
Definition duckdb.hpp:7850
static constexpr FileOpenFlags FILE_FLAGS_DIRECT_IO
Use direct IO when reading/writing to the file.
Definition duckdb.hpp:7854
static DUCKDB_API bool IsRemoteFile(const string &path)
Whether or not a file is remote or local, based only on file path.
Definition duckdb.cpp:74413
const column_t COLUMN_IDENTIFIER_ROW_ID
Special value used to signify the ROW ID of a table.
Definition duckdb.cpp:50303
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static DUCKDB_API string_t AddString(Vector &vector, const char *data, idx_t len)
Add a string to the string heap of the vector (auxiliary data).
Definition duckdb.cpp:137889