5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-03 05:31:14 +08:00

SQOOP-367 Codegen support for free-form query

git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1196921 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bilung Lee 2011-11-03 02:27:58 +00:00
parent 1598c5a481
commit d8a8c43009

View File

@ -136,6 +136,11 @@ public void configureOptions(ToolOptions toolOptions) {
.withDescription("Table to generate code for")
.withLongOpt(TABLE_ARG)
.create());
codeGenOpts.addOption(OptionBuilder.withArgName("statement")
.hasArg()
.withDescription("SQL 'statement' to generate code for")
.withLongOpt(SQL_QUERY_ARG)
.create(SQL_QUERY_SHORT_ARG));
toolOptions.addUniqueOptions(codeGenOpts);
toolOptions.addUniqueOptions(getOutputFormatOptions());
@ -160,6 +165,9 @@ public void applyOptions(CommandLine in, SqoopOptions out)
if (in.hasOption(TABLE_ARG)) {
out.setTableName(in.getOptionValue(TABLE_ARG));
}
if (in.hasOption(SQL_QUERY_ARG)) {
out.setSqlQuery(in.getOptionValue(SQL_QUERY_ARG));
}
applyCommonOptions(in, out);
applyOutputFormatOptions(in, out);
@ -182,9 +190,16 @@ public void validateOptions(SqoopOptions options)
validateOutputFormatOptions(options);
validateHiveOptions(options);
if (options.getTableName() == null) {
if (options.getTableName() == null
&& options.getSqlQuery() == null) {
throw new InvalidOptionsException(
"--table is required for code generation." + HELP_STR);
"--" + TABLE_ARG + " or --" + SQL_QUERY_ARG
+ " is required for codegen. " + HELP_STR);
} else if (options.getTableName() != null
&& options.getSqlQuery() != null) {
throw new InvalidOptionsException(
"Cannot specify --" + TABLE_ARG + " and --" + SQL_QUERY_ARG
+ " together. " + HELP_STR);
}
}
}