phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajeshb...@apache.org
Subject phoenix git commit: PHOENIX-1523 Make it easy to provide a tab literal as separator for CSV imports(Sergey Soldatov)
Date Thu, 31 Mar 2016 08:51:07 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 6219dfe78 -> 437ac8270


PHOENIX-1523 Make it easy to provide a tab literal as separator for CSV imports(Sergey Soldatov)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/437ac827
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/437ac827
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/437ac827

Branch: refs/heads/4.x-HBase-0.98
Commit: 437ac827041e0474b16c59921894058accb552ce
Parents: 6219dfe
Author: Rajeshbabu Chintaguntla <rajeshbabu@apache.org>
Authored: Thu Mar 31 14:25:10 2016 +0530
Committer: Rajeshbabu Chintaguntla <rajeshbabu@apache.org>
Committed: Thu Mar 31 14:25:10 2016 +0530

----------------------------------------------------------------------
 .../phoenix/end2end/CsvBulkLoadToolIT.java      | 32 ++++++++++++++++++++
 .../phoenix/mapreduce/CsvBulkLoadTool.java      |  3 +-
 .../org/apache/phoenix/util/PhoenixRuntime.java |  8 +++--
 3 files changed, 39 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/437ac827/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
index 96042c5..1e9c1d9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
@@ -101,6 +101,38 @@ public class CsvBulkLoadToolIT extends BaseOwnClusterHBaseManagedTimeIT
{
     }
 
     @Test
+    public void testImportWithTabs() throws Exception {
+
+        Statement stmt = conn.createStatement();
+        stmt.execute("CREATE TABLE TABLE8 (ID INTEGER NOT NULL PRIMARY KEY, " +
+                "NAME1 VARCHAR, NAME2 VARCHAR)");
+
+        FileSystem fs = FileSystem.get(getUtility().getConfiguration());
+        FSDataOutputStream outputStream = fs.create(new Path("/tmp/input8.csv"));
+        PrintWriter printWriter = new PrintWriter(outputStream);
+        printWriter.println("1\tName 1a\tName 2a");
+        printWriter.println("2\tName 2a\tName 2b");
+        printWriter.close();
+
+        CsvBulkLoadTool csvBulkLoadTool = new CsvBulkLoadTool();
+        csvBulkLoadTool.setConf(getUtility().getConfiguration());
+        int exitCode = csvBulkLoadTool.run(new String[] {
+                "--input", "/tmp/input8.csv",
+                "--table", "table8",
+                "--zookeeper", zkQuorum,
+                "--delimiter", "\\t"});
+        assertEquals(0, exitCode);
+
+        ResultSet rs = stmt.executeQuery("SELECT id, name1, name2 FROM table8 ORDER BY id");
+        assertTrue(rs.next());
+        assertEquals(1, rs.getInt(1));
+        assertEquals("Name 1a", rs.getString(2));
+
+        rs.close();
+        stmt.close();
+    }
+
+    @Test
     public void testFullOptionImport() throws Exception {
 
         Statement stmt = conn.createStatement();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/437ac827/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/CsvBulkLoadTool.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/CsvBulkLoadTool.java
b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/CsvBulkLoadTool.java
index e0b083e..8ed66b8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/CsvBulkLoadTool.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/CsvBulkLoadTool.java
@@ -23,6 +23,7 @@ import java.util.List;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
+import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.mapreduce.Job;
 import org.apache.hadoop.util.ToolRunner;
@@ -54,7 +55,7 @@ public class CsvBulkLoadTool extends AbstractBulkLoadTool {
 
         char delimiterChar = ',';
         if (cmdLine.hasOption(DELIMITER_OPT.getOpt())) {
-            String delimString = cmdLine.getOptionValue(DELIMITER_OPT.getOpt());
+            String delimString = StringEscapeUtils.unescapeJava(cmdLine.getOptionValue(DELIMITER_OPT.getOpt()));
             if (delimString.length() != 1) {
                 throw new IllegalArgumentException("Illegal delimiter character: " + delimString);
             }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/437ac827/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
index 508446c..3117fa9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
@@ -49,6 +49,7 @@ import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
+import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.client.Mutation;
@@ -636,10 +637,11 @@ public class PhoenixRuntime {
         }
 
         private static char getCharacter(String s) {
-            if (s.length() > 1) {
-                throw new IllegalArgumentException("Invalid single character: '" + s + "'");
+            String unescaped = StringEscapeUtils.unescapeJava(s);
+            if (unescaped.length() > 1) {
+                throw new IllegalArgumentException("Invalid single character: '" + unescaped
+ "'");
             }
-            return s.charAt(0);
+            return unescaped.charAt(0);
         }
 
         private static void usageError(String errorMsg, Options options) {


Mime
View raw message