Verify that CASE statement works when expressions contain dereference operators. @throws Exception
()
| 243 | * @throws Exception |
| 244 | */ |
| 245 | @Test |
| 246 | public void testWithDereferenceOperator() throws Exception { |
| 247 | PigServer pigServer = new PigServer(Util.getLocalTestMode()); |
| 248 | Data data = resetData(pigServer); |
| 249 | |
| 250 | data.set("foo", |
| 251 | tuple("a","x",1), |
| 252 | tuple("a","y",1), |
| 253 | tuple("b","x",2), |
| 254 | tuple("b","y",2), |
| 255 | tuple("c","x",3), |
| 256 | tuple("c","y",3) |
| 257 | ); |
| 258 | |
| 259 | pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage() AS (c1:chararray, c2:chararray, i:int);"); |
| 260 | pigServer.registerQuery("B = GROUP A BY (c1, i);"); |
| 261 | pigServer.registerQuery("C = FOREACH B GENERATE group.i, (" + |
| 262 | " CASE group.i % 3" + |
| 263 | " WHEN 0 THEN '3n'" + |
| 264 | " WHEN 1 THEN '3n+1'" + |
| 265 | " ELSE '3n+2'" + |
| 266 | " END" + |
| 267 | "), A.(c1, c2);"); |
| 268 | pigServer.registerQuery("STORE C INTO 'bar' USING mock.Storage();"); |
| 269 | |
| 270 | List<Tuple> out = data.get("bar"); |
| 271 | |
| 272 | String[] expected = new String[] { |
| 273 | "(1,3n+1,{(a,x),(a,y)})", |
| 274 | "(2,3n+2,{(b,x),(b,y)})", |
| 275 | "(3,3n,{(c,x),(c,y)})" |
| 276 | }; |
| 277 | Schema s = pigServer.dumpSchema("C"); |
| 278 | Util.checkQueryOutputs(out.iterator(), expected, org.apache.pig.newplan.logical.Util.translateSchema(s), |
| 279 | Util.isSparkExecType(Util.getLocalTestMode())); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Verify that FrontendException is thrown when case expression is missing, |
nothing calls this directly
no test coverage detected