Author: xuefu
Date: Fri Jun 12 02:48:37 2015
New Revision: 1685018
URL: http://svn.apache.org/r1685018
Log:
PIG-4597: Enable TestNullConstant unit test in spark mode(Xianda via Xuefu)
Modified:
pig/branches/spark/test/org/apache/pig/test/TestNullConstant.java
pig/branches/spark/test/org/apache/pig/test/Util.java
Modified: pig/branches/spark/test/org/apache/pig/test/TestNullConstant.java
URL:
http://svn.apache.org/viewvc/pig/branches/spark/test/org/apache/pig/test/TestNullConstant.java?rev=1685018&r1=1685017&r2=1685018&view=diff
==============================================================================
--- pig/branches/spark/test/org/apache/pig/test/TestNullConstant.java (original)
+++ pig/branches/spark/test/org/apache/pig/test/TestNullConstant.java Fri Jun
12 02:48:37 2015
@@ -109,16 +109,7 @@ public class TestNullConstant {
pigServer.registerQuery("d = foreach c generate flatten((SIZE(a) == 0
? null: a)), flatten((SIZE(b) == 0 ? null : b));");
Iterator<Tuple> it = pigServer.openIterator("d");
Object[][] results = new Object[][]{{10, "will_join", 10,
"will_join"}, {11, "will_not_join", null}, {null, 12, "will_not_join"}};
- int i = 0;
- while(it.hasNext()) {
-
- Tuple t = it.next();
- Object[] result = results[i++];
- assertEquals(result.length, t.size());
- for (int j = 0; j < result.length; j++) {
- assertEquals(result[j], t.get(j));
- }
- }
+ Util.checkQueryOutputsAfterSort(it,results);
}
@Test
Modified: pig/branches/spark/test/org/apache/pig/test/Util.java
URL:
http://svn.apache.org/viewvc/pig/branches/spark/test/org/apache/pig/test/Util.java?rev=1685018&r1=1685017&r2=1685018&view=diff
==============================================================================
--- pig/branches/spark/test/org/apache/pig/test/Util.java (original)
+++ pig/branches/spark/test/org/apache/pig/test/Util.java Fri Jun 12 02:48:37
2015
@@ -547,6 +547,29 @@ public class Util {
checkQueryOutputsAfterSort(actualResList, expectedResList);
}
+ /**
+ * Helper function to check if the result of Pig Query is in line with
expected results.
+ * It sorts actual and expected results before comparison.
+ * The tuple size in the tuple list can vary. Pass by a two-dimension
array, it will be converted to be a tuple list.
+ * e.g. expectedTwoDimensionObjects is [{{10, "will_join", 10,
"will_join"}, {11, "will_not_join", null}, {null, 12, "will_not_join"}}],
+ * the field size of these 3 tuples are [4,3,3]
+ *
+ * @param actualResultsIt
+ * @param expectedTwoDimensionObjects represents a tuple list, in which
the tuple can have variable size.
+ */
+ static public void checkQueryOutputsAfterSort(Iterator<Tuple>
actualResultsIt,
+ Object[][]
expectedTwoDimensionObjects) {
+ List<Tuple> expectedResTupleList = new ArrayList<Tuple>();
+ for (int i = 0; i < expectedTwoDimensionObjects.length; ++i) {
+ Tuple t = TupleFactory.getInstance().newTuple();
+ for (int j = 0; j < expectedTwoDimensionObjects[i].length; ++j) {
+ t.append(expectedTwoDimensionObjects[i][j]);
+ }
+ expectedResTupleList.add(t);
+ }
+ checkQueryOutputsAfterSort(actualResultsIt, expectedResTupleList);
+ }
+
static public void checkQueryOutputsAfterSort(
List<Tuple> actualResList, List<Tuple> expectedResList) {
Collections.sort(actualResList);