sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r1196921 - /incubator/sqoop/trunk/src/java/org/apache/sqoop/tool/CodeGenTool.java
Date Thu, 03 Nov 2011 02:27:59 GMT
Author: blee
Date: Thu Nov  3 02:27:58 2011
New Revision: 1196921

URL: http://svn.apache.org/viewvc?rev=1196921&view=rev
Log:
SQOOP-367 Codegen support for free-form query

Modified:
    incubator/sqoop/trunk/src/java/org/apache/sqoop/tool/CodeGenTool.java

Modified: incubator/sqoop/trunk/src/java/org/apache/sqoop/tool/CodeGenTool.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/trunk/src/java/org/apache/sqoop/tool/CodeGenTool.java?rev=1196921&r1=1196920&r2=1196921&view=diff
==============================================================================
--- incubator/sqoop/trunk/src/java/org/apache/sqoop/tool/CodeGenTool.java (original)
+++ incubator/sqoop/trunk/src/java/org/apache/sqoop/tool/CodeGenTool.java Thu Nov  3 02:27:58
2011
@@ -136,6 +136,11 @@ public class CodeGenTool extends com.clo
         .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 class CodeGenTool extends com.clo
     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 class CodeGenTool extends com.clo
     validateOutputFormatOptions(options);
     validateHiveOptions(options);
 
-    if (options.getTableName() == null) {
+    if (options.getTableName() == null
+     && options.getSqlQuery() == null) {
+      throw new InvalidOptionsException(
+          "--" + TABLE_ARG + " or --" + SQL_QUERY_ARG
+        + " is required for codegen. " + HELP_STR);
+    } else if (options.getTableName() != null
+            && options.getSqlQuery() != null) {
       throw new InvalidOptionsException(
-          "--table is required for code generation." + HELP_STR);
+          "Cannot specify --" + TABLE_ARG + " and --" + SQL_QUERY_ARG
+        + " together. " + HELP_STR);
     }
   }
 }



Mime
View raw message