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

Method testLeftOuterJoin

test/org/apache/pig/test/TestJoinBase.java:159–224  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

157 }
158
159 @Test
160 public void testLeftOuterJoin() throws Exception {
161 String[] input1 = {
162 "hello\t1",
163 "bye\t2",
164 "\t3"
165 };
166 String[] input2 = {
167 "hello\tworld",
168 "good\tmorning",
169 "\tevening"
170
171 };
172
173 String firstInput = createInputFile("a.txt", input1);
174 String secondInput = createInputFile("b.txt", input2);
175 List<Tuple> expectedResults = Util.getTuplesFromConstantTupleStrings(
176 new String[] {
177 "('hello',1,'hello','world')",
178 "('bye',2,null,null)",
179 "(null,3,null,null)"
180 });
181
182 // with and without optional outer
183 for(int i = 0; i < 2; i++) {
184 //with schema
185 String script = "a = load '"+ Util.encodeEscape(firstInput) +"' as (n:chararray, a:int); " +
186 "b = load '"+ Util.encodeEscape(secondInput) +"' as (n:chararray, m:chararray); ";
187 if(i == 0) {
188 script += "c = join a by $0 left outer, b by $0;" ;
189 } else {
190 script += "c = join a by $0 left, b by $0;" ;
191 }
192 script += "d = order c by $1;";
193 // ensure we parse correctly
194 Util.buildLp(pigServer, script);
195
196 // run query and test results only once
197 if(i == 0) {
198 Util.registerMultiLineQuery(pigServer, script);
199 Iterator<Tuple> it = pigServer.openIterator("d");
200 int counter= 0;
201 while(it.hasNext()) {
202 assertEquals(expectedResults.get(counter++), it.next());
203 }
204 assertEquals(expectedResults.size(), counter);
205
206 // without schema
207 script = "a = load '"+ Util.encodeEscape(firstInput) +"'; " +
208 "b = load '"+ Util.encodeEscape(secondInput) +"'; ";
209 if(i == 0) {
210 script += "c = join a by $0 left outer, b by $0;" ;
211 } else {
212 script += "c = join a by $0 left, b by $0;" ;
213 }
214 try {
215 Util.registerMultiLineQuery(pigServer, script);
216 } catch (Exception e) {

Callers

nothing calls this directly

Calls 14

createInputFileMethod · 0.95
encodeEscapeMethod · 0.95
buildLpMethod · 0.95
getPigExceptionMethod · 0.95
getErrorCodeMethod · 0.95
deleteInputFileMethod · 0.95
openIteratorMethod · 0.80
getMethod · 0.65
sizeMethod · 0.65
hasNextMethod · 0.45

Tested by

no test coverage detected