diff --git beeline/pom.xml beeline/pom.xml
index 6ec1d1a..fbe0ed0 100644
--- beeline/pom.xml
+++ beeline/pom.xml
@@ -81,6 +81,11 @@
libthrift
${libthrift.version}
+
+ net.sf.supercsv
+ super-csv
+ ${super-csv.version}
+
org.apache.hive
diff --git beeline/src/java/org/apache/hive/beeline/SeparatedValuesOutputFormat.java beeline/src/java/org/apache/hive/beeline/SeparatedValuesOutputFormat.java
index 7853c3f..851b182 100644
--- beeline/src/java/org/apache/hive/beeline/SeparatedValuesOutputFormat.java
+++ beeline/src/java/org/apache/hive/beeline/SeparatedValuesOutputFormat.java
@@ -22,6 +22,12 @@
*/
package org.apache.hive.beeline;
+import java.io.IOException;
+import java.io.StringWriter;
+
+import org.apache.zookeeper.common.IOUtils;
+import org.supercsv.io.CsvListWriter;
+import org.supercsv.prefs.CsvPreference;
/**
* OutputFormat for values separated by a delimiter.
*
@@ -51,14 +57,23 @@ public int print(Rows rows) {
public void printRow(Rows rows, Rows.Row row) {
String[] vals = row.values;
- StringBuilder buf = new StringBuilder();
- for (int i = 0; i < vals.length; i++) {
- buf.append(buf.length() == 0 ? "" : "" + getSeparator())
- .append('\'')
- .append(vals[i] == null ? "" : vals[i])
- .append('\'');
+ StringWriter strWriter = new StringWriter();
+ CsvPreference STANDARD_SURROUNDING_SPACES_NEED_QUOTES =
+ new CsvPreference.Builder('"', this.getSeparator(), "")
+ .surroundingSpacesNeedQuotes(true).build();
+ CsvListWriter write =
+ new CsvListWriter(strWriter, STANDARD_SURROUNDING_SPACES_NEED_QUOTES);
+
+ if (vals.length > 0) {
+ try {
+ write.write(vals);
+ } catch (IOException e) {
+ beeLine.error(e);
+ } finally {
+ IOUtils.closeStream(write);
+ }
}
- beeLine.output(buf.toString());
+ beeLine.output(strWriter.toString());
}
public void setSeparator(char separator) {
diff --git itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java
index 8888bd9..e1d44ec 100644
--- itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java
+++ itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java
@@ -362,7 +362,7 @@ public void testNullEmpty() throws Throwable {
final String TEST_NAME = "testNullNonDefault";
final String SCRIPT_TEXT = "set hive.support.concurrency = false;\n" +
"!set nullemptystring true\n select 'abc',null,'def' from " + tableName + " limit 1 ;\n";
- final String EXPECTED_PATTERN = "'abc','','def'";
+ final String EXPECTED_PATTERN = "abc,,def";
List argList = getBaseArgs(JDBC_URL);
argList.add("--outputformat=csv");
@@ -382,7 +382,7 @@ public void testNullEmptyCmdArg() throws Throwable {
final String SCRIPT_TEXT = "set hive.support.concurrency = false;\n" +
"select 'abc',null,'def' from " + tableName + " limit 1 ;\n";
//final String EXPECTED_PATTERN = "| abc | | def |";
- final String EXPECTED_PATTERN = "'abc','','def'";
+ final String EXPECTED_PATTERN = "abc,,def";
List argList = getBaseArgs(JDBC_URL);
argList.add("--nullemptystring=true");
diff --git pom.xml pom.xml
index b5a5697..57c1c12 100644
--- pom.xml
+++ pom.xml
@@ -144,6 +144,7 @@
1.0.1
1.7.5
4.0.4
+ 2.2.0
0.4.0-incubating
1.1
0.2