You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sqoop.apache.org by "Abhijeet Gaikwad (JIRA)" <ji...@apache.org> on 2012/08/23 20:11:42 UTC

[jira] [Commented] (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:comment-tabpanel&focusedCommentId=13440502#comment-13440502 ] 

Abhijeet Gaikwad commented on SQOOP-585:
----------------------------------------

As a formality:
1. Can you please change affect-version to the sqoop version you found this error on.
2. Please attach patch file rather pasting patch in the description. If can you see "More Actions" drop down at the top, then you have the privileges.

Thanks.
                
> 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.3
>         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: 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: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira