You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sqoop.apache.org by "Jarek Jarcec Cecho (JIRA)" <ji...@apache.org> on 2012/10/15 00:07:03 UTC

[jira] [Updated] (SQOOP-585) Bug when sqoop a join of two tables with the same column name with mysql backend

     [ https://issues.apache.org/jira/browse/SQOOP-585?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jarek Jarcec Cecho updated SQOOP-585:
-------------------------------------

    Labels: newbie patch  (was: patch)
    
> Bug when sqoop a join of two tables with the same column name with mysql backend
> --------------------------------------------------------------------------------
>
>                 Key: SQOOP-585
>                 URL: https://issues.apache.org/jira/browse/SQOOP-585
>             Project: Sqoop
>          Issue Type: Bug
>          Components: connectors/sqlserver
>    Affects Versions: 1.4.1-incubating
>         Environment: - Mysql server backend (Postgres is fine)
> - using a --query argument to join over two tables with identical column names.  Here is an example of my sqoop command:
> JAVA_HOME=/usr ./bin/sqoop import \
>   --query 'SELECT events.*, square_applications.name as square_application, user_agents.name as user_agent from events LEFT JOIN square_applications on events.square_application_id=square_applications.id LEFT JOIN user_agents on events.user_agent_id=user_agents.id where $CONDITIONS' \
>   --boundary-query "SELECT MIN(id), MAX(id) from events"\
>   --split-by events.id \
>   --target-dir /tmp/sqoop/events \
>   --connect jdbc:mysql://localhost/development_database
>            Reporter: Vida Ha
>            Priority: Minor
>              Labels: newbie, patch
>             Fix For: 1.4.3
>
>         Attachments: columnLabel.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> I get this error when I run the command:
> INFO: Executing SQL statement: SELECT events.*, square_applications.name as square_application, user_agents.name as user_agent from events LEFT JOIN square_applications on events.square_application_id=square_applications.id LEFT JOIN user_agents on events.user_agent_id=user_agents.id where  (1 = 0) 
> Aug 23, 2012 10:10:56 AM org.apache.sqoop.tool.ImportTool run
> SEVERE: Imported Failed: Duplicate Column identifier specified: 'name'
> Calling "getColumnLabel" instead of "getColumnName" in SqlManager.java fixes this problem and this still works in postgres as well as mysql.  Here is my patch:
> Index: src/java/org/apache/sqoop/manager/SqlManager.java
> ===================================================================
> --- src/java/org/apache/sqoop/manager/SqlManager.java   (revision 1375124)
> +++ src/java/org/apache/sqoop/manager/SqlManager.java   (working copy)
> @@ -135,9 +135,9 @@
>        ArrayList<String> columns = new ArrayList<String>();
>        ResultSetMetaData metadata = results.getMetaData();
>        for (int i = 1; i < cols + 1; i++) {
> -        String colName = metadata.getColumnName(i);
> +        String colName = metadata.getColumnLabel(i);
>          if (colName == null || colName.equals("")) {
> -          colName = metadata.getColumnLabel(i);
> +          colName = metadata.getColumnName(i);
>            if (null == colName) {
>              colName = "_RESULT_" + i;
>            }
> @@ -208,9 +208,9 @@
>              typeId = Types.BIGINT;
>          }
>  
> -        String colName = metadata.getColumnName(i);
> +        String colName = metadata.getColumnLabel(i);
>          if (colName == null || colName.equals("")) {
> -          colName = metadata.getColumnLabel(i);
> +          colName = metadata.getColumnName(i);
>          }
>  
>          colTypes.put(colName, Integer.valueOf(typeId));

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira