| 30 | import org.junit.Test; |
| 31 | |
| 32 | public class TestSchemaAliasVisitor { |
| 33 | |
| 34 | @Test |
| 35 | public void test() throws RecognitionException, ParsingFailureException, IOException { |
| 36 | String query = "A = load 'x' as ( u:int, v:long, w:bytearray); " + |
| 37 | "B = foreach A generate u, v, $0 as x, u as z; " + |
| 38 | "C = store B into 'output';"; |
| 39 | validate( query ); |
| 40 | } |
| 41 | |
| 42 | @Test |
| 43 | public void testNegative1() throws RecognitionException, ParsingFailureException, IOException { |
| 44 | String query = "A = load 'x' as ( u:int, v:long, w:bytearray); " + |
| 45 | "B = foreach A generate $0, v, $0; " + |
| 46 | "C = store B into 'output';"; |
| 47 | try { |
| 48 | validate( query ); |
| 49 | } catch(PlanValidationException ex) { |
| 50 | Assert.assertTrue( ex.getMessage().contains( "Duplicate schema alias" ) ); |
| 51 | return; |
| 52 | } |
| 53 | Assert.fail( "Query should fail to validate." ); |
| 54 | } |
| 55 | |
| 56 | @Test |
| 57 | // See PIG-644 |
| 58 | public void testNegative2() throws RecognitionException, ParsingFailureException, IOException { |
| 59 | String query = "a = load '1.txt' as (a0:int, a1:int);" + |
| 60 | "b = foreach a generate a0, a1 as a0;" + |
| 61 | "c = store b into 'output';"; |
| 62 | try { |
| 63 | validate( query ); |
| 64 | } catch(PlanValidationException ex) { |
| 65 | Assert.assertTrue( ex.getMessage().contains( "Duplicate schema alias" ) ); |
| 66 | return; |
| 67 | } |
| 68 | Assert.fail( "Query should fail to validate." ); |
| 69 | } |
| 70 | |
| 71 | @Test |
| 72 | // See PIG-644 |
| 73 | public void testNegative3() throws RecognitionException, ParsingFailureException, IOException { |
| 74 | String query = "a = load '1.txt' as (a0:int, a0:int);" + |
| 75 | "store a into 'output';"; |
| 76 | try { |
| 77 | validate( query ); |
| 78 | } catch(RecognitionException ex) { |
| 79 | Assert.assertTrue( ex.toString().contains( "Duplicated alias in schema" ) ); |
| 80 | return; |
| 81 | } |
| 82 | Assert.fail( "Query should fail to validate." ); |
| 83 | } |
| 84 | |
| 85 | private LogicalPlan validate(String query) throws RecognitionException, ParsingFailureException, IOException { |
| 86 | LogicalPlan plan = ParserTestingUtils.generateLogicalPlan( query ); |
| 87 | SchemaAliasVisitor visitor = new SchemaAliasVisitor( plan ); |
| 88 | visitor.visit(); |
| 89 | return plan; |
nothing calls this directly
no outgoing calls
no test coverage detected