diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java index c2515a539..3b5e05e3d 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java @@ -122,13 +122,23 @@ private void configureTableProperties(MutableContext context, LinkConfiguration String tableSql = toJobConfig.toJobConfig.sql; String tableColumns = toJobConfig.toJobConfig.columns; - if (tableName != null && tableSql != null) { - // when both fromTable name and fromTable sql are specified: - throw new SqoopException( - GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0007); + if (tableSql != null) { + // when toTable sql is specified: + if (tableSql.indexOf( + GenericJdbcConnectorConstants.SQL_PARAMETER_MARKER) == -1) { + // make sure parameter marker is in the specified sql + throw new SqoopException( + GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0013); + } - } else if (tableName != null) { - // when fromTable name is specified: + if (tableColumns == null) { + dataSql = tableSql; + } else { + throw new SqoopException( + GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0014); + } + }else if (tableName != null) { + // when toTable name is specified: if(stageEnabled) { LOG.info("Stage has been enabled."); LOG.info("Use stageTable: " + stageTableName + @@ -179,23 +189,7 @@ private void configureTableProperties(MutableContext context, LinkConfiguration builder.append(")"); dataSql = builder.toString(); } - } else if (tableSql != null) { - // when fromTable sql is specified: - - if (tableSql.indexOf( - GenericJdbcConnectorConstants.SQL_PARAMETER_MARKER) == -1) { - // make sure parameter marker is in the specified sql - throw new SqoopException( - GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0013); - } - - if (tableColumns == null) { - dataSql = tableSql; - } else { - throw new SqoopException( - GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0014); - } - } else { + } else { // when neither are specified: throw new SqoopException( GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0008); diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/configuration/ToJobConfig.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/configuration/ToJobConfig.java index c9651d536..633ace47d 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/configuration/ToJobConfig.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/configuration/ToJobConfig.java @@ -45,16 +45,13 @@ public class ToJobConfig { @Input public Boolean shouldClearStageTable; - + public static class ConfigValidator extends AbstractValidator { @Override public void validate(ToJobConfig config) { if (config.tableName == null && config.sql == null) { addMessage(Status.ERROR, "Either table name or SQL must be specified"); } - if (config.tableName != null && config.sql != null) { - addMessage(Status.ERROR, "Both table name and SQL cannot be specified"); - } if (config.tableName == null && config.stageTableName != null) { addMessage(Status.ERROR, "Stage table name cannot be specified without specifying table name");