MCPcopy Create free account
hub / github.com/apache/pig / testPi

Method testPi

test/org/apache/pig/test/TestPi.java:91–125  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

89 }
90
91 @Test
92 public void testPi() throws Exception {
93
94 pig.registerQuery("A = load 'foo' using mock.Storage() as (x:double, y:double);");
95 pig.registerQuery("B = foreach A generate $0 - 0.5 as d1, $1 - 0.5 as d2;");
96 pig.registerQuery("C = foreach B generate $0 * $0 as m1, $1 * $1 as m2;");
97 pig.registerQuery("D = foreach C generate $0 + $1 as s1;");
98 pig.registerQuery("D = foreach D generate $0, ARITY($0);");
99
100 pig.registerQuery("E = filter D by $0 <= 0.25;");
101
102 pig.registerQuery("F = cogroup D by $1, E by $1;");
103 pig.registerQuery("G = foreach F generate COUNT($1) as total, COUNT($2) as in_circle;");
104
105 Iterator<Tuple> values = pig.openIterator("G");
106 assertTrue(values.hasNext());
107 Tuple finalValues = values.next();
108 int totalPoints = DataType.toInteger(finalValues.get(0));
109 int inCirclePoints = DataType.toInteger(finalValues.get(1));
110
111 log.info("Value of PI = " + 4 * (double)inCircle / (double)total);
112 log.info("Value of PI (From Test data) = " + 4 * (double)inCirclePoints / (double)totalPoints);
113
114
115 Iterator<Tuple> lengthTest = pig.openIterator("D");
116
117 while(lengthTest.hasNext()) {
118 Tuple temp = lengthTest.next();
119 totalLengthTest += temp.get(0).toString().length();
120 }
121
122 assertEquals(totalPoints, total);
123 assertEquals(inCirclePoints, inCircle);
124 assertEquals(totalLengthTest, totalLength);
125 }
126}

Callers

nothing calls this directly

Calls 10

toIntegerMethod · 0.95
getMethod · 0.95
openIteratorMethod · 0.80
infoMethod · 0.80
lengthMethod · 0.80
registerQueryMethod · 0.45
hasNextMethod · 0.45
nextMethod · 0.45
toStringMethod · 0.45
assertEqualsMethod · 0.45

Tested by

no test coverage detected