()
| 65 | } |
| 66 | |
| 67 | @Test |
| 68 | public void testJoinSchema2() throws Exception { |
| 69 | // test join where one load does not have schema |
| 70 | String[] input1 = { |
| 71 | "1\t2", |
| 72 | "2\t3", |
| 73 | "3\t4" |
| 74 | }; |
| 75 | String[] input2 = { |
| 76 | "1\thello", |
| 77 | "4\tbye", |
| 78 | }; |
| 79 | |
| 80 | String firstInput = createInputFile("a.txt", input1); |
| 81 | String secondInput = createInputFile("b.txt", input2); |
| 82 | Tuple expectedResultCharArray = |
| 83 | (Tuple)Util.getPigConstant("('1','2','1','hello','1','2','1','hello')"); |
| 84 | |
| 85 | Tuple expectedResult = TupleFactory.getInstance().newTuple(); |
| 86 | for(Object field : expectedResultCharArray.getAll()){ |
| 87 | expectedResult.append(new DataByteArray(field.toString())); |
| 88 | } |
| 89 | |
| 90 | // with schema |
| 91 | String script = "a = load '"+ Util.encodeEscape(firstInput) +"' ; " + |
| 92 | //re-using alias a for new operator below, doing this intentionally |
| 93 | // because such use case has been seen |
| 94 | "a = foreach a generate $0 as i, $1 as j ;" + |
| 95 | "b = load '"+ Util.encodeEscape(secondInput) +"' as (k, l); " + |
| 96 | "c = join a by $0, b by $0;" + |
| 97 | "d = foreach c generate i,j,k,l,a::i as ai,a::j as aj,b::k as bk,b::l as bl;"; |
| 98 | Util.registerMultiLineQuery(pigServer, script); |
| 99 | Iterator<Tuple> it = pigServer.openIterator("d"); |
| 100 | assertTrue(it.hasNext()); |
| 101 | Tuple res = it.next(); |
| 102 | assertEquals(expectedResult, res); |
| 103 | assertFalse(it.hasNext()); |
| 104 | deleteInputFile(firstInput); |
| 105 | deleteInputFile(secondInput); |
| 106 | |
| 107 | } |
| 108 | |
| 109 | @Test |
| 110 | public void testMultiOuterJoinFailure() throws Exception { |
nothing calls this directly
no test coverage detected