mirror of
https://github.com/apache/sqoop.git
synced 2025-05-10 02:40:49 +08:00
SQOOP-2445. Sqoop2: Generic JDBC: Prevent use of tableColumns and sql at the same time
(Jarcec via Hari)
This commit is contained in:
parent
6be57ae7e6
commit
a70975c669
@ -285,25 +285,10 @@ private void configureTableProperties(MutableContext context, LinkConfiguration
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert tableSql.contains(GenericJdbcConnectorConstants.SQL_CONDITIONS_TOKEN);
|
assert tableSql.contains(GenericJdbcConnectorConstants.SQL_CONDITIONS_TOKEN);
|
||||||
|
dataSql = tableSql;
|
||||||
|
|
||||||
if (tableColumns == null) {
|
String[] queryColumns = executor.getQueryColumns(dataSql.replace(GenericJdbcConnectorConstants.SQL_CONDITIONS_TOKEN, "1 = 0"));
|
||||||
dataSql = tableSql;
|
fieldNames = executor.columnList(queryColumns);
|
||||||
|
|
||||||
String[] queryColumns = executor.getQueryColumns(dataSql.replace(GenericJdbcConnectorConstants.SQL_CONDITIONS_TOKEN, "1 = 0"));
|
|
||||||
fieldNames = executor.columnList(queryColumns);
|
|
||||||
} else {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("SELECT ");
|
|
||||||
builder.append(tableColumns);
|
|
||||||
builder.append(" FROM ");
|
|
||||||
builder.append("(");
|
|
||||||
builder.append(tableSql);
|
|
||||||
builder.append(") ");
|
|
||||||
builder.append(GenericJdbcConnectorConstants.SUBQUERY_ALIAS);
|
|
||||||
dataSql = builder.toString();
|
|
||||||
|
|
||||||
fieldNames = tableColumns;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info("Using dataSql: " + dataSql);
|
LOG.info("Using dataSql: " + dataSql);
|
||||||
|
@ -64,7 +64,10 @@ public void validate(FromJobConfig config) {
|
|||||||
addMessage(Status.ERROR, "Both schema name and SQL cannot be specified");
|
addMessage(Status.ERROR, "Both schema name and SQL cannot be specified");
|
||||||
}
|
}
|
||||||
if (config.sql != null && config.partitionColumn == null) {
|
if (config.sql != null && config.partitionColumn == null) {
|
||||||
addMessage(Status.ERROR, "Partition column is required on query based import.");
|
addMessage(Status.ERROR, "Partition column is required on query based import");
|
||||||
|
}
|
||||||
|
if(config.sql != null && config.columns != null) {
|
||||||
|
addMessage(Status.ERROR, "Can't use sql import and specify columns at the same time");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,34 +312,6 @@ public void testIncrementalTableSqlFromZero() throws Exception {
|
|||||||
assertEquals(String.valueOf(START+NUMBER_OF_ROWS-1), context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_LAST_INCREMENTAL_VALUE));
|
assertEquals(String.valueOf(START+NUMBER_OF_ROWS-1), context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_LAST_INCREMENTAL_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void testTableSqlWithTableColumns() throws Exception {
|
|
||||||
LinkConfiguration linkConfig = new LinkConfiguration();
|
|
||||||
FromJobConfiguration jobConfig = new FromJobConfiguration();
|
|
||||||
|
|
||||||
linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
|
|
||||||
linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
|
|
||||||
jobConfig.fromJobConfig.sql = schemalessTableSql;
|
|
||||||
jobConfig.fromJobConfig.columns = tableColumns;
|
|
||||||
jobConfig.fromJobConfig.partitionColumn = "DCOL";
|
|
||||||
|
|
||||||
MutableContext context = new MutableMapContext();
|
|
||||||
InitializerContext initializerContext = new InitializerContext(context);
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
Initializer initializer = new GenericJdbcFromInitializer();
|
|
||||||
initializer.initialize(initializerContext, linkConfig, jobConfig);
|
|
||||||
|
|
||||||
verifyResult(context,
|
|
||||||
"SELECT ICOL,VCOL FROM (" + schemalessTableSql + ") SQOOP_SUBQUERY_ALIAS",
|
|
||||||
tableColumns,
|
|
||||||
"\"DCOL\"",
|
|
||||||
String.valueOf(Types.DOUBLE),
|
|
||||||
String.valueOf((double)START),
|
|
||||||
String.valueOf((double)(START+NUMBER_OF_ROWS-1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testTableNameWithSchema() throws Exception {
|
public void testTableNameWithSchema() throws Exception {
|
||||||
@ -473,35 +445,6 @@ public void testGetSchemaForSql() throws Exception {
|
|||||||
assertEquals(getSchema("Query"), schema);
|
assertEquals(getSchema("Query"), schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void testTableSqlWithTableColumnsWithSchema() throws Exception {
|
|
||||||
LinkConfiguration linkConfig = new LinkConfiguration();
|
|
||||||
FromJobConfiguration jobConfig = new FromJobConfiguration();
|
|
||||||
|
|
||||||
linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
|
|
||||||
linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;
|
|
||||||
jobConfig.fromJobConfig.schemaName = schemaName;
|
|
||||||
jobConfig.fromJobConfig.sql = tableSql;
|
|
||||||
jobConfig.fromJobConfig.columns = tableColumns;
|
|
||||||
jobConfig.fromJobConfig.partitionColumn = "DCOL";
|
|
||||||
|
|
||||||
MutableContext context = new MutableMapContext();
|
|
||||||
InitializerContext initializerContext = new InitializerContext(context);
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
Initializer initializer = new GenericJdbcFromInitializer();
|
|
||||||
initializer.initialize(initializerContext, linkConfig, jobConfig);
|
|
||||||
|
|
||||||
verifyResult(context,
|
|
||||||
"SELECT ICOL,VCOL FROM (" + tableSql + ") SQOOP_SUBQUERY_ALIAS",
|
|
||||||
tableColumns,
|
|
||||||
"\"DCOL\"",
|
|
||||||
String.valueOf(Types.DOUBLE),
|
|
||||||
String.valueOf((double)START),
|
|
||||||
String.valueOf((double)(START+NUMBER_OF_ROWS-1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts expected content inside the generated context.
|
* Asserts expected content inside the generated context.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user