5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-17 01:11:07 +08:00

SQOOP-827: Sqoop2: MMapInput is null while retrieving from DB if pass empty map on write

(Mengwei Ding via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2013-08-19 08:26:52 -07:00
parent d140c5ddd0
commit 78235e39df
5 changed files with 74 additions and 29 deletions

View File

@ -32,8 +32,8 @@ public MMapInput(String name, boolean sensitive) {
@Override @Override
public String getUrlSafeValueString() { public String getUrlSafeValueString() {
Map<String, String> valueMap = getValue(); Map<String, String> valueMap = getValue();
if (valueMap == null || valueMap.size() == 0) { if (valueMap == null) {
return ""; return null;
} }
boolean first = true; boolean first = true;
StringBuilder vsb = new StringBuilder(); StringBuilder vsb = new StringBuilder();
@ -51,9 +51,11 @@ public String getUrlSafeValueString() {
@Override @Override
public void restoreFromUrlSafeValueString(String valueString) { public void restoreFromUrlSafeValueString(String valueString) {
Map<String, String> valueMap = null; if (valueString == null) {
if (valueString != null && valueString.trim().length() > 0) { setValue(null);
valueMap = new HashMap<String, String>(); } else {
Map<String, String> valueMap = new HashMap<String, String>();
if (valueString.trim().length() > 0) {
String[] valuePairs = valueString.split("&"); String[] valuePairs = valueString.split("&");
for (String pair : valuePairs) { for (String pair : valuePairs) {
String[] nameAndVal = pair.split("="); String[] nameAndVal = pair.split("=");
@ -70,6 +72,7 @@ public void restoreFromUrlSafeValueString(String valueString) {
} }
setValue(valueMap); setValue(valueMap);
} }
}
@Override @Override
public MInputType getType() { public MInputType getType() {

View File

@ -19,6 +19,7 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -82,7 +83,13 @@ public void testUrlSafe() {
String tmp = input1.getUrlSafeValueString(); String tmp = input1.getUrlSafeValueString();
// Restore to actual value // Restore to actual value
input1.restoreFromUrlSafeValueString(tmp); input1.restoreFromUrlSafeValueString(tmp);
assertEquals(null, input1.getValue()); assertNotNull(input1.getValue());
assertEquals(0, input1.getValue().size());
input1.setValue(null);
tmp = input1.getUrlSafeValueString();
input1.restoreFromUrlSafeValueString(tmp);
assertNull(input1.getValue());
} }
/** /**

View File

@ -27,6 +27,7 @@
import org.apache.sqoop.model.MInput; import org.apache.sqoop.model.MInput;
import org.apache.sqoop.model.MJob; import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MJobForms; import org.apache.sqoop.model.MJobForms;
import org.apache.sqoop.model.MMapInput;
import org.apache.sqoop.model.MStringInput; import org.apache.sqoop.model.MStringInput;
import java.sql.Connection; import java.sql.Connection;
@ -197,7 +198,7 @@ protected void loadConnectorAndFramework() throws Exception {
+ " VALUES('I1', " + (x * 6 + i * 2 + 1) + ", 0, 'STRING', false, 30)"); + " VALUES('I1', " + (x * 6 + i * 2 + 1) + ", 0, 'STRING', false, 30)");
runQuery("INSERT INTO SQOOP.SQ_INPUT" runQuery("INSERT INTO SQOOP.SQ_INPUT"
+"(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)" +"(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
+ " VALUES('I2', " + (x * 6 + i * 2 + 1) + ", 1, 'STRING', false, 30)"); + " VALUES('I2', " + (x * 6 + i * 2 + 1) + ", 1, 'MAP', false, 30)");
// Second form // Second form
runQuery("INSERT INTO SQOOP.SQ_INPUT" runQuery("INSERT INTO SQOOP.SQ_INPUT"
@ -205,7 +206,7 @@ protected void loadConnectorAndFramework() throws Exception {
+ " VALUES('I3', " + (x * 6 + i * 2 + 2) + ", 0, 'STRING', false, 30)"); + " VALUES('I3', " + (x * 6 + i * 2 + 2) + ", 0, 'STRING', false, 30)");
runQuery("INSERT INTO SQOOP.SQ_INPUT" runQuery("INSERT INTO SQOOP.SQ_INPUT"
+"(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)" +"(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
+ " VALUES('I4', " + (x * 6 + i * 2 + 2) + ", 1, 'STRING', false, 30)"); + " VALUES('I4', " + (x * 6 + i * 2 + 2) + ", 1, 'MAP', false, 30)");
} }
} }
} }
@ -360,14 +361,14 @@ protected List<MForm> getForms() {
inputs = new LinkedList<MInput<?>>(); inputs = new LinkedList<MInput<?>>();
input = new MStringInput("I1", false, (short)30); input = new MStringInput("I1", false, (short)30);
inputs.add(input); inputs.add(input);
input = new MStringInput("I2", false, (short)30); input = new MMapInput("I2", false);
inputs.add(input); inputs.add(input);
forms.add(new MForm("F1", inputs)); forms.add(new MForm("F1", inputs));
inputs = new LinkedList<MInput<?>>(); inputs = new LinkedList<MInput<?>>();
input = new MStringInput("I3", false, (short)30); input = new MStringInput("I3", false, (short)30);
inputs.add(input); inputs.add(input);
input = new MStringInput("I4", false, (short)30); input = new MMapInput("I4", false);
inputs.add(input); inputs.add(input);
forms.add(new MForm("F2", inputs)); forms.add(new MForm("F2", inputs));

View File

@ -21,9 +21,12 @@
import org.apache.sqoop.model.MConnection; import org.apache.sqoop.model.MConnection;
import org.apache.sqoop.model.MForm; import org.apache.sqoop.model.MForm;
import org.apache.sqoop.model.MJob; import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MMapInput;
import org.apache.sqoop.model.MStringInput; import org.apache.sqoop.model.MStringInput;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Test connection methods on Derby repository. * Test connection methods on Derby repository.
@ -166,10 +169,16 @@ public void testUpdateConnection() throws Exception {
List<MForm> forms; List<MForm> forms;
forms = connection.getConnectorPart().getForms(); forms = connection.getConnectorPart().getForms();
((MStringInput)forms.get(0).getInputs().get(1)).setValue("Injected"); ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated");
((MMapInput)forms.get(0).getInputs().get(1)).setValue(null);
((MStringInput)forms.get(1).getInputs().get(0)).setValue("Updated");
((MMapInput)forms.get(1).getInputs().get(1)).setValue(null);
forms = connection.getFrameworkPart().getForms(); forms = connection.getFrameworkPart().getForms();
((MStringInput)forms.get(1).getInputs().get(1)).setValue("Injected"); ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated");
((MMapInput)forms.get(0).getInputs().get(1)).setValue(new HashMap<String, String>()); // inject new map value
((MStringInput)forms.get(1).getInputs().get(0)).setValue("Updated");
((MMapInput)forms.get(1).getInputs().get(1)).setValue(new HashMap<String, String>()); // inject new map value
connection.setName("name"); connection.setName("name");
@ -183,10 +192,18 @@ public void testUpdateConnection() throws Exception {
assertEquals("name", connection.getName()); assertEquals("name", connection.getName());
forms = retrieved.getConnectorPart().getForms(); forms = retrieved.getConnectorPart().getForms();
assertEquals("Injected", forms.get(0).getInputs().get(1).getValue()); assertEquals("Updated", forms.get(0).getInputs().get(0).getValue());
assertNull(forms.get(0).getInputs().get(1).getValue());
assertEquals("Updated", forms.get(1).getInputs().get(0).getValue());
assertNull(forms.get(1).getInputs().get(1).getValue());
forms = retrieved.getFrameworkPart().getForms(); forms = retrieved.getFrameworkPart().getForms();
assertEquals("Injected", forms.get(1).getInputs().get(1).getValue()); assertEquals("Updated", forms.get(0).getInputs().get(0).getValue());
assertNotNull(forms.get(0).getInputs().get(1).getValue());
assertEquals(((Map)forms.get(0).getInputs().get(1).getValue()).size(), 0);
assertEquals("Updated", forms.get(1).getInputs().get(0).getValue());
assertNotNull(forms.get(1).getInputs().get(1).getValue());
assertEquals(((Map)forms.get(1).getInputs().get(1).getValue()).size(), 0);
} }
public void testEnableAndDisableConnection() throws Exception { public void testEnableAndDisableConnection() throws Exception {

View File

@ -20,9 +20,12 @@
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.model.MForm; import org.apache.sqoop.model.MForm;
import org.apache.sqoop.model.MJob; import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MMapInput;
import org.apache.sqoop.model.MStringInput; import org.apache.sqoop.model.MStringInput;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Test job methods on Derby repository. * Test job methods on Derby repository.
@ -182,10 +185,16 @@ public void testUpdateJob() throws Exception {
List<MForm> forms; List<MForm> forms;
forms = job.getConnectorPart().getForms(); forms = job.getConnectorPart().getForms();
((MStringInput)forms.get(0).getInputs().get(1)).setValue("Injected"); ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated");
((MMapInput)forms.get(0).getInputs().get(1)).setValue(null);
((MStringInput)forms.get(1).getInputs().get(0)).setValue("Updated");
((MMapInput)forms.get(1).getInputs().get(1)).setValue(null);
forms = job.getFrameworkPart().getForms(); forms = job.getFrameworkPart().getForms();
((MStringInput)forms.get(1).getInputs().get(1)).setValue("Injected"); ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated");
((MMapInput)forms.get(0).getInputs().get(1)).setValue(new HashMap<String, String>()); // inject new map value
((MStringInput)forms.get(1).getInputs().get(0)).setValue("Updated");
((MMapInput)forms.get(1).getInputs().get(1)).setValue(new HashMap<String, String>()); // inject new map value
job.setName("name"); job.setName("name");
@ -199,10 +208,18 @@ public void testUpdateJob() throws Exception {
assertEquals("name", retrieved.getName()); assertEquals("name", retrieved.getName());
forms = retrieved.getConnectorPart().getForms(); forms = retrieved.getConnectorPart().getForms();
assertEquals("Injected", forms.get(0).getInputs().get(1).getValue()); assertEquals("Updated", forms.get(0).getInputs().get(0).getValue());
assertNull(forms.get(0).getInputs().get(1).getValue());
assertEquals("Updated", forms.get(1).getInputs().get(0).getValue());
assertNull(forms.get(1).getInputs().get(1).getValue());
forms = retrieved.getFrameworkPart().getForms(); forms = retrieved.getFrameworkPart().getForms();
assertEquals("Injected", forms.get(1).getInputs().get(1).getValue()); assertEquals("Updated", forms.get(0).getInputs().get(0).getValue());
assertNotNull(forms.get(0).getInputs().get(1).getValue());
assertEquals(((Map)forms.get(0).getInputs().get(1).getValue()).size(), 0);
assertEquals("Updated", forms.get(1).getInputs().get(0).getValue());
assertNotNull(forms.get(1).getInputs().get(1).getValue());
assertEquals(((Map)forms.get(1).getInputs().get(1).getValue()).size(), 0);
} }
public void testEnableAndDisableJob() throws Exception { public void testEnableAndDisableJob() throws Exception {