mirror of
https://github.com/apache/sqoop.git
synced 2025-05-03 19:21:37 +08:00
SQOOP-359 Import fails with Unknown SQL datatype exception
git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1180279 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d6eec1f2d5
commit
8711e293bd
@ -440,11 +440,19 @@ public void importQuery(ImportJobContext context)
|
|||||||
}
|
}
|
||||||
|
|
||||||
String splitCol = getSplitColumn(opts, null);
|
String splitCol = getSplitColumn(opts, null);
|
||||||
if (null == splitCol && opts.getNumMappers() > 1) {
|
if (splitCol == null) {
|
||||||
// Can't infer a primary key.
|
String boundaryQuery = opts.getBoundaryQuery();
|
||||||
throw new ImportException("A split-by column must be specified for "
|
if (opts.getNumMappers() > 1) {
|
||||||
+ "parallel free-form query imports. Please specify one with "
|
// Can't infer a primary key.
|
||||||
+ "--split-by or perform a sequential import with '-m 1'.");
|
throw new ImportException("A split-by column must be specified for "
|
||||||
|
+ "parallel free-form query imports. Please specify one with "
|
||||||
|
+ "--split-by or perform a sequential import with '-m 1'.");
|
||||||
|
} else if (boundaryQuery != null && !boundaryQuery.isEmpty()) {
|
||||||
|
// Query import with boundary query and no split column specified
|
||||||
|
throw new ImportException("Using a boundary query for a query based "
|
||||||
|
+ "import requires specifying the split by column as well. Please "
|
||||||
|
+ "specify a column name using --split-by and try again.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
importer.runImport(null, jarFile, splitCol, opts.getConf());
|
importer.runImport(null, jarFile, splitCol, opts.getConf());
|
||||||
|
@ -171,11 +171,16 @@ protected void configureInputFormat(Job job, String tableName,
|
|||||||
String inputBoundingQuery = options.getBoundaryQuery();
|
String inputBoundingQuery = options.getBoundaryQuery();
|
||||||
|
|
||||||
if(inputBoundingQuery == null) {
|
if(inputBoundingQuery == null) {
|
||||||
|
inputBoundingQuery =
|
||||||
mgr.getInputBoundsQuery(splitByCol, sanitizedQuery);
|
mgr.getInputBoundsQuery(splitByCol, sanitizedQuery);
|
||||||
}
|
if (inputBoundingQuery == null) {
|
||||||
if (inputBoundingQuery == null) {
|
if (splitByCol != null) {
|
||||||
inputBoundingQuery = "SELECT MIN(" + splitByCol + "), MAX("
|
inputBoundingQuery = "SELECT MIN(" + splitByCol + "), MAX("
|
||||||
+ splitByCol + ") FROM (" + sanitizedQuery + ") AS t1";
|
+ splitByCol + ") FROM (" + sanitizedQuery + ") AS t1";
|
||||||
|
} else {
|
||||||
|
inputBoundingQuery = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DataDrivenDBInputFormat.setInput(job, DBWritable.class,
|
DataDrivenDBInputFormat.setInput(job, DBWritable.class,
|
||||||
inputQuery, inputBoundingQuery);
|
inputQuery, inputBoundingQuery);
|
||||||
|
@ -46,8 +46,9 @@ public class TestBoundaryQuery extends ImportJobTestCase {
|
|||||||
* Create the argv to pass to Sqoop.
|
* Create the argv to pass to Sqoop.
|
||||||
* @return the argv as an array of strings.
|
* @return the argv as an array of strings.
|
||||||
*/
|
*/
|
||||||
protected String [] getArgv(boolean includeHadoopFlags, String boundaryQuery,
|
protected String [] getArgv(boolean includeHadoopFlags, boolean tableImport,
|
||||||
String targetDir) {
|
String boundaryQuery,
|
||||||
|
String targetDir, String... extraArgs) {
|
||||||
|
|
||||||
ArrayList<String> args = new ArrayList<String>();
|
ArrayList<String> args = new ArrayList<String>();
|
||||||
|
|
||||||
@ -55,20 +56,29 @@ public class TestBoundaryQuery extends ImportJobTestCase {
|
|||||||
CommonArgs.addHadoopFlags(args);
|
CommonArgs.addHadoopFlags(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
args.add("--table");
|
if (tableImport) {
|
||||||
args.add(HsqldbTestServer.getTableName());
|
args.add("--table");
|
||||||
args.add("--split-by");
|
args.add(HsqldbTestServer.getTableName());
|
||||||
args.add("INTFIELD1");
|
} else {
|
||||||
|
args.add("--query");
|
||||||
|
args.add("SELECT INTFIELD1, INTFIELD2 FROM "
|
||||||
|
+ HsqldbTestServer.getTableName() + " WHERE $CONDITIONS");
|
||||||
|
}
|
||||||
args.add("--connect");
|
args.add("--connect");
|
||||||
args.add(HsqldbTestServer.getUrl());
|
args.add(HsqldbTestServer.getUrl());
|
||||||
args.add("--boundary-query");
|
if (boundaryQuery != null) {
|
||||||
args.add(boundaryQuery);
|
args.add("--boundary-query");
|
||||||
|
args.add(boundaryQuery);
|
||||||
|
}
|
||||||
args.add("--as-sequencefile");
|
args.add("--as-sequencefile");
|
||||||
args.add("--target-dir");
|
args.add("--target-dir");
|
||||||
args.add(targetDir);
|
args.add(targetDir);
|
||||||
args.add("--class-name");
|
args.add("--class-name");
|
||||||
args.add(getTableName());
|
args.add(getTableName());
|
||||||
args.add("--verbose");
|
args.add("--verbose");
|
||||||
|
for (String extraArg : extraArgs) {
|
||||||
|
args.add(extraArg);
|
||||||
|
}
|
||||||
|
|
||||||
return args.toArray(new String[0]);
|
return args.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
@ -89,18 +99,18 @@ private int getFirstInt(String str) {
|
|||||||
return Integer.parseInt(parts[0]);
|
return Integer.parseInt(parts[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runQueryTest(String query, int numExpectedResults,
|
public void runQueryTest(String query, boolean tableImport,
|
||||||
int expectedSum, String targetDir)
|
int numExpectedResults, int expectedSum, String targetDir,
|
||||||
throws IOException {
|
String... extraArgs) throws IOException {
|
||||||
|
|
||||||
ClassLoader prevClassLoader = null;
|
ClassLoader prevClassLoader = null;
|
||||||
SequenceFile.Reader reader = null;
|
SequenceFile.Reader reader = null;
|
||||||
|
|
||||||
String [] argv = getArgv(true, query, targetDir);
|
String [] argv = getArgv(true, tableImport, query, targetDir, extraArgs);
|
||||||
runImport(argv);
|
runImport(argv);
|
||||||
try {
|
try {
|
||||||
SqoopOptions opts = new ImportTool().parseArguments(
|
SqoopOptions opts = new ImportTool().parseArguments(
|
||||||
getArgv(false, query, targetDir),
|
getArgv(false, tableImport, query, targetDir, extraArgs),
|
||||||
null, null, true);
|
null, null, true);
|
||||||
|
|
||||||
CompilationManager compileMgr = new CompilationManager(opts);
|
CompilationManager compileMgr = new CompilationManager(opts);
|
||||||
@ -161,6 +171,13 @@ public void testBoundaryQuery() throws IOException {
|
|||||||
String query = "select min(intfield1), max(intfield1) from "
|
String query = "select min(intfield1), max(intfield1) from "
|
||||||
+ getTableName() +" where intfield1 in (3, 5)";
|
+ getTableName() +" where intfield1 in (3, 5)";
|
||||||
|
|
||||||
runQueryTest(query, 2, 8, getTablePath().toString());
|
runQueryTest(query, true, 2, 8, getTablePath().toString(),
|
||||||
|
"--split-by", "INTFIELD1");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testNoBoundaryQuerySingleMapper() throws IOException {
|
||||||
|
|
||||||
|
runQueryTest(null, false, 4, 16, getTablePath().toString(),
|
||||||
|
"--m", "1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user