You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by Richards Peter <hb...@gmail.com> on 2015/12/09 09:12:28 UTC

Determine absolute path of a file in hdfs

Hi,

I have a situation where I need to determine the absolute path of a file in
hadoop as a String. The path should exclude the schema and authority. Eg:
/mn/op/data/t1.dat

I found the following option in hadoop api:
https://hadoop.apache.org/docs/r2.6.2/api/org/apache/hadoop/fs/Path.html#getPathWithoutSchemeAndAuthority%28org.apache.hadoop.fs.Path%29

The aforementioned api returns a Path object. I do not want a new Path
object. Instead I would like to obtain the path as a String.

If I have the original path stored in a variable path (Path path), will
path.toUri().getPath() be sufficient to retrieve the intended path as a
String? I tried to obtain the path using this approach and I found it to
work fine for the cases that I tested. But I would like to take a
confirmation before I incorporate the code to my project.

Could you please confirm whether my approach is fine?

Thanks,
Richards Peter.

Re: Determine absolute path of a file in hdfs

Posted by Richards Peter <hb...@gmail.com>.
Thanks Chris for the confirmation.

Richards Peter.

On Wed, Dec 9, 2015 at 11:59 PM, Chris Nauroth <cn...@hortonworks.com>
wrote:

> Hello,
>
> Yes, path.toUri().getPath() is a reliable way to get the absolute path
> without scheme or authority as a String from a Path instance.  The Hadoop
> codebase itself uses this same pattern throughout a lot of JUnit tests when
> we need to run assertions on an absolute path.
>
> --Chris Nauroth
>
> From: Richards Peter <hb...@gmail.com>
> Date: Wednesday, December 9, 2015 at 1:12 AM
> To: "user@hadoop.apache.org" <us...@hadoop.apache.org>
> Subject: Determine absolute path of a file in hdfs
>
> Hi,
>
> I have a situation where I need to determine the absolute path of a file
> in hadoop as a String. The path should exclude the schema and authority.
> Eg: /mn/op/data/t1.dat
>
> I found the following option in hadoop api:
>
> https://hadoop.apache.org/docs/r2.6.2/api/org/apache/hadoop/fs/Path.html#getPathWithoutSchemeAndAuthority%28org.apache.hadoop.fs.Path%29
>
> The aforementioned api returns a Path object. I do not want a new Path
> object. Instead I would like to obtain the path as a String.
>
> If I have the original path stored in a variable path (Path path), will
> path.toUri().getPath() be sufficient to retrieve the intended path as a
> String? I tried to obtain the path using this approach and I found it to
> work fine for the cases that I tested. But I would like to take a
> confirmation before I incorporate the code to my project.
>
> Could you please confirm whether my approach is fine?
>
> Thanks,
> Richards Peter.
>

Re: Determine absolute path of a file in hdfs

Posted by Richards Peter <hb...@gmail.com>.
Thanks Chris for the confirmation.

Richards Peter.

On Wed, Dec 9, 2015 at 11:59 PM, Chris Nauroth <cn...@hortonworks.com>
wrote:

> Hello,
>
> Yes, path.toUri().getPath() is a reliable way to get the absolute path
> without scheme or authority as a String from a Path instance.  The Hadoop
> codebase itself uses this same pattern throughout a lot of JUnit tests when
> we need to run assertions on an absolute path.
>
> --Chris Nauroth
>
> From: Richards Peter <hb...@gmail.com>
> Date: Wednesday, December 9, 2015 at 1:12 AM
> To: "user@hadoop.apache.org" <us...@hadoop.apache.org>
> Subject: Determine absolute path of a file in hdfs
>
> Hi,
>
> I have a situation where I need to determine the absolute path of a file
> in hadoop as a String. The path should exclude the schema and authority.
> Eg: /mn/op/data/t1.dat
>
> I found the following option in hadoop api:
>
> https://hadoop.apache.org/docs/r2.6.2/api/org/apache/hadoop/fs/Path.html#getPathWithoutSchemeAndAuthority%28org.apache.hadoop.fs.Path%29
>
> The aforementioned api returns a Path object. I do not want a new Path
> object. Instead I would like to obtain the path as a String.
>
> If I have the original path stored in a variable path (Path path), will
> path.toUri().getPath() be sufficient to retrieve the intended path as a
> String? I tried to obtain the path using this approach and I found it to
> work fine for the cases that I tested. But I would like to take a
> confirmation before I incorporate the code to my project.
>
> Could you please confirm whether my approach is fine?
>
> Thanks,
> Richards Peter.
>

Re: Determine absolute path of a file in hdfs

Posted by Richards Peter <hb...@gmail.com>.
Thanks Chris for the confirmation.

Richards Peter.

On Wed, Dec 9, 2015 at 11:59 PM, Chris Nauroth <cn...@hortonworks.com>
wrote:

> Hello,
>
> Yes, path.toUri().getPath() is a reliable way to get the absolute path
> without scheme or authority as a String from a Path instance.  The Hadoop
> codebase itself uses this same pattern throughout a lot of JUnit tests when
> we need to run assertions on an absolute path.
>
> --Chris Nauroth
>
> From: Richards Peter <hb...@gmail.com>
> Date: Wednesday, December 9, 2015 at 1:12 AM
> To: "user@hadoop.apache.org" <us...@hadoop.apache.org>
> Subject: Determine absolute path of a file in hdfs
>
> Hi,
>
> I have a situation where I need to determine the absolute path of a file
> in hadoop as a String. The path should exclude the schema and authority.
> Eg: /mn/op/data/t1.dat
>
> I found the following option in hadoop api:
>
> https://hadoop.apache.org/docs/r2.6.2/api/org/apache/hadoop/fs/Path.html#getPathWithoutSchemeAndAuthority%28org.apache.hadoop.fs.Path%29
>
> The aforementioned api returns a Path object. I do not want a new Path
> object. Instead I would like to obtain the path as a String.
>
> If I have the original path stored in a variable path (Path path), will
> path.toUri().getPath() be sufficient to retrieve the intended path as a
> String? I tried to obtain the path using this approach and I found it to
> work fine for the cases that I tested. But I would like to take a
> confirmation before I incorporate the code to my project.
>
> Could you please confirm whether my approach is fine?
>
> Thanks,
> Richards Peter.
>

Re: Determine absolute path of a file in hdfs

Posted by Richards Peter <hb...@gmail.com>.
Thanks Chris for the confirmation.

Richards Peter.

On Wed, Dec 9, 2015 at 11:59 PM, Chris Nauroth <cn...@hortonworks.com>
wrote:

> Hello,
>
> Yes, path.toUri().getPath() is a reliable way to get the absolute path
> without scheme or authority as a String from a Path instance.  The Hadoop
> codebase itself uses this same pattern throughout a lot of JUnit tests when
> we need to run assertions on an absolute path.
>
> --Chris Nauroth
>
> From: Richards Peter <hb...@gmail.com>
> Date: Wednesday, December 9, 2015 at 1:12 AM
> To: "user@hadoop.apache.org" <us...@hadoop.apache.org>
> Subject: Determine absolute path of a file in hdfs
>
> Hi,
>
> I have a situation where I need to determine the absolute path of a file
> in hadoop as a String. The path should exclude the schema and authority.
> Eg: /mn/op/data/t1.dat
>
> I found the following option in hadoop api:
>
> https://hadoop.apache.org/docs/r2.6.2/api/org/apache/hadoop/fs/Path.html#getPathWithoutSchemeAndAuthority%28org.apache.hadoop.fs.Path%29
>
> The aforementioned api returns a Path object. I do not want a new Path
> object. Instead I would like to obtain the path as a String.
>
> If I have the original path stored in a variable path (Path path), will
> path.toUri().getPath() be sufficient to retrieve the intended path as a
> String? I tried to obtain the path using this approach and I found it to
> work fine for the cases that I tested. But I would like to take a
> confirmation before I incorporate the code to my project.
>
> Could you please confirm whether my approach is fine?
>
> Thanks,
> Richards Peter.
>

Re: Determine absolute path of a file in hdfs

Posted by Chris Nauroth <cn...@hortonworks.com>.
Hello,

Yes, path.toUri().getPath() is a reliable way to get the absolute path without scheme or authority as a String from a Path instance.  The Hadoop codebase itself uses this same pattern throughout a lot of JUnit tests when we need to run assertions on an absolute path.

--Chris Nauroth

From: Richards Peter <hb...@gmail.com>>
Date: Wednesday, December 9, 2015 at 1:12 AM
To: "user@hadoop.apache.org<ma...@hadoop.apache.org>" <us...@hadoop.apache.org>>
Subject: Determine absolute path of a file in hdfs

Hi,

I have a situation where I need to determine the absolute path of a file in hadoop as a String. The path should exclude the schema and authority. Eg: /mn/op/data/t1.dat

I found the following option in hadoop api:
https://hadoop.apache.org/docs/r2.6.2/api/org/apache/hadoop/fs/Path.html#getPathWithoutSchemeAndAuthority%28org.apache.hadoop.fs.Path%29

The aforementioned api returns a Path object. I do not want a new Path object. Instead I would like to obtain the path as a String.

If I have the original path stored in a variable path (Path path), will path.toUri().getPath() be sufficient to retrieve the intended path as a String? I tried to obtain the path using this approach and I found it to work fine for the cases that I tested. But I would like to take a confirmation before I incorporate the code to my project.

Could you please confirm whether my approach is fine?

Thanks,
Richards Peter.

Re: Determine absolute path of a file in hdfs

Posted by Chris Nauroth <cn...@hortonworks.com>.
Hello,

Yes, path.toUri().getPath() is a reliable way to get the absolute path without scheme or authority as a String from a Path instance.  The Hadoop codebase itself uses this same pattern throughout a lot of JUnit tests when we need to run assertions on an absolute path.

--Chris Nauroth

From: Richards Peter <hb...@gmail.com>>
Date: Wednesday, December 9, 2015 at 1:12 AM
To: "user@hadoop.apache.org<ma...@hadoop.apache.org>" <us...@hadoop.apache.org>>
Subject: Determine absolute path of a file in hdfs

Hi,

I have a situation where I need to determine the absolute path of a file in hadoop as a String. The path should exclude the schema and authority. Eg: /mn/op/data/t1.dat

I found the following option in hadoop api:
https://hadoop.apache.org/docs/r2.6.2/api/org/apache/hadoop/fs/Path.html#getPathWithoutSchemeAndAuthority%28org.apache.hadoop.fs.Path%29

The aforementioned api returns a Path object. I do not want a new Path object. Instead I would like to obtain the path as a String.

If I have the original path stored in a variable path (Path path), will path.toUri().getPath() be sufficient to retrieve the intended path as a String? I tried to obtain the path using this approach and I found it to work fine for the cases that I tested. But I would like to take a confirmation before I incorporate the code to my project.

Could you please confirm whether my approach is fine?

Thanks,
Richards Peter.

Re: Determine absolute path of a file in hdfs

Posted by Chris Nauroth <cn...@hortonworks.com>.
Hello,

Yes, path.toUri().getPath() is a reliable way to get the absolute path without scheme or authority as a String from a Path instance.  The Hadoop codebase itself uses this same pattern throughout a lot of JUnit tests when we need to run assertions on an absolute path.

--Chris Nauroth

From: Richards Peter <hb...@gmail.com>>
Date: Wednesday, December 9, 2015 at 1:12 AM
To: "user@hadoop.apache.org<ma...@hadoop.apache.org>" <us...@hadoop.apache.org>>
Subject: Determine absolute path of a file in hdfs

Hi,

I have a situation where I need to determine the absolute path of a file in hadoop as a String. The path should exclude the schema and authority. Eg: /mn/op/data/t1.dat

I found the following option in hadoop api:
https://hadoop.apache.org/docs/r2.6.2/api/org/apache/hadoop/fs/Path.html#getPathWithoutSchemeAndAuthority%28org.apache.hadoop.fs.Path%29

The aforementioned api returns a Path object. I do not want a new Path object. Instead I would like to obtain the path as a String.

If I have the original path stored in a variable path (Path path), will path.toUri().getPath() be sufficient to retrieve the intended path as a String? I tried to obtain the path using this approach and I found it to work fine for the cases that I tested. But I would like to take a confirmation before I incorporate the code to my project.

Could you please confirm whether my approach is fine?

Thanks,
Richards Peter.

Re: Determine absolute path of a file in hdfs

Posted by Chris Nauroth <cn...@hortonworks.com>.
Hello,

Yes, path.toUri().getPath() is a reliable way to get the absolute path without scheme or authority as a String from a Path instance.  The Hadoop codebase itself uses this same pattern throughout a lot of JUnit tests when we need to run assertions on an absolute path.

--Chris Nauroth

From: Richards Peter <hb...@gmail.com>>
Date: Wednesday, December 9, 2015 at 1:12 AM
To: "user@hadoop.apache.org<ma...@hadoop.apache.org>" <us...@hadoop.apache.org>>
Subject: Determine absolute path of a file in hdfs

Hi,

I have a situation where I need to determine the absolute path of a file in hadoop as a String. The path should exclude the schema and authority. Eg: /mn/op/data/t1.dat

I found the following option in hadoop api:
https://hadoop.apache.org/docs/r2.6.2/api/org/apache/hadoop/fs/Path.html#getPathWithoutSchemeAndAuthority%28org.apache.hadoop.fs.Path%29

The aforementioned api returns a Path object. I do not want a new Path object. Instead I would like to obtain the path as a String.

If I have the original path stored in a variable path (Path path), will path.toUri().getPath() be sufficient to retrieve the intended path as a String? I tried to obtain the path using this approach and I found it to work fine for the cases that I tested. But I would like to take a confirmation before I incorporate the code to my project.

Could you please confirm whether my approach is fine?

Thanks,
Richards Peter.