Fix temporary dataset_path creation for URIs related to remote fs
MEMBER
Hi ! Thanks for the fix :) 

I think this should be `extract_path_from_uri` 's responsibility to strip the extra `/` from a badly formatted path like `hdfs:///absolute/path` (or raise an error). Do you think you can simply do the changes in `extract_path_from_uri` ? This way this fix will be available for all the other parts of the lib that need to extract the inner path from an URI of a remote filesystem

Then we can also keep your test cases but simply apply them to `extract_path_from_uri` instead
2021-11-22T09:41:52Z
https://github.com/huggingface/datasets/pull/3296#issuecomment-975335632
https://api.github.com/repos/huggingface/datasets/issues/3296
IC_kwDODunzps46InDQ
https://api.github.com/repos/huggingface/datasets/issues/comments/975335632/reactions
2021-11-22T09:41:52Z
https://api.github.com/repos/huggingface/datasets/issues/comments/975335632
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
CONTRIBUTOR
Hi @lhoestq! No problem! Thanks for your interest! :)

I think stripping the 3rd `/` in `hdfs:///absolute/path` inside `extract_path_from_uri` is not the solution. When I provide `hdfs:///absolute/path` to `extract_path_from_uri` we want `/absolute/path` to be returned, as it does now (at least in the case of URIs with `hdfs` schemas, for `s3` is different as it should start with a bucket name).

The problem comes in line 1041 in the original code below:

https://github.com/huggingface/datasets/blob/42f6b1d18a4a1b6009b6e62d115491be16dfca22/src/datasets/arrow_dataset.py#L1038-L1042

Lets assume the following parameters for line 1041 after `extract_path_from_uri` has removed the `hdfs` schema part and the `://` from `hdfs:///absolute/path`, and `get_temporary_cache_files_directory()` returns `/tmp/a1b2b3c4`, as it is shown below: 

```python
src_dataset_path = '/absolute/path'
tmp_dir = '/tmp/a1b2b3c4'
dataset_path = Path(tmp_dir, src_dataset_path)
```

After passing those paths to the `Path` object, `dataset_path` contains only `/absolute/path`; that is, it has lost the temporary directory path. This is because, when two (or more) absolute paths are passed to the `Path` function, only the last one is taken. However, if the contents of those variables are:

```python
src_dataset_path = 'relative/path'
tmp_dir = '/tmp/a1b2b3c4'
dataset_path = Path(tmp_dir, src_dataset_path)
```

then `dataset_path` contains `/tmp/a1b2b3c4/relative/path` as expected.

Absolute paths are allowed in hdfs URIs, so that's why I added the extra function `build_local_temp_path` in the PR; so in case the second argument is an absolute path, it still will create the correct absolute path by concatenating the temp dir and the path passed by converting it to a relative path (and it also works for windows paths too.) It also allows to add the tests, checking that the main combinations are ok.

I've checked all the places where the result of `extract_path_from_uri` is used, and as far as I've seen this is the only place where it is concatenated with another possible absolute path, so no need to add `build_local_temp_path` anywhere else. 

2021-12-01T22:44:22Z
https://github.com/huggingface/datasets/pull/3296#issuecomment-984126044
https://api.github.com/repos/huggingface/datasets/issues/3296
IC_kwDODunzps46qJJc
https://api.github.com/repos/huggingface/datasets/issues/comments/984126044/reactions
2021-12-01T22:44:22Z
https://api.github.com/repos/huggingface/datasets/issues/comments/984126044
https://avatars.githubusercontent.com/u/918006?v=4
https://api.github.com/users/francisco-perez-sorrosal/events{/privacy}
https://api.github.com/users/francisco-perez-sorrosal/followers
https://api.github.com/users/francisco-perez-sorrosal/following{/other_user}
https://api.github.com/users/francisco-perez-sorrosal/gists{/gist_id}
https://github.com/francisco-perez-sorrosal
francisco-perez-sorrosal
MDQ6VXNlcjkxODAwNg==
https://api.github.com/users/francisco-perez-sorrosal/orgs
https://api.github.com/users/francisco-perez-sorrosal/received_events
https://api.github.com/users/francisco-perez-sorrosal/repos
https://api.github.com/users/francisco-perez-sorrosal/starred{/owner}{/repo}
https://api.github.com/users/francisco-perez-sorrosal/subscriptions
User
https://api.github.com/users/francisco-perez-sorrosal
public
This aims to close #3295