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

Method testJoinSchema

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

Source from the content-addressed store, hash-verified

100
101
102 @Test
103 public void testJoinSchema() throws Exception {
104 String[] input1 = {
105 "1\t2",
106 "2\t3",
107 "3\t4"
108 };
109 String[] input2 = {
110 "1\thello",
111 "4\tbye",
112 };
113
114 String firstInput = createInputFile("a.txt", input1);
115 String secondInput = createInputFile("b.txt", input2);
116 Tuple expectedResult = (Tuple)Util.getPigConstant("(1,2,1,'hello',1,2,1,'hello')");
117
118 // with schema
119 String script = "a = load '"+ Util.encodeEscape(firstInput) +"' as (i:int, j:int); " +
120 "b = load '"+ Util.encodeEscape(secondInput) +"' as (k:int, l:chararray); " +
121 "c = join a by $0, b by $0;" +
122 "d = foreach c generate i,j,k,l,a::i as ai,a::j as aj,b::k as bk,b::l as bl;";
123 Util.registerMultiLineQuery(pigServer, script);
124 Iterator<Tuple> it = pigServer.openIterator("d");
125 assertTrue(it.hasNext());
126 assertEquals(expectedResult, it.next());
127 assertFalse(it.hasNext());
128
129 // schema with duplicates
130 script = "a = load '"+ Util.encodeEscape(firstInput) +"' as (i:int, j:int); " +
131 "b = load '"+ Util.encodeEscape(secondInput) +"' as (i:int, l:chararray); " +
132 "c = join a by $0, b by $0;" +
133 "d = foreach c generate i,j,l,a::i as ai,a::j as aj,b::i as bi,b::l as bl;";
134 boolean exceptionThrown = false;
135 try{
136 Util.registerMultiLineQuery(pigServer, script);
137 pigServer.openIterator("d");
138 }catch (Exception e) {
139 PigException pe = LogUtils.getPigException(e);
140 assertEquals(1025, pe.getErrorCode());
141 exceptionThrown = true;
142 }
143 assertTrue(exceptionThrown);
144
145 // schema with duplicates with resolution
146 script = "a = load '"+ Util.encodeEscape(firstInput) +"' as (i:int, j:int); " +
147 "b = load '"+ Util.encodeEscape(secondInput) +"' as (i:int, l:chararray); " +
148 "c = join a by $0, b by $0;" +
149 "d = foreach c generate a::i as ai1,j,b::i as bi1,l,a::i as ai2,a::j as aj2,b::i as bi3,b::l as bl3;";
150 Util.registerMultiLineQuery(pigServer, script);
151 it = pigServer.openIterator("d");
152 assertTrue(it.hasNext());
153 assertEquals(expectedResult, it.next());
154 assertFalse(it.hasNext());
155 deleteInputFile(firstInput);
156 deleteInputFile(secondInput);
157 }
158
159 @Test

Callers

nothing calls this directly

Calls 11

createInputFileMethod · 0.95
getPigConstantMethod · 0.95
encodeEscapeMethod · 0.95
getPigExceptionMethod · 0.95
getErrorCodeMethod · 0.95
deleteInputFileMethod · 0.95
openIteratorMethod · 0.80
hasNextMethod · 0.45
assertEqualsMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected