sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arv...@apache.org
Subject svn commit: r1170977 - in /incubator/sqoop/trunk/src: java/com/cloudera/sqoop/orm/AvroSchemaGenerator.java test/com/cloudera/sqoop/TestAvroImportExportRoundtrip.java
Date Thu, 15 Sep 2011 06:55:33 GMT
Author: arvind
Date: Thu Sep 15 06:55:33 2011
New Revision: 1170977

URL: http://svn.apache.org/viewvc?rev=1170977&view=rev
Log:
SQOOP-332. Cannot use --as-avrodatafile with --query.

(Joseph Boyd via Arvind Prabhakar)

Modified:
    incubator/sqoop/trunk/src/java/com/cloudera/sqoop/orm/AvroSchemaGenerator.java
    incubator/sqoop/trunk/src/test/com/cloudera/sqoop/TestAvroImportExportRoundtrip.java

Modified: incubator/sqoop/trunk/src/java/com/cloudera/sqoop/orm/AvroSchemaGenerator.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/trunk/src/java/com/cloudera/sqoop/orm/AvroSchemaGenerator.java?rev=1170977&r1=1170976&r2=1170977&view=diff
==============================================================================
--- incubator/sqoop/trunk/src/java/com/cloudera/sqoop/orm/AvroSchemaGenerator.java (original)
+++ incubator/sqoop/trunk/src/java/com/cloudera/sqoop/orm/AvroSchemaGenerator.java Thu Sep
15 06:55:33 2011
@@ -63,10 +63,13 @@ public class AvroSchemaGenerator {
       field.addProp("sqlType", Integer.toString(sqlType));
       fields.add(field);
     }
-    String doc = "Sqoop import of " + tableName;
-    Schema schema = Schema.createRecord(tableName, doc, null, false);
+
+    String avroTableName = (tableName == null ? "QueryResult" : tableName);
+
+    String doc = "Sqoop import of " + avroTableName;
+    Schema schema = Schema.createRecord(avroTableName, doc, null, false);
     schema.setFields(fields);
-    schema.addProp("tableName", tableName);
+    schema.addProp("tableName", avroTableName);
     return schema;
   }
 

Modified: incubator/sqoop/trunk/src/test/com/cloudera/sqoop/TestAvroImportExportRoundtrip.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/trunk/src/test/com/cloudera/sqoop/TestAvroImportExportRoundtrip.java?rev=1170977&r1=1170976&r2=1170977&view=diff
==============================================================================
--- incubator/sqoop/trunk/src/test/com/cloudera/sqoop/TestAvroImportExportRoundtrip.java (original)
+++ incubator/sqoop/trunk/src/test/com/cloudera/sqoop/TestAvroImportExportRoundtrip.java Thu
Sep 15 06:55:33 2011
@@ -44,6 +44,16 @@ public class TestAvroImportExportRoundtr
   public static final Log LOG = LogFactory
       .getLog(TestAvroImportExportRoundtrip.class.getName());
 
+  public void testRoundtripQuery() throws IOException, SQLException {
+    String[] argv = {};
+
+    runImport(getOutputArgvForQuery(true));
+    deleteTableData();
+    runExport(getExportArgvForQuery(true, 10, 10, newStrArray(argv, "-m", "" + 1)));
+
+    checkFirstColumnSum();
+  }
+
   public void testRoundtrip() throws IOException, SQLException {
     String[] argv = {};
 
@@ -81,13 +91,79 @@ public class TestAvroImportExportRoundtr
 
   /**
    * Create the argv to pass to Sqoop.
+   *
+   * @return the argv as an array of strings.
+   */
+  protected String[] getOutputArgvForQuery(boolean includeHadoopFlags) {
+    ArrayList<String> args = new ArrayList<String>();
+
+    if (includeHadoopFlags) {
+      CommonArgs.addHadoopFlags(args);
+    }
+
+    args.add("--query");
+    args.add("select * from " + HsqldbTestServer.getTableName() + " where $CONDITIONS");
+    args.add("--connect");
+    args.add(HsqldbTestServer.getUrl());
+    args.add("--target-dir");
+    args.add(getWarehouseDir() + "/query_result");
+    args.add("--split-by");
+    args.add("INTFIELD1");
+    args.add("--as-avrodatafile");
+
+    return args.toArray(new String[0]);
+  }
+
+  protected String [] getExportArgv(boolean includeHadoopFlags,
+      int rowsPerStmt, int statementsPerTx, String... additionalArgv) {
+    ArrayList<String> args = formatAdditionalArgs(additionalArgv);
+
+    args.add("--table");
+    args.add(getTableName());
+    args.add("--export-dir");
+    args.add(getTablePath().toString());
+    args.add("--connect");
+    args.add(getConnectString());
+    args.add("-m");
+    args.add("1");
+
+    LOG.debug("args:");
+    for (String a : args) {
+      LOG.debug("  " + a);
+    }
+
+    return args.toArray(new String[0]);
+  }
+
+  protected String [] getExportArgvForQuery(boolean includeHadoopFlags,
+      int rowsPerStmt, int statementsPerTx, String... additionalArgv) {
+    ArrayList<String> args = formatAdditionalArgs(additionalArgv);
+
+    args.add("--table");
+    args.add(getTableName());
+    args.add("--export-dir");
+    args.add(getWarehouseDir() + "/query_result");
+    args.add("--connect");
+    args.add(getConnectString());
+    args.add("-m");
+    args.add("1");
+
+    LOG.debug("args:");
+    for (String a : args) {
+      LOG.debug("  " + a);
+    }
+
+    return args.toArray(new String[0]);
+  }
+
+  /**
+   * Create the argv to pass to Sqoop.
    * @param includeHadoopFlags if true, then include -D various.settings=values
    * @param rowsPerStmt number of rows to export in a single INSERT statement.
    * @param statementsPerTx ## of statements to use in a transaction.
    * @return the argv as an array of strings.
    */
-  protected String [] getExportArgv(boolean includeHadoopFlags,
-      int rowsPerStmt, int statementsPerTx, String... additionalArgv) {
+  protected ArrayList<String> formatAdditionalArgs(String... additionalArgv) {
     ArrayList<String> args = new ArrayList<String>();
 
     // Any additional Hadoop flags (-D foo=bar) are prepended.
@@ -120,22 +196,7 @@ public class TestAvroImportExportRoundtr
         }
       }
     }
-
-    args.add("--table");
-    args.add(getTableName());
-    args.add("--export-dir");
-    args.add(getTablePath().toString());
-    args.add("--connect");
-    args.add(getConnectString());
-    args.add("-m");
-    args.add("1");
-
-    LOG.debug("args:");
-    for (String a : args) {
-      LOG.debug("  " + a);
-    }
-
-    return args.toArray(new String[0]);
+    return args;
   }
 
   // this test just uses the two int table.



Mime
View raw message