diff options
author | Jason Altekruse <altekrusejason@gmail.com> | 2014-12-18 17:40:12 -0800 |
---|---|---|
committer | Jason Altekruse <altekrusejason@gmail.com> | 2014-12-19 10:32:19 -0800 |
commit | df56954771950cd850ecae10404007d11d9241cb (patch) | |
tree | 9eef0e68cb27b219315db47ffbb41811d606fc71 | |
parent | e715a2ce40d4908b82f9518615d9f8f3a994cca2 (diff) |
DRILL-1824: Fix equality between maps and lists for test framework.
Fix failing test due to not creating hadoop's Text object, as well as lack of equality between these Text objects and a string containing the same text.
-rw-r--r-- | exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java | 17 | ||||
-rw-r--r-- | exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java | 32 | ||||
-rw-r--r-- | exec/java-exec/src/test/java/org/apache/drill/TestFrameworkTest.java (renamed from exec/java-exec/src/test/java/org/apache/drill/TestTestFramework.java) | 22 | ||||
-rw-r--r-- | exec/java-exec/src/test/resources/testframework/map_reordering.json | 7 | ||||
-rw-r--r-- | exec/java-exec/src/test/resources/testframework/map_reordering2.json | 7 |
5 files changed, 67 insertions, 18 deletions
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java index cea5676c5..dd5145d9d 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringArrayList.java @@ -18,6 +18,7 @@ package org.apache.drill.exec.util; import java.util.ArrayList; +import java.util.List; import org.apache.hadoop.io.Text; @@ -37,14 +38,18 @@ public class JsonStringArrayList<E> extends ArrayList<E> { } @Override - public boolean equals(Object other) { - if (other instanceof JsonStringArrayList) { - return toString().equals(other.toString()); + public boolean equals(Object obj) { + if (this == obj) { + return true; } - if (other instanceof String) { - return toString().equals(other); + if (obj == null) { + return false; } - return false; + if (!(obj instanceof List)) { + return false; + } + List other = (List) obj; + return this.size() == other.size() && this.containsAll(other); } @Override diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java index 6e83494f6..ac980eb74 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/JsonStringHashMap.java @@ -18,6 +18,7 @@ package org.apache.drill.exec.util; import java.util.LinkedHashMap; +import java.util.Map; import org.apache.hadoop.io.Text; @@ -41,14 +42,33 @@ public class JsonStringHashMap<K, V> extends LinkedHashMap<K, V> { } @Override - public boolean equals(Object other) { - if (other instanceof JsonStringHashMap) { - return toString().equals(other.toString()); + public boolean equals(Object obj) { + if (this == obj) { + return true; } - if (other instanceof String) { - return toString().equals(other); + if (obj == null) { + return false; } - return false; + if (!(obj instanceof Map)) { + return false; + } + Map other = (Map) obj; + if (this.size() != other.size()) { + return false; + } + for (K key : this.keySet()) { + if (this.get(key) == null ) { + if (other.get(key) == null) { + continue; + } else { + return false; + } + } + if ( ! this.get(key).equals(other.get(key))) { + return false; + } + } + return true; } @Override diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestTestFramework.java b/exec/java-exec/src/test/java/org/apache/drill/TestFrameworkTest.java index f75e686c7..f8db5337c 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/TestTestFramework.java +++ b/exec/java-exec/src/test/java/org/apache/drill/TestFrameworkTest.java @@ -23,6 +23,7 @@ import org.apache.drill.common.types.TypeProtos; import org.apache.drill.common.types.Types; import org.apache.drill.exec.util.JsonStringArrayList; import org.apache.drill.exec.util.JsonStringHashMap; +import org.apache.hadoop.io.Text; import org.junit.Ignore; import org.junit.Test; @@ -36,7 +37,7 @@ import static org.junit.Assert.assertEquals; // currently using it with the assumption that the csv and json readers are well tested, and handling diverse // types in the test framework would require doing some redundant work to enable casting outside of Drill or // some better tooling to generate parquet files that have all of the parquet types -public class TestTestFramework extends BaseTestQuery{ +public class TestFrameworkTest extends BaseTestQuery{ private static String CSV_COLS = " cast(columns[0] as bigint) employee_id, columns[1] as first_name, columns[2] as last_name "; @@ -100,6 +101,15 @@ public class TestTestFramework extends BaseTestQuery{ } @Test + public void testMapOrdering() throws Exception { + testBuilder() + .sqlQuery("select * from cp.`/testframework/map_reordering.json`") + .unOrdered() + .jsonBaselineFile("testframework/map_reordering2.json") + .build().run(); + } + + @Test public void testBaselineValsVerificationWithNulls() throws Exception { testBuilder() .sqlQuery("select * from cp.`store/json/json_simple_with_null.json`") @@ -139,17 +149,17 @@ public class TestTestFramework extends BaseTestQuery{ l_list.add(2l); JsonStringHashMap x = new JsonStringHashMap(); - x.put("y", "kevin"); - x.put("z", "paul"); + x.put("y", new Text("kevin")); + x.put("z", new Text("paul")); // [{"orange":"yellow","pink":"red"},{"pink":"purple"}] JsonStringArrayList z = new JsonStringArrayList(); JsonStringHashMap z_1 = new JsonStringHashMap(); - z_1.put("orange", "yellow"); - z_1.put("pink", "red"); + z_1.put("orange", new Text("yellow")); + z_1.put("pink", new Text("red")); JsonStringHashMap z_2 = new JsonStringHashMap(); - z_2.put("pink", "purple"); + z_2.put("pink", new Text("purple")); z.add(z_1); z.add(z_2); diff --git a/exec/java-exec/src/test/resources/testframework/map_reordering.json b/exec/java-exec/src/test/resources/testframework/map_reordering.json new file mode 100644 index 000000000..e8e467fe8 --- /dev/null +++ b/exec/java-exec/src/test/resources/testframework/map_reordering.json @@ -0,0 +1,7 @@ +{ + "a_map" : { + "a" : 1, + "b" : 2, + "c" : 3 + } +}
\ No newline at end of file diff --git a/exec/java-exec/src/test/resources/testframework/map_reordering2.json b/exec/java-exec/src/test/resources/testframework/map_reordering2.json new file mode 100644 index 000000000..606e7aead --- /dev/null +++ b/exec/java-exec/src/test/resources/testframework/map_reordering2.json @@ -0,0 +1,7 @@ +{ + "a_map" : { + "c" : 3, + "b" : 2, + "a" : 1 + } +} |