Skip to content

Conversation

@bkietz
Copy link
Member

@bkietz bkietz commented Nov 4, 2019

@bkietz bkietz requested a review from fsaintjacques November 4, 2019 20:33
@github-actions
Copy link

github-actions bot commented Nov 4, 2019

Copy link
Contributor

@fsaintjacques fsaintjacques left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an API perspective, this is the wrong approach. The caller can't disable this non-trivially (passing a selector with an empty base is... an implementation detail hack) and forces the caller to always pass a Selector even if there's none, e.g how can the user pass just an explicit list of FileStats?

This should live in PartitionScheme, independent of DataSourceDiscovery, Either via a prefix optional parameter or a composed StripBasePartitionScheme(child_scheme, prefix) if you don't want to add the prefix to all relevant schemes.

@nealrichardson any idea on how to make this ergonomic?

@fsaintjacques fsaintjacques changed the title ARROW-7058: [C++] FilSystemDataSourceDiscovery should apply partition schemes relative to its base dir ARROW-7058: [C++] FileSystemDataSourceDiscovery should apply partition schemes relative to its base dir Nov 5, 2019
@nealrichardson
Copy link
Member

IDK about C++ API ergonomics, I just know what the expected behavior should be. If I tell you my dataset is in /home/username/data/taxi, and it's partitioned in directories year, month, day, we should interpret that to mean relative to the dataset root directory, not the root of the file system. I can't think of any reason why I would want something other than that, so I don't see value in having a C++ API that makes me do extra work to avoid doing something illogical.

std::vector<fs::FileStats> files, PathPartitions* out) {
for (const auto& file : files) {
const auto& path = file.path();
if (file.path().substr(0, base_dir.size()) != base_dir) continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to decide what should be the most friendly behavior in such case. I'd tempted to vote for parse without trimming instead of skipping the file.

std::string path = file.path();
if (!base_dir.empty() && path.substr(0, base_dir.size()) == base_dir) {
  path = path.substr(base_dir.size());
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing some paths with a known prefix removed and other paths with an unknown prefix seems like a foot gun to me. I'd expect the files which lie outside base_dir to be picked up with a different instance of Discovery (with the correct base_dir for those files).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Ben. If I'm supplying my own file paths, and some are relative to the given "base_dir" and some aren't, (1) the simple partition scheme of applying a schema to path segments probably won't just work across all of them if they don't share a base_dir, and if I want to use it I should put them in different Discovery instances; and (2) if we tried to get partition info from files outside of base_dir, it will probably error in parsing the path segments, so continue and not assign partition data to that file is probably safest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants