You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Vladimir Sitnikov (Jira)" <ji...@apache.org> on 2020/04/16 08:30:00 UTC

[jira] [Commented] (CALCITE-3790) Make the URL of FileSource available

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

Vladimir Sitnikov commented on CALCITE-3790:
--------------------------------------------

File#toURI produces absolute URI always.

I wonder if we should handle {{!f.isAbsolute()}} so it produces **relative** URL:

{code:java}String filePath = file.getPath();
      if (!file.isAbsolute()) {
        if (File.separatorChar != '/') {
          filePath = filePath.replace(File.separatorChar, '/');
        }
        if (file.isDirectory() && !filePath.endsWith("/")) {
          filePath += "/";
        }
        try {
          return new URL("file", null, 0, URLEncoder.encode(filePath, StandardCharsets.UTF_8.name()));
        } catch (MalformedURLException e) {
          throw new IllegalArgumentException("Unable to create URI for file " + filePath, e);
        } catch (UnsupportedEncodingException e) {
          throw new IllegalArgumentException("UTF-8 is not found", e);
        }
      }{code}

Then it would align the behaviours for relative files and URLs like {{file:relative/path.txt}}
Note: relative URLs are already implemented and tested.

> Make the URL of FileSource available
> ------------------------------------
>
>                 Key: CALCITE-3790
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3790
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Liya Fan
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 4h 20m
>  Remaining Estimate: 0h
>
> When a FileSource is constructed with only a File object, its URL is left null. This makes it inconvenient for some scenarios where a valid URL is required.
> This can be resolved, as each file in the local file system corresponds to a file URL, and we fix it by converting a file object to a file URL.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)