You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ra...@apache.org on 2016/03/31 10:49:07 UTC
phoenix git commit: PHOENIX-1523 Make it easy to provide a tab
literal as separator for CSV imports(Sergey Soldatov)
Repository: phoenix
Updated Branches:
refs/heads/master b98805039 -> 9e767ff55
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/9e767ff5
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/9e767ff5
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/9e767ff5
Branch: refs/heads/master
Commit: 9e767ff559517332670eff102cedcdd7f54d6246
Parents: b988050
Author: Rajeshbabu Chintaguntla <ra...@apache.org>
Authored: Thu Mar 31 14:22:54 2016 +0530
Committer: Rajeshbabu Chintaguntla <ra...@apache.org>
Committed: Thu Mar 31 14:22:54 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/9e767ff5/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/9e767ff5/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/9e767ff5/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 73b2f7a..2b6619a 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;
@@ -633,10 +634,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) {