parquet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ziva...@apache.org
Subject [parquet-mr] branch master updated: PARQUET-1534: [parquet-cli] IllegalArgumentException on Windows (#627)
Date Mon, 27 May 2019 14:22:36 GMT
This is an automated email from the ASF dual-hosted git repository.

zivanfi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/parquet-mr.git


The following commit(s) were added to refs/heads/master by this push:
     new f1a719b  PARQUET-1534:  [parquet-cli] IllegalArgumentException on Windows (#627)
f1a719b is described below

commit f1a719b264cec72e17db463aaa413d3871d068a6
Author: Masayuki Takahashi <masayuki038@gmail.com>
AuthorDate: Mon May 27 23:22:31 2019 +0900

    PARQUET-1534:  [parquet-cli] IllegalArgumentException on Windows (#627)
    
    Calling BaseCommand#qualifiedURI with Windows file path, java.net.URI.create throws IllegalArgumentException
and the command execution is aborted.
---
 .../java/org/apache/parquet/cli/BaseCommand.java   |  15 ++--
 .../org/apache/parquet/cli/BaseCommandTest.java    | 100 +++++++++++++++++++++
 2 files changed, 108 insertions(+), 7 deletions(-)

diff --git a/parquet-cli/src/main/java/org/apache/parquet/cli/BaseCommand.java b/parquet-cli/src/main/java/org/apache/parquet/cli/BaseCommand.java
index 96ca5a5..1bd74bd 100644
--- a/parquet-cli/src/main/java/org/apache/parquet/cli/BaseCommand.java
+++ b/parquet-cli/src/main/java/org/apache/parquet/cli/BaseCommand.java
@@ -50,6 +50,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.MalformedURLException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.security.AccessController;
@@ -175,12 +176,13 @@ public abstract class BaseCommand implements Command, Configurable {
    * @throws IOException if there is an error creating a qualified URI
    */
   public URI qualifiedURI(String filename) throws IOException {
-    URI fileURI = URI.create(filename);
-    if (RESOURCE_URI_SCHEME.equals(fileURI.getScheme())) {
-      return fileURI;
-    } else {
-      return qualifiedPath(filename).toUri();
-    }
+    try {
+      URI fileURI = new URI(filename);
+      if (RESOURCE_URI_SCHEME.equals(fileURI.getScheme())) {
+        return fileURI;
+      }
+    } catch (URISyntaxException ignore) {}
+    return qualifiedPath(filename).toUri();
   }
 
   /**
@@ -392,5 +394,4 @@ public abstract class BaseCommand implements Command, Configurable {
           "Could not determine file format of %s.", source));
     }
   }
-
 }
diff --git a/parquet-cli/src/test/java/org/apache/parquet/cli/BaseCommandTest.java b/parquet-cli/src/test/java/org/apache/parquet/cli/BaseCommandTest.java
new file mode 100644
index 0000000..59985e5
--- /dev/null
+++ b/parquet-cli/src/test/java/org/apache/parquet/cli/BaseCommandTest.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.parquet.cli;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.List;
+
+public class BaseCommandTest {
+
+  private static final String FILE_PATH = "/var/tmp/test.parquet";
+  private static final String WIN_FILE_PATH = "C:\\Test\\Downloads\\test.parquet";
+
+  private Logger console = LoggerFactory.getLogger(BaseCommandTest.class);
+  private TestCommand command;
+
+  @Before
+  public void setUp() {
+    this.command = new TestCommand(this.console);
+  }
+
+  // For All OS
+  @Test
+  public void qualifiedPathTest() throws IOException {
+    Path path = this.command.qualifiedPath(FILE_PATH);
+    Assert.assertEquals("test.parquet", path.getName());
+  }
+
+  @Test
+  public void qualifiedURITest() throws IOException {
+    URI uri = this.command.qualifiedURI(FILE_PATH);
+    Assert.assertEquals("/var/tmp/test.parquet", uri.getPath());
+  }
+
+  @Test
+  public void qualifiedURIResourceURITest() throws IOException {
+    URI uri = this.command.qualifiedURI("resource:/a");
+    Assert.assertEquals("/a", uri.getPath());
+  }
+
+  // For Windows
+  @Test
+  public void qualifiedPathTestForWindows() throws IOException {
+    Assume.assumeTrue
+             (System.getProperty("os.name").toLowerCase().startsWith("win"));
+    Path path = this.command.qualifiedPath(WIN_FILE_PATH);
+    Assert.assertEquals("test.parquet", path.getName());
+  }
+
+  @Test
+  public void qualifiedURITestForWindows() throws IOException {
+    Assume.assumeTrue
+             (System.getProperty("os.name").toLowerCase().startsWith("win"));
+    URI uri = this.command.qualifiedURI(WIN_FILE_PATH);
+    Assert.assertEquals("/C:/Test/Downloads/test.parquet", uri.getPath());
+  }
+
+  class TestCommand extends BaseCommand {
+
+    public TestCommand(Logger console) {
+      super(console);
+      setConf(new Configuration());
+    }
+
+    @Override
+    public int run() throws IOException {
+      return 0;
+    }
+
+    @Override
+    public List<String> getExamples() {
+      return null;
+    }
+  }
+}


Mime
View raw message