5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-04 01:32:20 +08:00

SQOOP-88. Parameterize pre-table-import validity checks in SqlManager.

Adds SqlManager.checkTableImportOptions() method called by importTable().

From: Aaron Kimball <aaron@cloudera.com>

git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1149978 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Bayer 2011-07-22 20:04:17 +00:00
parent 1a63734c0d
commit c7b1ddb708

View File

@ -335,6 +335,28 @@ protected String getSplitColumn(SqoopOptions opts, String tableName) {
return splitCol; return splitCol;
} }
/**
* Offers the ConnManager an opportunity to validate that the
* options specified in the ImportJobContext are valid.
* @throws ImportException if the import is misconfigured.
*/
protected void checkTableImportOptions(ImportJobContext context)
throws IOException, ImportException {
String tableName = context.getTableName();
SqoopOptions opts = context.getOptions();
// Default implementation: check that the split column is set
// correctly.
String splitCol = getSplitColumn(opts, tableName);
if (null == splitCol && opts.getNumMappers() > 1) {
// Can't infer a primary key.
throw new ImportException("No primary key could be found for table "
+ tableName + ". Please specify one with --split-by or perform "
+ "a sequential import with '-m 1'.");
}
}
/** /**
* Default implementation of importTable() is to launch a MapReduce job * Default implementation of importTable() is to launch a MapReduce job
* via DataDrivenImportJob to read the table with DataDrivenDBInputFormat. * via DataDrivenImportJob to read the table with DataDrivenDBInputFormat.
@ -357,14 +379,9 @@ public void importTable(ImportJobContext context)
context); context);
} }
String splitCol = getSplitColumn(opts, tableName); checkTableImportOptions(context);
if (null == splitCol && opts.getNumMappers() > 1) {
// Can't infer a primary key.
throw new ImportException("No primary key could be found for table "
+ tableName + ". Please specify one with --split-by or perform "
+ "a sequential import with '-m 1'.");
}
String splitCol = getSplitColumn(opts, tableName);
importer.runImport(tableName, jarFile, splitCol, opts.getConf()); importer.runImport(tableName, jarFile, splitCol, opts.getConf());
} }