Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::DirectFileReader Class Reference
Inheritance diagram for duckdb::DirectFileReader:
Collaboration diagram for duckdb::DirectFileReader:

Public Member Functions

 DirectFileReader (OpenFileInfo file_p, const LogicalType &type)
unique_ptr< BaseStatistics > GetStatistics (ClientContext &context, const string &name) override
 Get statistics for a specific column.
bool TryInitializeScan (ClientContext &context, GlobalTableFunctionState &gstate, LocalTableFunctionState &lstate) override
 Try to initialize a scan over the reader - this is done while the global lock is held.
AsyncResult Scan (ClientContext &context, GlobalTableFunctionState &global_state, LocalTableFunctionState &local_state, DataChunk &chunk) override
 Scan a chunk from the read state.
void FinishFile (ClientContext &context, GlobalTableFunctionState &gstate) override
 Finish scanning a given file.
string GetReaderType () const override
Public Member Functions inherited from duckdb::BaseFileReader
 BaseFileReader (OpenFileInfo file_p)
const vector< MultiFileColumnDefinition > & GetColumns () const
const string & GetFileName () const
virtual bool UseCastMap () const
virtual void AddVirtualColumn (column_t virtual_column_id)
 Adds a virtual column to be projected at the end.
virtual DUCKDB_API shared_ptr< BaseUnionData > GetUnionData (idx_t file_idx)
virtual DUCKDB_API void PrepareReader (ClientContext &context, GlobalTableFunctionState &)
 Prepare reader for scanning.
virtual void PrepareScan (ClientContext &context, GlobalTableFunctionState &gstate, LocalTableFunctionState &lstate)
 Prepare a scan - called after TryInitializeScan succeeds - this is done without any lock held.
virtual DUCKDB_API double GetProgressInFile (ClientContext &context)
 Get progress within a given file.
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const
Public Member Functions inherited from duckdb::enable_shared_from_this< BaseFileReader >
shared_ptr< BaseFileReader > shared_from_this ()

Private Attributes

bool done
LogicalType type

Additional Inherited Members

Public Attributes inherited from duckdb::BaseFileReader
OpenFileInfo file
 The file we are reading.
optional_idx file_list_idx
 (Optionally) The file index (generated by the multi file reader)
vector< MultiFileColumnDefinition > columns
 The set of columns for the current file.
MultiFileLocalColumnIds< MultiFileLocalColumnId > column_ids
 The column ids to read from the file.
vector< ColumnIndex > column_indexes
 The column indexes to read from the file.
unique_ptr< TableFilterSet > filters
 The set of table filters (adjusted to local indexes).
unordered_map< column_t, unique_ptr< Expression > > expression_map
unordered_map< column_t, LogicalType > cast_map
 The final types for various expressions - this is ONLY used if UseCastMap() is explicitly enabled.
unique_ptr< DeleteFilter > deletion_filter
 (Optionally) The deletion filter (generated by the multi file reader)
Protected Member Functions inherited from duckdb::enable_shared_from_this< BaseFileReader >
enable_shared_from_this & operator= (enable_shared_from_this const &) noexcept

Constructor & Destructor Documentation

◆ DirectFileReader()

duckdb::DirectFileReader::DirectFileReader ( OpenFileInfo file_p,
const LogicalType & type )
explicit
242212 : BaseFileReader(std::move(file_p)), done(false), type(type) {
242213 columns.push_back(MultiFileColumnDefinition("filename", LogicalType::VARCHAR));
242214 columns.push_back(MultiFileColumnDefinition("content", type));
242215 columns.push_back(MultiFileColumnDefinition("size", LogicalType::BIGINT));
242216 columns.push_back(MultiFileColumnDefinition("last_modified", LogicalType::TIMESTAMP_TZ));
242217}
vector< MultiFileColumnDefinition > columns
The set of columns for the current file.
Definition duckdb.cpp:80258

◆ ~DirectFileReader()

duckdb::DirectFileReader::~DirectFileReader ( )
override
242219 {
242220}

Member Function Documentation

◆ GetStatistics()

unique_ptr< BaseStatistics > duckdb::DirectFileReader::GetStatistics ( ClientContext & context,
const string & name )
overridevirtual

Get statistics for a specific column.

Reimplemented from duckdb::BaseFileReader.

242222 {
242223 return nullptr;
242224}

◆ TryInitializeScan()

bool duckdb::DirectFileReader::TryInitializeScan ( ClientContext & context,
GlobalTableFunctionState & gstate,
LocalTableFunctionState & lstate )
overridevirtual

Try to initialize a scan over the reader - this is done while the global lock is held.

Implements duckdb::BaseFileReader.

242227 {
242228 auto &state = gstate.Cast<ReadFileGlobalState>();
242229 return file_list_idx.GetIndex() < state.file_list->GetTotalFileCount() && !done;
242230}
optional_idx file_list_idx
(Optionally) The file index (generated by the multi file reader)
Definition duckdb.cpp:80256

◆ Scan()

AsyncResult duckdb::DirectFileReader::Scan ( ClientContext & context,
GlobalTableFunctionState & global_state,
LocalTableFunctionState & local_state,
DataChunk & chunk )
overridevirtual

Scan a chunk from the read state.

Implements duckdb::BaseFileReader.

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 // We utilize projection pushdown here to only read the file content if the 'data' column is requested
242264 unique_ptr<FileHandle> file_handle = nullptr;
242265
242266 // Given the columns requested, do we even need to open the file?
242267 if (state.requires_file_open) {
242268 auto flags = FileFlags::FILE_FLAGS_READ;
242269 if (FileSystem::IsRemoteFile(file.path)) {
242271 }
242272 flags.SetCachingMode(CachingMode::CACHE_REMOTE_ONLY);
242273 file_handle = fs.OpenFile(file, flags);
242274 } else {
242275 // At least verify that the file exist
242276 // The globbing behavior in remote filesystems can lead to files being listed that do not actually exist
242277 if (FileSystem::IsRemoteFile(file.path) && !fs.FileExists(file.path)) {
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 // We utilize projection pushdown to avoid potentially expensive fs operations.
242286 auto proj_idx = state.column_ids[col_idx];
242287 if (proj_idx == COLUMN_IDENTIFIER_ROW_ID) {
242288 continue;
242289 }
242290 try {
242291 switch (proj_idx) {
242292 case ReadFileBindData::FILE_NAME_COLUMN: {
242293 auto &file_name_vector = output.data[col_idx];
242294 auto file_name_string = StringVector::AddString(file_name_vector, file.path);
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 // Initialize write stream if not yet done
242302 if (!state.stream) {
242303 state.stream = make_uniq<MemoryStream>(BufferAllocator::Get(context), NextPowerOfTwo(file_size));
242304 }
242305 state.stream->Rewind();
242306
242307 // Read in batches of 128mb
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 // Uh oh, random EOF?
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 // This can sometimes fail (e.g. httpfs file system cant always parse the last modified time
242350 // correctly)
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 // Filesystems are not required to support all operations, so we just set the column to NULL if not
242369 // implemented
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
Here is the call graph for this function:

◆ FinishFile()

void duckdb::DirectFileReader::FinishFile ( ClientContext & context,
GlobalTableFunctionState & gstate )
overridevirtual

Finish scanning a given file.

Reimplemented from duckdb::BaseFileReader.

242384 {
242385 return;
242386}

◆ GetReaderType()

string duckdb::DirectFileReader::GetReaderType ( ) const
inlineoverridevirtual

Implements duckdb::BaseFileReader.

242155 {
242156 return "File";
242157 };

The documentation for this class was generated from the following file: