public void testPlanWithCast() throws Exception {
    LogicalPlanTester lpt = new LogicalPlanTester();
    lpt.buildPlan("a = load 'd.txt' as (id, c);");
    lpt.buildPlan("b = filter a by (int)id==10;");
    LogicalPlan plan = lpt.buildPlan("store b into 'empty';");

    // check basics
    org.apache.pig.experimental.logical.relational.LogicalPlan newPlan = migratePlan(plan);
    assertEquals(3, newPlan.size());
    assertEquals(newPlan.getSources().size(), 1);

    // check load
    LogicalRelationalOperator op = (LogicalRelationalOperator) newPlan.getSources().get(0);
    assertEquals(op.getClass(), org.apache.pig.experimental.logical.relational.LOLoad.class);

    // check filter
    op = (LogicalRelationalOperator) newPlan.getSuccessors(op).get(0);
    assertEquals(op.getClass(), org.apache.pig.experimental.logical.relational.LOFilter.class);

    LogicalExpressionPlan exp =
        ((org.apache.pig.experimental.logical.relational.LOFilter) op).getFilterPlan();

    EqualExpression eq = (EqualExpression) exp.getSources().get(0);
    assertEquals(eq.getLhs().getClass(), CastExpression.class);

    assertEquals(eq.getLhs().getClass(), CastExpression.class);
    LogicalExpression ep = (LogicalExpression) exp.getSuccessors(eq.getLhs()).get(0);
    assertEquals(ep.getClass(), ProjectExpression.class);
    assertEquals(((ProjectExpression) ep).getColNum(), 0);
    assertEquals(((ProjectExpression) ep).getInputNum(), 0);

    assertEquals(eq.getRhs().getClass(), ConstantExpression.class);

    // check store
    op = (LogicalRelationalOperator) newPlan.getSuccessors(op).get(0);
    assertEquals(op.getClass(), org.apache.pig.experimental.logical.relational.LOStore.class);
  }
  public void testJoinPlan() throws Exception {
    LogicalPlanTester lpt = new LogicalPlanTester();
    lpt.buildPlan("a = load 'd1.txt' as (id, c);");
    lpt.buildPlan("b = load 'd2.txt'as (id, c);");
    lpt.buildPlan("c = join a by id, b by c;");
    lpt.buildPlan("d = filter c by a::id==NULL AND b::c==NULL;");
    LogicalPlan plan = lpt.buildPlan("store d into 'empty';");

    // check basics
    org.apache.pig.experimental.logical.relational.LogicalPlan newPlan = migratePlan(plan);
    assertEquals(5, newPlan.size());
    assertEquals(newPlan.getSources().size(), 2);

    // check load and join
    LogicalRelationalOperator op =
        (LogicalRelationalOperator) newPlan.getSuccessors(newPlan.getSources().get(0)).get(0);
    assertEquals(op.getClass(), org.apache.pig.experimental.logical.relational.LOJoin.class);
    assertEquals(((LOJoin) op).getJoinType(), LOJoin.JOINTYPE.HASH);

    LogicalRelationalOperator l1 = (LogicalRelationalOperator) newPlan.getPredecessors(op).get(0);
    assertEquals(l1.getClass(), org.apache.pig.experimental.logical.relational.LOLoad.class);
    assertEquals(l1.getAlias(), "a");

    LogicalRelationalOperator l2 = (LogicalRelationalOperator) newPlan.getPredecessors(op).get(1);
    assertEquals(l2.getClass(), org.apache.pig.experimental.logical.relational.LOLoad.class);
    assertEquals(l2.getAlias(), "b");

    // check join input plans
    LogicalExpressionPlan p1 = ((LOJoin) op).getJoinPlan(0).iterator().next();
    assertEquals(p1.size(), 1);

    ProjectExpression prj = (ProjectExpression) p1.getSources().get(0);

    assertEquals(prj.getInputNum(), 0);
    assertEquals(prj.getColNum(), 0);

    LogicalExpressionPlan p2 = ((LOJoin) op).getJoinPlan(1).iterator().next();
    assertEquals(p2.size(), 1);

    prj = (ProjectExpression) p2.getSources().get(0);

    assertEquals(prj.getInputNum(), 1);
    assertEquals(prj.getColNum(), 1);

    // check filter
    op = (LogicalRelationalOperator) newPlan.getSuccessors(op).get(0);
    assertEquals(op.getClass(), org.apache.pig.experimental.logical.relational.LOFilter.class);
    LogicalExpressionPlan exp =
        ((org.apache.pig.experimental.logical.relational.LOFilter) op).getFilterPlan();

    AndExpression ae = (AndExpression) exp.getSources().get(0);

    EqualExpression eq = (EqualExpression) exp.getSuccessors(ae).get(0);
    assertEquals(eq.getLhs().getClass(), ProjectExpression.class);
    assertEquals(((ProjectExpression) eq.getLhs()).getColNum(), 0);
    assertEquals(((ProjectExpression) eq.getLhs()).getInputNum(), 0);

    assertEquals(eq.getRhs().getClass(), ConstantExpression.class);

    eq = (EqualExpression) exp.getSuccessors(ae).get(1);
    assertEquals(eq.getLhs().getClass(), ProjectExpression.class);
    assertEquals(((ProjectExpression) eq.getLhs()).getColNum(), 3);
    assertEquals(((ProjectExpression) eq.getLhs()).getInputNum(), 0);

    assertEquals(eq.getRhs().getClass(), ConstantExpression.class);

    // check store
    op = (LogicalRelationalOperator) newPlan.getSuccessors(op).get(0);
    assertEquals(op.getClass(), org.apache.pig.experimental.logical.relational.LOStore.class);
  }