From 048c6dc95d47c8b30e3a365c2a0fbbfe5a577eb9 Mon Sep 17 00:00:00 2001 From: FuqiaoWang Date: Sat, 23 Apr 2016 21:12:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?<>bug=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D:=E5=8F=AA=E5=A1=AB=E5=86=99Table=20SQL=20statement?= =?UTF-8?q?=E9=A1=B9=E6=97=B6=EF=BC=8C=E6=8A=A5=E4=B8=8D=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8F=90=E5=8F=96tableName=E9=94=99=E8=AF=AF=EF=BC=8C=E5=A1=AB?= =?UTF-8?q?=E5=86=99tableName=E9=A1=B9=E5=92=8CTable=20SQL=20statement?= =?UTF-8?q?=E9=A1=B9=E6=97=B6=EF=BC=8C=E6=8A=A5=E4=BA=8C=E8=80=85=E4=B8=8D?= =?UTF-8?q?=E5=8F=AF=E5=90=8C=E6=97=B6=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jdbc/GenericJdbcToInitializer.java | 41 ++++++++----------- .../jdbc/configuration/ToJobConfig.java | 3 -- 2 files changed, 18 insertions(+), 26 deletions(-) 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..314e0363a 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,24 @@ 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 +190,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..74e727891 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 @@ -52,9 +52,6 @@ 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"); From 493fcee31a6ac52bad5fe70f3920a2738fcff597 Mon Sep 17 00:00:00 2001 From: FrankQiao <425256284@qq.com> Date: Sat, 23 Apr 2016 22:47:18 +0800 Subject: [PATCH 2/2] When completing the TO part of a job, people cannot state custom SQL statement by any means. When both TableName and SQL statement are provided, it reports the BOTH exception:GENERIC_JDBC_CONNECTOR_0007("The table name and the table sql cannot be specified together"). When only the SQL statement is provided, it reports the CANNOT extract exception:Both table name and SQL cannot be specified. We simply modify the corresponding branch logic judgment and removed at the same time fill tableName, Table SQL validation --- .../apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java | 1 - .../apache/sqoop/connector/jdbc/configuration/ToJobConfig.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) 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 314e0363a..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 @@ -124,7 +124,6 @@ private void configureTableProperties(MutableContext context, LinkConfiguration 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 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 74e727891..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,7 +45,7 @@ public class ToJobConfig { @Input public Boolean shouldClearStageTable; - + public static class ConfigValidator extends AbstractValidator { @Override public void validate(ToJobConfig config) {