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::LocalGlobResult Struct Reference
Inheritance diagram for duckdb::LocalGlobResult:
Collaboration diagram for duckdb::LocalGlobResult:

Public Member Functions

 LocalGlobResult (LocalFileSystem &fs, const string &path, FileGlobOptions options, optional_ptr< FileOpener > opener)
 
- Public Member Functions inherited from duckdb::LazyMultiFileList
 LazyMultiFileList (optional_ptr< ClientContext > context)
 
vector< OpenFileInfoGetAllFiles () const override
 
FileExpandResult GetExpandResult () const override
 
idx_t GetTotalFileCount () const override
 Get the total file count - forces all files to be expanded / known so the exact count can be computed.
 
MultiFileCount GetFileCount (idx_t min_exact_count=0) const override
 
- Public Member Functions inherited from duckdb::MultiFileList
MultiFileListIterationHelper Files () const
 Get Iterator over the files for pretty for loops.
 
void InitializeScan (MultiFileListScanData &iterator) const
 Initialize a sequential scan over a file list.
 
bool Scan (MultiFileListScanData &iterator, OpenFileInfo &result_file) const
 Scan the next file into result_file, returns false when out of files.
 
OpenFileInfo GetFirstFile () const
 Returns the first file or an empty string if GetTotalFileCount() == 0.
 
bool IsEmpty () const
 Syntactic sugar for GetExpandResult() == FileExpandResult::NO_FILES.
 
virtual unique_ptr< MultiFileListComplexFilterPushdown (ClientContext &context, const MultiFileOptions &options, MultiFilePushdownInfo &info, vector< unique_ptr< Expression > > &filters) const
 Virtual functions for subclasses.
 
virtual unique_ptr< MultiFileListDynamicFilterPushdown (ClientContext &context, const MultiFileOptions &options, const vector< string > &names, const vector< LogicalType > &types, const vector< column_t > &column_ids, TableFilterSet &filters) const
 
virtual vector< OpenFileInfoGetDisplayFileList (optional_idx max_files=optional_idx()) const
 
virtual unique_ptr< NodeStatisticsGetCardinality (ClientContext &context) const
 
virtual unique_ptr< MultiFileListCopy () const
 
template<class TARGET >
TARGETCast ()
 
template<class TARGET >
const TARGETCast () const
 

Protected Member Functions

bool ExpandNextPath () const override
 Grabs the next path and expands it into Expanded paths: returns false if no more files to expand.
 
- Protected Member Functions inherited from duckdb::LazyMultiFileList
bool FileIsAvailable (idx_t i) const override
 Whether or not the file at the index is available instantly - or if this requires additional I/O.
 
OpenFileInfo GetFile (idx_t i) const override
 Get the i-th expanded file.
 

Private Attributes

LocalFileSystemfs
 
string path
 
optional_ptr< FileOpeneropener
 
vector< PathSplitsplits
 
bool absolute_path = false
 
std::priority_queue< ExpandDirectoryexpand_directories
 
bool finished = false
 

Additional Inherited Members

- Protected Attributes inherited from duckdb::LazyMultiFileList
mutex lock
 
vector< OpenFileInfoexpanded_files
 The expanded files.
 
bool all_files_expanded = false
 Whether or not all files have been expanded.
 
optional_ptr< ClientContextcontext
 

Constructor & Destructor Documentation

◆ LocalGlobResult()

duckdb::LocalGlobResult::LocalGlobResult ( LocalFileSystem fs,
const string &  path,
FileGlobOptions  options,
optional_ptr< FileOpener opener 
)
80051 : LazyMultiFileList(FileOpener::TryGetClientContext(opener)), fs(fs), path(fs.ExpandPath(path_p, opener)),
80052 opener(opener) {
80053 if (path.empty()) {
80054 finished = true;
80055 return;
80056 }
80057 // split up the path into separate chunks
80058 idx_t last_pos = 0;
80059 for (idx_t i = 0; i < path.size(); i++) {
80060 if (path[i] == '\\' || path[i] == '/') {
80061 if (i == last_pos) {
80062 // empty: skip this position
80063 last_pos = i + 1;
80064 continue;
80065 }
80066 if (splits.empty()) {
80067 splits.emplace_back(fs, path.substr(0, i));
80068 } else {
80069 splits.emplace_back(fs, path.substr(last_pos, i - last_pos));
80070 }
80071 last_pos = i + 1;
80072 }
80073 }
80074 splits.emplace_back(fs, path.substr(last_pos, path.size() - last_pos));
80075 // handle absolute paths
80076 absolute_path = false;
80077 if (fs.IsPathAbsolute(path)) {
80078 // first character is a slash - unix absolute path
80079 absolute_path = true;
80080 } else if (StringUtil::Contains(splits[0].path,
80081 ":")) { // TODO: this is weird? shouldn't IsPathAbsolute handle this?
80082 // first split has a colon - windows absolute path
80083 absolute_path = true;
80084 } else if (splits[0].path == "~") {
80085 // starts with home directory
80086 auto home_directory = fs.GetHomeDirectory(opener);
80087 if (!home_directory.empty()) {
80088 absolute_path = true;
80089 splits[0].path = home_directory;
80090 D_ASSERT(path[0] == '~');
80091 if (!fs.HasGlob(path)) {
80092 expanded_files = fs.FetchFileWithoutGlob(home_directory + path.substr(1), opener, absolute_path);
80093 finished = true;
80094 return;
80095 }
80096 }
80097 }
80098 // Check if the path has a glob at all
80099 if (!fs.HasGlob(path)) {
80100 // no glob: return only the file (if it exists or is a pipe)
80101 expanded_files = fs.FetchFileWithoutGlob(path, opener, absolute_path);
80102 finished = true;
80103 return;
80104 }
80105 if (absolute_path) {
80106 // for absolute paths, we don't start by scanning the current directory
80107 // FIXME: we don't support /[GLOB]/.. - i.e. globs in the first level of an absolute path
80108 if (splits.size() > 1) {
80109 expand_directories.emplace(splits[0].path, 1);
80110 }
80111 } else {
80112 // If file_search_path is set, use those paths as the first glob elements
80113 Value value;
80114 if (opener && opener->TryGetCurrentSetting("file_search_path", value)) {
80115 auto search_paths_str = value.ToString();
80116 auto search_paths = StringUtil::Split(search_paths_str, ',');
80117 for (const auto &search_path : search_paths) {
80118 expand_directories.emplace(search_path, 0);
80119 }
80120 }
80121 if (expand_directories.empty()) {
80122 expand_directories.emplace(".", 0, true);
80123 }
80124 }
80125
80126 if (HasMultipleCrawl(splits)) {
80127 throw IOException("Cannot use multiple \'**\' in one path");
80128 }
80129}
static DUCKDB_API string GetHomeDirectory(optional_ptr< FileOpener > opener)
Gets the users home directory.
Definition duckdb.cpp:73850
static DUCKDB_API string ExpandPath(const string &path, optional_ptr< FileOpener > opener)
Expands a given path, including e.g. expanding the home directory of the user.
Definition duckdb.cpp:73909
static DUCKDB_API bool HasGlob(const string &str)
Whether there is a glob in the string.
Definition duckdb.cpp:74130
vector< OpenFileInfo > expanded_files
The expanded files.
Definition duckdb.cpp:53855
bool IsPathAbsolute(const string &path) override
Checks if path is is an absolute path.
Definition duckdb.cpp:79196
static DUCKDB_API bool Contains(const string &haystack, const string &needle)
Returns true if the needle string exists in the haystack.
static DUCKDB_API vector< string > Split(const string &str, char delimiter)
Split the input string based on newline char.

Member Function Documentation

◆ ExpandNextPath()

bool duckdb::LocalGlobResult::ExpandNextPath ( ) const
overrideprotectedvirtual

Grabs the next path and expands it into Expanded paths: returns false if no more files to expand.

Implements duckdb::LazyMultiFileList.

80131 {
80132 if (finished) {
80133 return false;
80134 }
80135 if (expand_directories.empty()) {
80136 if (expanded_files.empty()) {
80137 // no result found that matches the glob
80138 // last ditch effort: search the path as a string literal
80139 expanded_files = fs.FetchFileWithoutGlob(path, opener, absolute_path);
80140 }
80141 finished = true;
80142 return false;
80143 }
80144
80145 auto next_dir = expand_directories.top();
80146 auto is_empty = next_dir.is_empty;
80147 auto split_index = next_dir.split_index;
80148 auto &current_path = next_dir.path;
80149 expand_directories.pop();
80150
80151 auto &next_split = splits[split_index];
80152 bool is_last_component = split_index + 1 == splits.size();
80153 auto &next_component = next_split.path;
80154 bool has_glob = next_split.has_glob;
80155 // if it's the last chunk we need to find files, otherwise we find directories
80156 // not the last chunk: gather a list of all directories that match the glob pattern
80157 if (!has_glob) {
80158 // no glob, just append as-is
80159 if (is_empty) {
80160 if (is_last_component) {
80161 throw InternalException("No glob in only component - but entire split has globs?");
80162 }
80163 // no path yet - just append
80164 expand_directories.emplace(next_component, split_index + 1);
80165 } else {
80166 if (is_last_component) {
80167 // last component - we are emitting a result here
80168 auto filename = fs.JoinPath(current_path, next_component);
80169 if (fs.FileExists(filename, opener) || fs.DirectoryExists(filename, opener)) {
80170 expanded_files.emplace_back(std::move(filename));
80171 }
80172 } else {
80173 // not the last component - add the next directory as "to-be-expanded"
80174 expand_directories.emplace(fs.JoinPath(current_path, next_component), split_index + 1);
80175 }
80176 }
80177 } else {
80178 // glob - need to resolve the glob
80179 if (IsCrawl(next_component)) {
80180 if (is_last_component) {
80181 // the crawl is the last component - we are looking for files in this directory
80182 // any directories we encounter are added to the expand directories
80183 CrawlDirectoryLevel(fs, current_path, expanded_files, expand_directories, split_index);
80184 } else {
80185 // not the last crawl
80186 // ** also matches the current directory (i.e. dir/**/file.parquet also matches dir/file.parquet)
80187 expand_directories.emplace(current_path, split_index + 1);
80188 // now crawl the contents of this directory - but don't add any files we find
80189 CrawlDirectoryLevel(fs, current_path, nullptr, expand_directories, split_index);
80190 }
80191 } else {
80192 // glob this directory according to the next component
80193 if (is_last_component) {
80194 // last component - match files and place them in the result
80195 GlobFilesInternal(fs, current_path, next_component, false, expanded_files);
80196 } else {
80197 // not the last component - match directories and add to expansion list
80198 vector<OpenFileInfo> child_directories;
80199 GlobFilesInternal(fs, current_path, next_component, true, child_directories);
80200 for (auto &file : child_directories) {
80201 expand_directories.emplace(std::move(file.path), split_index + 1);
80202 }
80203 }
80204 }
80205 }
80206 return true;
80207}
DUCKDB_API string JoinPath(const string &a, const string &path)
Join two paths together.
Definition duckdb.cpp:73803
bool FileExists(const string &filename, optional_ptr< FileOpener > opener=nullptr) override
Check if a file exists.
Definition duckdb.cpp:78440
bool DirectoryExists(const string &directory, optional_ptr< FileOpener > opener=nullptr) override
Check if a directory exists.
Definition duckdb.cpp:78992
Here is the call graph for this function:

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