sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject git commit: SQOOP-827: Sqoop2: MMapInput is null while retrieving from DB if pass empty map on write
Date Mon, 19 Aug 2013 15:27:39 GMT
Updated Branches:
  refs/heads/sqoop2 d140c5ddd -> 78235e39d


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

(Mengwei Ding via Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/78235e39
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/78235e39
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/78235e39

Branch: refs/heads/sqoop2
Commit: 78235e39dfb5c36324739976fa54ec9cfaaba08a
Parents: d140c5d
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Mon Aug 19 08:26:52 2013 -0700
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Mon Aug 19 08:26:52 2013 -0700

----------------------------------------------------------------------
 .../java/org/apache/sqoop/model/MMapInput.java  | 35 +++++++++++---------
 .../org/apache/sqoop/model/TestMMapInput.java   |  9 ++++-
 .../sqoop/repository/derby/DerbyTestCase.java   |  9 ++---
 .../derby/TestConnectionHandling.java           | 25 +++++++++++---
 .../sqoop/repository/derby/TestJobHandling.java | 25 +++++++++++---
 5 files changed, 74 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/78235e39/common/src/main/java/org/apache/sqoop/model/MMapInput.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MMapInput.java b/common/src/main/java/org/apache/sqoop/model/MMapInput.java
index de17e2d..37dd265 100644
--- a/common/src/main/java/org/apache/sqoop/model/MMapInput.java
+++ b/common/src/main/java/org/apache/sqoop/model/MMapInput.java
@@ -32,8 +32,8 @@ public final class MMapInput extends MInput<Map<String, String>>
{
   @Override
   public String getUrlSafeValueString() {
     Map<String, String> valueMap = getValue();
-    if (valueMap == null || valueMap.size() == 0) {
-      return "";
+    if (valueMap == null) {
+      return null;
     }
     boolean first = true;
     StringBuilder vsb = new StringBuilder();
@@ -51,24 +51,27 @@ public final class MMapInput extends MInput<Map<String, String>>
{
 
   @Override
   public void restoreFromUrlSafeValueString(String valueString) {
-    Map<String, String> valueMap = null;
-    if (valueString != null && valueString.trim().length() > 0) {
-      valueMap = new HashMap<String, String>();
-      String[] valuePairs = valueString.split("&");
-      for (String pair : valuePairs) {
-        String[] nameAndVal = pair.split("=");
-        if (nameAndVal.length > 0) {
-          String name = nameAndVal[0];
-          String value = null;
-          if (nameAndVal.length > 1) {
-            value = nameAndVal[1];
-          }
+    if (valueString == null) {
+      setValue(null);
+    } else {
+      Map<String, String> valueMap = new HashMap<String, String>();
+      if (valueString.trim().length() > 0) {
+        String[] valuePairs = valueString.split("&");
+        for (String pair : valuePairs) {
+          String[] nameAndVal = pair.split("=");
+          if (nameAndVal.length > 0) {
+            String name = nameAndVal[0];
+            String value = null;
+            if (nameAndVal.length > 1) {
+              value = nameAndVal[1];
+            }
 
-          valueMap.put(name, value);
+            valueMap.put(name, value);
+          }
         }
       }
+      setValue(valueMap);
     }
-    setValue(valueMap);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/sqoop/blob/78235e39/common/src/test/java/org/apache/sqoop/model/TestMMapInput.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestMMapInput.java b/common/src/test/java/org/apache/sqoop/model/TestMMapInput.java
index eb877cf..120fb07 100644
--- a/common/src/test/java/org/apache/sqoop/model/TestMMapInput.java
+++ b/common/src/test/java/org/apache/sqoop/model/TestMMapInput.java
@@ -19,6 +19,7 @@ package org.apache.sqoop.model;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
@@ -82,7 +83,13 @@ public class TestMMapInput {
     String tmp = input1.getUrlSafeValueString();
     // Restore to actual value
     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());
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/sqoop/blob/78235e39/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
index 8a5aee8..a2a0bc7 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
@@ -27,6 +27,7 @@ import org.apache.sqoop.model.MFramework;
 import org.apache.sqoop.model.MInput;
 import org.apache.sqoop.model.MJob;
 import org.apache.sqoop.model.MJobForms;
+import org.apache.sqoop.model.MMapInput;
 import org.apache.sqoop.model.MStringInput;
 
 import java.sql.Connection;
@@ -197,7 +198,7 @@ abstract public class DerbyTestCase extends TestCase {
         + " VALUES('I1', " + (x * 6 + i * 2 + 1) + ", 0, 'STRING', false, 30)");
         runQuery("INSERT INTO SQOOP.SQ_INPUT"
         +"(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
         runQuery("INSERT INTO SQOOP.SQ_INPUT"
@@ -205,7 +206,7 @@ abstract public class DerbyTestCase extends TestCase {
         + " VALUES('I3', " + (x * 6 + i * 2 + 2) + ", 0, 'STRING', false, 30)");
         runQuery("INSERT INTO SQOOP.SQ_INPUT"
         +"(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 @@ abstract public class DerbyTestCase extends TestCase {
     inputs = new LinkedList<MInput<?>>();
     input = new MStringInput("I1", false, (short)30);
     inputs.add(input);
-    input = new MStringInput("I2", false, (short)30);
+    input = new MMapInput("I2", false);
     inputs.add(input);
     forms.add(new MForm("F1", inputs));
 
     inputs = new LinkedList<MInput<?>>();
     input = new MStringInput("I3", false, (short)30);
     inputs.add(input);
-    input = new MStringInput("I4", false, (short)30);
+    input = new MMapInput("I4", false);
     inputs.add(input);
     forms.add(new MForm("F2", inputs));
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/78235e39/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectionHandling.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectionHandling.java
b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectionHandling.java
index 6959f2d..f9e9217 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectionHandling.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectionHandling.java
@@ -21,9 +21,12 @@ import org.apache.sqoop.common.SqoopException;
 import org.apache.sqoop.model.MConnection;
 import org.apache.sqoop.model.MForm;
 import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MMapInput;
 import org.apache.sqoop.model.MStringInput;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Test connection methods on Derby repository.
@@ -166,10 +169,16 @@ public class TestConnectionHandling extends DerbyTestCase {
     List<MForm> forms;
 
     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();
-    ((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");
 
@@ -183,10 +192,18 @@ public class TestConnectionHandling extends DerbyTestCase {
     assertEquals("name", connection.getName());
 
     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();
-    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 {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/78235e39/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java
b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java
index a3d804e..4325c5c 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java
@@ -20,9 +20,12 @@ package org.apache.sqoop.repository.derby;
 import org.apache.sqoop.common.SqoopException;
 import org.apache.sqoop.model.MForm;
 import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MMapInput;
 import org.apache.sqoop.model.MStringInput;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Test job methods on Derby repository.
@@ -182,10 +185,16 @@ public class TestJobHandling extends DerbyTestCase {
     List<MForm> forms;
 
     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();
-    ((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");
 
@@ -199,10 +208,18 @@ public class TestJobHandling extends DerbyTestCase {
     assertEquals("name", retrieved.getName());
 
     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();
-    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 {


Mime
View raw message