Review Board 1.7.22


Fix for SQOOP-1097

Review Request #12342 - Created July 8, 2013 and updated

Venkat Ranganathan
SQOOP-1097
Reviewers
Sqoop
sqoop-trunk
Fix for mysql export using procedure.   While fixing this, found that Oracle export also has additional issues when using DB specific types that are not handled.   Fixed both the issues and provided a generic implementation for future db tests.
All unit tests pass.  Created a mysql and oracle specific test for testing both the functionality of doing procedure based export and handling db specific types
src/java/org/apache/sqoop/manager/ConnManager.java
Revision c9e05da New Change
[20] 365 lines
[+20] [+] public Type toAvroType(String tableName, String columnName, int sqlType) {
366
    LOG.error("This database does not support column type names.");
366
    LOG.error("This database does not support column type names.");
367
    return null;
367
    return null;
368
  }
368
  }
369

    
   
369

   
370
  /**
370
  /**
371
   * Return an unordered mapping from colname to sql type name for
371
   * Return an unordered mapping from colname to sql type name for all columns
372
   * all columns in a query.
372
   * in a procedure.

    
   
373
   */

    
   
374
  public Map<String, String> getColumnTypeNamesForProcedure(String callName) {

    
   
375
    LOG.error("This database does not support procedure param type names.");

    
   
376
    return null;

    
   
377
  }

    
   
378

   

    
   
379
  /**

    
   
380
   * Return an unordered mapping from colname to sql type name for all columns

    
   
381
   * in a query.
373
   */
382
   */
374
  public Map<String, String> getColumnTypeNamesForQuery(String query) {
383
  public Map<String, String> getColumnTypeNamesForQuery(String query) {
375
    LOG.error("This database does not support free-form query"
384
    LOG.error("This database does not support free-form query"
376
        + " column type names.");
385
        + " column type names.");
377
    return null;
386
    return null;
[+20] [20] 6 lines
[+20] public Type toAvroType(String tableName, String columnName, int sqlType) {
384
   * @param tableName the name of the table
393
   * @param tableName the name of the table
385
   * @param sqlQuery the SQL query to use if tableName is null
394
   * @param sqlQuery the SQL query to use if tableName is null
386
   */
395
   */
387
  public Map<String, String> getColumnTypeNames(String tableName,
396
  public Map<String, String> getColumnTypeNames(String tableName,
388
      String sqlQuery) {
397
    String sqlQuery) {

    
   
398
    return getColumnTypeNames(tableName, null, sqlQuery);

    
   
399
  }

    
   
400

   

    
   
401
  /**

    
   
402
   * Return an unordered mapping from colname to sql type name for all columns

    
   
403
   * in a table or query.

    
   
404
   *

    
   
405
   * @param tableName

    
   
406
   *          the name of the table

    
   
407
   * @param callName

    
   
408
   *          the name of the procedure

    
   
409
   * @param sqlQuery

    
   
410
   *          the SQL query to use if tableName is null

    
   
411
   */

    
   
412
  public Map<String, String> getColumnTypeNames(String tableName,

    
   
413
    String callName, String sqlQuery) {
389
    Map<String, String> columnTypeNames;
414
    Map<String, String> columnTypeNames;
390
    if (null != tableName) {
415
    if (null != tableName) {
391
      // We're generating a class based on a table import.
416
      // We're generating a class based on a table import.
392
      columnTypeNames = getColumnTypeNamesForTable(tableName);
417
      columnTypeNames = getColumnTypeNamesForTable(tableName);

    
   
418
    } else if (null != callName) {

    
   
419
      columnTypeNames = getColumnTypeNamesForProcedure(callName);
393
    } else {
420
    } else {
394
      // This is based on an arbitrary query.
421
      // This is based on an arbitrary query.
395
      String query = sqlQuery;
422
      String query = sqlQuery;
396
      if (query.indexOf(SqlManager.SUBSTITUTE_TOKEN) == -1) {
423
      if (query.indexOf(SqlManager.SUBSTITUTE_TOKEN) == -1) {
397
        throw new RuntimeException("Query [" + query + "] must contain '"
424
        throw new RuntimeException("Query [" + query + "] must contain '"
[+20] [20] 348 lines
src/java/org/apache/sqoop/manager/MySQLManager.java
Revision 2090b1a New Change
 
src/java/org/apache/sqoop/manager/OracleManager.java
Revision edc888e New Change
 
src/java/org/apache/sqoop/manager/SqlManager.java
Revision e96368b New Change
 
src/test/com/cloudera/sqoop/ThirdPartyTests.java
Revision 7fae052 New Change
 
src/test/org/apache/sqoop/TestExportUsingProcedure.java
Revision 6414ef7 New Change
 
src/test/org/apache/sqoop/manager/mysql/MySqlCallExportTest.java
New File
 
src/test/org/apache/sqoop/manager/oracle/OracleCallExportTest.java
New File
 
  1. src/java/org/apache/sqoop/manager/ConnManager.java: Loading...
  2. src/java/org/apache/sqoop/manager/MySQLManager.java: Loading...
  3. src/java/org/apache/sqoop/manager/OracleManager.java: Loading...
  4. src/java/org/apache/sqoop/manager/SqlManager.java: Loading...
  5. src/test/com/cloudera/sqoop/ThirdPartyTests.java: Loading...
  6. src/test/org/apache/sqoop/TestExportUsingProcedure.java: Loading...
  7. src/test/org/apache/sqoop/manager/mysql/MySqlCallExportTest.java: Loading...
  8. src/test/org/apache/sqoop/manager/oracle/OracleCallExportTest.java: Loading...