()
| 224 | } |
| 225 | |
| 226 | @Test |
| 227 | public void testRightOuterJoin() throws Exception { |
| 228 | String[] input1 = { |
| 229 | "hello\t1", |
| 230 | "bye\t2", |
| 231 | "\t3" |
| 232 | }; |
| 233 | String[] input2 = { |
| 234 | "hello\tworld", |
| 235 | "good\tmorning", |
| 236 | "\tevening" |
| 237 | |
| 238 | }; |
| 239 | |
| 240 | String firstInput = createInputFile("a.txt", input1); |
| 241 | String secondInput = createInputFile("b.txt", input2); |
| 242 | List<Tuple> expectedResults = Util.getTuplesFromConstantTupleStrings( |
| 243 | new String[] { |
| 244 | "(null,null,null,'evening')", |
| 245 | "(null,null,'good','morning')", |
| 246 | "('hello',1,'hello','world')" |
| 247 | }); |
| 248 | // with and without optional outer |
| 249 | for(int i = 0; i < 2; i++) { |
| 250 | // with schema |
| 251 | String script = "a = load '"+ Util.encodeEscape(firstInput) +"' as (n:chararray, a:int); " + |
| 252 | "b = load '"+ Util.encodeEscape(secondInput) +"' as (n:chararray, m:chararray); "; |
| 253 | if(i == 0) { |
| 254 | script += "c = join a by $0 right outer, b by $0;" ; |
| 255 | } else { |
| 256 | script += "c = join a by $0 right, b by $0;" ; |
| 257 | } |
| 258 | script += "d = order c by $3;"; |
| 259 | // ensure we parse correctly |
| 260 | Util.buildLp(pigServer, script); |
| 261 | |
| 262 | // run query and test results only once |
| 263 | if(i == 0) { |
| 264 | Util.registerMultiLineQuery(pigServer, script); |
| 265 | Iterator<Tuple> it = pigServer.openIterator("d"); |
| 266 | int counter= 0; |
| 267 | while(it.hasNext()) { |
| 268 | assertEquals(expectedResults.get(counter++), it.next()); |
| 269 | } |
| 270 | assertEquals(expectedResults.size(), counter); |
| 271 | |
| 272 | // without schema |
| 273 | script = "a = load '"+ Util.encodeEscape(firstInput) +"'; " + |
| 274 | "b = load '"+ Util.encodeEscape(secondInput) +"'; " ; |
| 275 | if(i == 0) { |
| 276 | script += "c = join a by $0 right outer, b by $0;" ; |
| 277 | } else { |
| 278 | script += "c = join a by $0 right, b by $0;" ; |
| 279 | } |
| 280 | try { |
| 281 | Util.registerMultiLineQuery(pigServer, script); |
| 282 | } catch (Exception e) { |
| 283 | PigException pe = LogUtils.getPigException(e); |
nothing calls this directly
no test coverage detected