mirror of
https://github.com/apache/sqoop.git
synced 2025-05-03 15:00:45 +08:00
SQOOP-67. NPE when column name list contains spaces
- e.g. sqoop -import --columns "col1, col2" From: Jonathan Hsieh <jon@cloudera.com> git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1150042 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c0ca0c100b
commit
cb911f34b4
@ -653,7 +653,11 @@ public void applyOptions(CommandLine in, SqoopOptions out)
|
||||
}
|
||||
|
||||
if (in.hasOption(COLUMNS_ARG)) {
|
||||
out.setColumns(in.getOptionValue(COLUMNS_ARG).split(","));
|
||||
String[] cols= in.getOptionValue(COLUMNS_ARG).split(",");
|
||||
for (int i=0; i<cols.length; i++) {
|
||||
cols[i] = cols[i].trim();
|
||||
}
|
||||
out.setColumns(cols);
|
||||
}
|
||||
|
||||
if (in.hasOption(SPLIT_BY_ARG)) {
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
package com.cloudera.sqoop;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@ -210,4 +212,39 @@ public void testSkipThirdCol() {
|
||||
verifyTypes(types, insertVals, validateVals, validateLine, loadCols);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests that the columns argument can handle comma-separated column
|
||||
* names. So this is like having:
|
||||
* --columns "DATA_COL0,DATA_COL1,DATA_COL2"
|
||||
* as two args on a sqoop command line
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void testSingleColumnsArg() throws IOException {
|
||||
String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" };
|
||||
String [] insertVals = { "'foo'", "'bar'", "'baz'" };
|
||||
String [] validateVals = { "foo", "bar", "baz" };
|
||||
String validateLine = "foo,bar,baz";
|
||||
String [] loadCols = {"DATA_COL0,DATA_COL1,DATA_COL2"};
|
||||
|
||||
verifyTypes(types, insertVals, validateVals, validateLine, loadCols);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests that the columns argument can handle spaces between column
|
||||
* names. So this is like having:
|
||||
* --columns "DATA_COL0, DATA_COL1, DATA_COL2"
|
||||
* as two args on a sqoop command line
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void testColumnsWithSpaces() throws IOException {
|
||||
String [] types = { "VARCHAR(32)", "VARCHAR(32)", "VARCHAR(32)" };
|
||||
String [] insertVals = { "'foo'", "'bar'", "'baz'" };
|
||||
String [] validateVals = { "foo", "bar", "baz" };
|
||||
String validateLine = "foo,bar,baz";
|
||||
String [] loadCols = {"DATA_COL0, DATA_COL1, DATA_COL2"};
|
||||
|
||||
verifyTypes(types, insertVals, validateVals, validateLine, loadCols);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user