[ 
https://issues.apache.org/jira/browse/HDFS-7031?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14126329#comment-14126329
 ] 

Chris Nauroth commented on HDFS-7031:
-------------------------------------

Hi, [~rdblue].

I've always understood the contract of {{Path#makeQualified}} to take an 
unqualified URI (no scheme/authority, possibly absolute or relative path) and 
join it to the default's scheme and authority to make it qualified, possibly 
also using working directory to turn a relative path into an absolute path.  In 
this example, the input is already a qualified URI.  It's unclear to me whether 
or not the contract is as clearly defined for this case.  The current behavior 
certainly looks wrong, but I can think of 2 possible "correct" behaviors:
# {{file://some/local/path}} - Your proposed change would do this.  
Essentially, I think this is saying don't change the input URI if it's already 
qualified.
# {{hdfs://nn:8020/some/local/path}} - This is saying that the URI must always 
be qualified against the specified default, possibly overriding an existing 
scheme and authority.  Arguably, this is more correct when called in the 
context of {{FileSystem#makeQualified}}, because the caller has requested the 
action for a specific {{FileSystem}} instance.

Is there any chance that your application's code upstream of {{Path}} is doing 
something incorrect?  Perhaps it needs to be passing a {{Path}} without the 
file scheme.  The {{Path}} class is widely used across the whole ecosystem, and 
the ambiguity around the contract in this case makes me a bit reluctant to 
change the behavior.

> Path#makeQualified copies authority when scheme does not match
> --------------------------------------------------------------
>
>                 Key: HDFS-7031
>                 URL: https://issues.apache.org/jira/browse/HDFS-7031
>             Project: Hadoop HDFS
>          Issue Type: Bug
>          Components: hdfs-client
>    Affects Versions: 2.3.0
>            Reporter: Ryan Blue
>
> I have an application that calls {{makeQualified}} that amounts to this:
> {code:java}
> new Path("file:/some/local/path").makeQualified(
>     URI.create("hdfs://nn:8020"), new Path("/"));
> {code}
> This unexpectedly produces {{file://nn:8020/some/local/path}}, using the 
> authority section from the default URI even though the path that is being 
> qualified doesn't have a scheme that matches the default URI.
> In {{Path}}, there is a check to see if the default URI should be used:
> {code:java}
>     if (scheme != null &&
>         (authority != null || defaultUri.getAuthority() == null))
>       return path;
> {code}
> I think this should be:
> {code:java}
>     // if the scheme matches and there is no authority, use the default
>     if (scheme != null && scheme.equals(defaultUri.getScheme()) &&
>         (authority != null || defaultUri.getAuthority() == null))
>       return path;
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to