Package org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators

Examples of org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POCast


        bag.add(t);
      }

    }

    POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
    POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
    PhysicalPlan plan = new PhysicalPlan();
    plan.add(prj);
    plan.add(op);
    plan.connect(prj, op);

        prj.setResultType(DataType.BOOLEAN);

        for (Iterator<Tuple> it = bag.iterator(); it.hasNext();) {
            Tuple t = it.next();
            plan.attachInput(t);
            if (t.get(0) == null) {

                Boolean result = (Boolean) op.getNextBoolean().result;
                assertEquals(null, result);

            }

        }

        prj.setResultType(DataType.INTEGER);

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      if(t.get(0) == null) {

        Integer result  = (Integer)op.getNextInteger().result;
        assertEquals( null, result);

      }

    }

    prj.setResultType(DataType.FLOAT);

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      if(t.get(0) == null) {

        Integer result  = (Integer)op.getNextInteger().result;
        assertEquals( null, result);

      }

    }

    prj.setResultType(DataType.DOUBLE);

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      if(t.get(0) == null) {

        Double result = (Double) op.getNextDouble().result;
      assertEquals(null, result);

      }
    }

        prj.setResultType(DataType.DATETIME);

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            if(t.get(0) == null) {

                DateTime result  = (DateTime)op.getNextDateTime().result;
                assertEquals( null, result);

            }

        }

    prj.setResultType(DataType.CHARARRAY);

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      if(t.get(0) == null) {

        String result  = (String)op.getNextString().result;
        assertEquals( null, result);

      }

    }

    prj.setResultType(DataType.BYTEARRAY);

    TupleFactory tf = TupleFactory.getInstance();

    {
      Tuple t = tf.newTuple();
      t.append(new DataByteArray((new Integer(r.nextInt())).toString().getBytes()));
      plan.attachInput(t);
      if(t.get(0) == null) {

        DataByteArray result = (DataByteArray) op.getNextString().result;
        assertEquals(null, result);

      }

    }
View Full Code Here


  @Test
  public void testValueTypesChanged() throws IOException {

    // Plan to test when result type is ByteArray and casting is requested
    // for example casting of values coming out of map lookup.
    POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
    PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);
    DataBag bag = BagFactory.getInstance().newDefaultBag();

    // Create a bag having tuples having values of different types.
    for(int i = 0; i < MAX; i++) {
      Tuple t = TupleFactory.getInstance().newTuple();
      if (i % 6 == 0)
          t.append(r.nextBoolean());
      if(i % 6 == 1)
        t.append(r.nextInt());
      if(i % 6 == 2)
        t.append(r.nextLong());
      if(i % 6 == 3)
        t.append(r.nextDouble());
      if(i % 6 == 4)
        t.append(r.nextFloat());
      if(i % 6 == 5)
          t.append(r.nextLong());
      bag.add(t);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      planToTestBACasts.attachInput(t);
      Object toCast = t.get(0);
            Boolean b = DataType.toBoolean(toCast);
            Result res = opWithInputTypeAsBA.getNextBoolean();
            if (res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(b, res.result);
            }
      Integer i = DataType.toInteger(toCast);
      res = opWithInputTypeAsBA.getNextInteger();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(i, res.result);
      }
      Long l = DataType.toLong(toCast);
      res = opWithInputTypeAsBA.getNextLong();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(l, res.result);
      }

      Float f = DataType.toFloat(toCast);
      res = opWithInputTypeAsBA.getNextFloat();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(f, res.result);
      }

      Double d = DataType.toDouble(toCast);
      res = opWithInputTypeAsBA.getNextDouble();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(d, res.result);
      }

      if (!(toCast instanceof Boolean)) {
                DateTime dt = DataType.toDateTime(toCast);
                res = opWithInputTypeAsBA.getNextDateTime();
                if(res.returnStatus == POStatus.STATUS_OK) {
                    assertEquals(dt, res.result);
                }
      }

      String s = DataType.toString(toCast);
      res = opWithInputTypeAsBA.getNextString();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(s, res.result);
      }
    }
  }
View Full Code Here

            Tuple t = TupleFactory.getInstance().newTuple();
            t.append(r.nextBoolean());
            bag.add(t);
        }

        POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
        LoadFunc load = new TestLoader();
        op.setFuncSpec(new FuncSpec(load.getClass().getName()));
        POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
        PhysicalPlan plan = new PhysicalPlan();
        plan.add(prj);
        plan.add(op);
        plan.connect(prj, op);

        prj.setResultType(DataType.BOOLEAN);

        // Plan to test when result type is ByteArray and casting is requested
        // for example casting of values coming out of map lookup.
        POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
        PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Boolean b = (Boolean) t.get(0);
            Result res = op.getNextBoolean();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(b, res.result);
            }
            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextBoolean();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(b, res.result);
            }
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Integer i = ((Boolean) t.get(0)) ? Integer.valueOf(1) : Integer.valueOf(0);
            Result res = op.getNextInteger();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(i, res.result);
            }
            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextInteger();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(i, res.result);
            }
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Long l = ((Boolean) t.get(0)) ? Long.valueOf(1L) : Long.valueOf(0L);
            Result res = op.getNextLong();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(l, res.result);
            }
            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextLong();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(l, res.result);
            }
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Float f = ((Boolean) t.get(0)) ? Float.valueOf(1.0F) : Float.valueOf(0.0F);
            Result res = op.getNextFloat();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(f, res.result);
            }
            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextFloat();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(f, res.result);
            }
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Double d = ((Boolean) t.get(0)) ? Double.valueOf(1.0D) : Double.valueOf(0.0D);
            Result res = op.getNextDouble();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(d, res.result);
            }
            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextDouble();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(d, res.result);
            }
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            DateTime dt = null;
            Result res = op.getNextDateTime();
            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            String str = ((Boolean)t.get(0)).toString();
            Result res = op.getNextString();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(str, res.result);
            }
            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextString();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(str, res.result);
            }
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            DataByteArray dba = new DataByteArray(((Boolean)t.get(0)).toString().getBytes());
            Result res = op.getNextDataByteArray();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(dba, res.result);
            }
            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextDataByteArray();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(dba, res.result);
            }
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Map map = null;
            Result res = op.getNextMap();
            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Result res = op.getNextTuple();
            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            DataBag b = null;
            Result res = op.getNextDataBag();
            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextMap();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextTuple();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextDataBag();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
  }
View Full Code Here

      Tuple t = TupleFactory.getInstance().newTuple();
      t.append(i == 0 ? 0 : r.nextInt());
      bag.add(t);
    }

    POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
    LoadFunc load = new TestLoader();
    op.setFuncSpec(new FuncSpec(load.getClass().getName()));
    POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
    PhysicalPlan plan = new PhysicalPlan();
    plan.add(prj);
    plan.add(op);
    plan.connect(prj, op);

    prj.setResultType(DataType.INTEGER);
    // Plan to test when result type is ByteArray and casting is requested
    // for example casting of values coming out of map lookup.
    POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
    PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);

        for (Iterator<Tuple> it = bag.iterator(); it.hasNext();) {
            Tuple t = it.next();
            plan.attachInput(t);
            Boolean b = Boolean.valueOf((Integer) t.get(0) != 0);
            Result res = op.getNextBoolean();
            if (res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(b, res.result);
            }
            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextBoolean();
            if (res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(b, res.result);
            }
        }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Integer i = (Integer) t.get(0);
      Result res = op.getNextInteger();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(i, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextInteger();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(i, res.result);
      }
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Float f = ((Integer)t.get(0)).floatValue();
      Result res = op.getNextFloat();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(f, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextFloat();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(f, res.result);
      }
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Long l = ((Integer)t.get(0)).longValue();
      Result res = op.getNextLong();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(l, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextLong();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(l, res.result);
      }
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Double d = ((Integer)t.get(0)).doubleValue();
      Result res = op.getNextDouble();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(d, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextDouble();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(d, res.result);
      }
    }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            DateTime dt = new DateTime(((Integer)t.get(0)).longValue());
            Result res = op.getNextDateTime();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(dt, res.result);
            }
            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextDateTime();
            if(res.returnStatus == POStatus.STATUS_OK) {
                assertEquals(dt, res.result);
            }
        }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      String str = ((Integer)t.get(0)).toString();
      Result res = op.getNextString();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(str, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextString();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(str, res.result);
      }
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      DataByteArray dba = new DataByteArray(((Integer)t.get(0)).toString().getBytes());
      Result res = op.getNextDataByteArray();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(dba, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextDataByteArray();
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(dba, res.result);
      }
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Map map = null;
      Result res = op.getNextMap();
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Result res = op.getNextTuple();
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      DataBag b = null;
      Result res = op.getNextDataBag();
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextMap();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextTuple();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextDataBag();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
  }
View Full Code Here

      Tuple t = TupleFactory.getInstance().newTuple();
      t.append(i == 0 ? 0L : r.nextLong());
      bag.add(t);
    }

    POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
    LoadFunc load = new TestLoader();
    op.setFuncSpec(new FuncSpec(load.getClass().getName()));
    POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
    PhysicalPlan plan = new PhysicalPlan();
    plan.add(prj);
    plan.add(op);
    plan.connect(prj, op);

    prj.setResultType(DataType.LONG);

    // Plan to test when result type is ByteArray and casting is requested
    // for example casting of values coming out of map lookup.
    POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
    PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);

        for (Iterator<Tuple> it = bag.iterator(); it.hasNext();) {
            Tuple t = it.next();
            plan.attachInput(t);
            Boolean b = Boolean.valueOf(((Long) t.get(0)) != 0L);
            Result res = op.getNextBoolean();
            if (res.returnStatus == POStatus.STATUS_OK) {
                // System.out.println(res.result + " : " + i);
                assertEquals(b, res.result);
            }

            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextBoolean();
            if (res.returnStatus == POStatus.STATUS_OK)
                assertEquals(b, res.result);

        }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Integer i = ((Long) t.get(0)).intValue();
      Result res = op.getNextInteger();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + i);
        assertEquals(i, res.result);
      }

      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextInteger();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(i, res.result);

    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Float f = ((Long)t.get(0)).floatValue();
      Result res = op.getNextFloat();
      if(res.returnStatus == POStatus.STATUS_OK) {
//         System.out.println(res.result + " : " + f);
        assertEquals(f, res.result);
      }

      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextFloat();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(f, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Long l = ((Long)t.get(0)).longValue();
      Result res = op.getNextLong();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + l);
        assertEquals(l, res.result);
      }

      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextLong();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(l, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Double d = ((Long)t.get(0)).doubleValue();
      Result res = op.getNextDouble();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + d);
        assertEquals(d, res.result);
      }

      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextDouble();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(d, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            DateTime dt = new DateTime(t.get(0));
            Result res = op.getNextDateTime();
            if(res.returnStatus == POStatus.STATUS_OK) {
                //System.out.println(res.result + " : " + l);
                assertEquals(dt, res.result);
            }

            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextDateTime();
            if(res.returnStatus == POStatus.STATUS_OK)
                assertEquals(dt, res.result);
        }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      String str = ((Long)t.get(0)).toString();
      Result res = op.getNextString();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + str);
        assertEquals(str, res.result);
      }

      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextString();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(str, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      DataByteArray dba = new DataByteArray(((Long)t.get(0)).toString().getBytes());
      Result res = op.getNextDataByteArray();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + dba);
        assertEquals(dba, res.result);
      }

      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextDataByteArray();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(dba, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Map map = null;
      Result res = op.getNextMap();
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Result res = op.getNextTuple();
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      DataBag b = null;
      Result res = op.getNextDataBag();
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextMap();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextTuple();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextDataBag();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
  }
View Full Code Here

      Tuple t = TupleFactory.getInstance().newTuple();
      t.append(i == 0 ? 0.0F : r.nextFloat());
      bag.add(t);
    }

    POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
    LoadFunc load = new TestLoader();
    op.setFuncSpec(new FuncSpec(load.getClass().getName()));
    POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
    PhysicalPlan plan = new PhysicalPlan();
    plan.add(prj);
    plan.add(op);
    plan.connect(prj, op);

    prj.setResultType(DataType.FLOAT);

    // Plan to test when result type is ByteArray and casting is requested
    // for example casting of values coming out of map lookup.
    POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
    PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Boolean b = Boolean.valueOf(((Float) t.get(0)) != 0.0F);
            Result res = op.getNextBoolean();
            if(res.returnStatus == POStatus.STATUS_OK) {
                //System.out.println(res.result + " : " + i);
                assertEquals(b, res.result);
            }
            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextBoolean();
            if(res.returnStatus == POStatus.STATUS_OK)
                assertEquals(b, res.result);
        }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Integer i = ((Float) t.get(0)).intValue();
      Result res = op.getNextInteger();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + i);
        assertEquals(i, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextInteger();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(i, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Float f = ((Float)t.get(0)).floatValue();
      Result res = op.getNextFloat();
      if(res.returnStatus == POStatus.STATUS_OK) {
//        System.out.println(res.result + " : " + f);
        assertEquals(f, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextFloat();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(f, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Long l = ((Float)t.get(0)).longValue();
      Result res = op.getNextLong();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + l);
        assertEquals(l, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextLong();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(l, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Double d = ((Float)t.get(0)).doubleValue();
      Result res = op.getNextDouble();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + d);
        assertEquals(d, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextDouble();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(d, res.result);
    }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            DateTime dt = new DateTime(((Float)t.get(0)).longValue());
            Result res = op.getNextDateTime();
            if(res.returnStatus == POStatus.STATUS_OK) {
                //System.out.println(res.result + " : " + dt);
                assertEquals(dt, res.result);
            }

            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextDateTime();
            if(res.returnStatus == POStatus.STATUS_OK)
                assertEquals(dt, res.result);
        }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      String str = ((Float)t.get(0)).toString();
      Result res = op.getNextString();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + str);
        assertEquals(str, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextString();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(str, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      DataByteArray dba = new DataByteArray(((Float)t.get(0)).toString().getBytes());
      Result res = op.getNextDataByteArray();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + dba);
        assertEquals(dba, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextDataByteArray();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(dba, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      if(t.get(0) == null) {

            Float result = (Float) op.getNextFloat().result;
        assertEquals( null, result);

      }
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Map map = null;
      Result res = op.getNextMap();
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Result res = op.getNextTuple();
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      DataBag b = null;
      Result res = op.getNextDataBag();
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextMap();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextTuple();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextDataBag();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
  }
View Full Code Here

      Tuple t = TupleFactory.getInstance().newTuple();
      t.append(i == 0 ? 0.0D : r.nextDouble());
      bag.add(t);
    }

    POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
    LoadFunc load = new TestLoader();
    op.setFuncSpec(new FuncSpec(load.getClass().getName()));
    POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
    PhysicalPlan plan = new PhysicalPlan();
    plan.add(prj);
    plan.add(op);
    plan.connect(prj, op);

    prj.setResultType(DataType.DOUBLE);

    // Plan to test when result type is ByteArray and casting is requested
    // for example casting of values coming out of map lookup.
    POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
    PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);

        for (Iterator<Tuple> it = bag.iterator(); it.hasNext();) {
            Tuple t = it.next();
            plan.attachInput(t);
            Boolean b = Boolean.valueOf(((Double) t.get(0)) != 0.0D);
            Result res = op.getNextBoolean();
            if (res.returnStatus == POStatus.STATUS_OK) {
                // System.out.println(res.result + " : " + i);
                assertEquals(b, res.result);
            }
            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextBoolean();
            if (res.returnStatus == POStatus.STATUS_OK)
                assertEquals(b, res.result);
        }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Integer i = ((Double) t.get(0)).intValue();
      Result res = op.getNextInteger();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + i);
        assertEquals(i, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextInteger();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(i, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Float f = ((Double)t.get(0)).floatValue();
      Result res = op.getNextFloat();
      if(res.returnStatus == POStatus.STATUS_OK) {
//        System.out.println(res.result + " : " + f);
        assertEquals(f, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextFloat();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(f, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Long l = ((Double)t.get(0)).longValue();
      Result res = op.getNextLong();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + l);
        assertEquals(l, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextLong();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(l, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Double d = ((Double)t.get(0)).doubleValue();
      Result res = op.getNextDouble();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + d);
        assertEquals(d, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextDouble();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(d, res.result);
    }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            DateTime dt = new DateTime(((Double)t.get(0)).longValue());
            Result res = op.getNextDateTime();
            if(res.returnStatus == POStatus.STATUS_OK) {
                //System.out.println(res.result + " : " + dt);
                assertEquals(dt, res.result);
            }

            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextDateTime();
            if(res.returnStatus == POStatus.STATUS_OK)
                assertEquals(dt, res.result);
        }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      String str = ((Double)t.get(0)).toString();
      Result res = op.getNextString();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + str);
        assertEquals(str, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextString();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(str, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      DataByteArray dba = new DataByteArray(((Double)t.get(0)).toString().getBytes());
      Result res = op.getNextDataByteArray();
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + dba);
        assertEquals(dba, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNextDataByteArray();
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(dba, res.result);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Map map = null;
      Result res = op.getNextMap();
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Result res = op.getNextTuple();
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }

    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      DataBag b = null;
      Result res = op.getNextDataBag();
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
    {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextMap();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextTuple();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextDataBag();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
  }
View Full Code Here

            Tuple t = TupleFactory.getInstance().newTuple();
            t.append(i == 0 ? new DateTime(0L) : new DateTime(r.nextLong()));
            bag.add(t);
        }

        POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
        LoadFunc load = new TestLoader();
        op.setFuncSpec(new FuncSpec(load.getClass().getName()));
        POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
        PhysicalPlan plan = new PhysicalPlan();
        plan.add(prj);
        plan.add(op);
        plan.connect(prj, op);

        prj.setResultType(DataType.DATETIME);

        // Plan to test when result type is ByteArray and casting is requested
        // for example casting of values coming out of map lookup.
        POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
        PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);

        for (Iterator<Tuple> it = bag.iterator(); it.hasNext();) {
            Tuple t = it.next();
            plan.attachInput(t);
            Boolean b = null;
            Result res = op.getNextBoolean();
            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Integer i = new Long(((DateTime) t.get(0)).getMillis()).intValue();
            Result res = op.getNextInteger();
            if(res.returnStatus == POStatus.STATUS_OK) {
                //System.out.println(res.result + " : " + i);
                assertEquals(i, res.result);
            }

            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextInteger();
            if(res.returnStatus == POStatus.STATUS_OK)
                assertEquals(i, res.result);

        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Float f = new Float(Long.valueOf(((DateTime) t.get(0)).getMillis()).floatValue());
            Result res = op.getNextFloat();
            if(res.returnStatus == POStatus.STATUS_OK) {
                //System.out.println(res.result + " : " + f);
                assertEquals(f, res.result);
            }

            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextFloat();
            if(res.returnStatus == POStatus.STATUS_OK)
                assertEquals(f, res.result);
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Long l = new Long(((DateTime)t.get(0)).getMillis());
            Result res = op.getNextLong();
            if(res.returnStatus == POStatus.STATUS_OK) {
                //System.out.println(res.result + " : " + l);
                assertEquals(l, res.result);
            }

            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextLong();
            if(res.returnStatus == POStatus.STATUS_OK)
                assertEquals(l, res.result);
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Double d = new Double(Long.valueOf(((DateTime) t.get(0)).getMillis()).doubleValue());
            Result res = op.getNextDouble();
            if(res.returnStatus == POStatus.STATUS_OK) {
                //System.out.println(res.result + " : " + f);
                assertEquals(d, res.result);
            }

            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextDouble();
            if(res.returnStatus == POStatus.STATUS_OK)
                assertEquals(d, res.result);
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            DateTime dt = (DateTime)t.get(0);
            Result res = op.getNextDateTime();
            if(res.returnStatus == POStatus.STATUS_OK) {
                //System.out.println(res.result + " : " + l);
                assertEquals(dt, res.result);
            }

            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextDateTime();
            if(res.returnStatus == POStatus.STATUS_OK)
                assertEquals(dt, res.result);
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            String str = ((DateTime)t.get(0)).toString();
            Result res = op.getNextString();
            if(res.returnStatus == POStatus.STATUS_OK) {
                //System.out.println(res.result + " : " + str);
                assertEquals(str, res.result);
            }

            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextString();
            if(res.returnStatus == POStatus.STATUS_OK)
                assertEquals(str, res.result);
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            DataByteArray dba = new DataByteArray(((DateTime)t.get(0)).toString().getBytes());
            Result res = op.getNextDataByteArray();
            if(res.returnStatus == POStatus.STATUS_OK) {
                //System.out.println(res.result + " : " + dba);
                assertEquals(dba, res.result);
            }

            planToTestBACasts.attachInput(t);
            res = opWithInputTypeAsBA.getNextDataByteArray();
            if(res.returnStatus == POStatus.STATUS_OK)
                assertEquals(dba, res.result);
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Map map = null;
            Result res = op.getNextMap();
            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            Result res = op.getNextTuple();
            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
        }

        for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
            Tuple t = it.next();
            plan.attachInput(t);
            DataBag b = null;
            Result res = op.getNextDataBag();
            assertEquals(POStatus.STATUS_ERR, res.returnStatus);
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextMap();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextTuple();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNextDataBag();
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
    }
View Full Code Here

      Tuple t = TupleFactory.getInstance().newTuple();
      t.append(r.nextInt());
      bag.add(t);
    }
   
    POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
    LoadFunc load = new TestLoader();
    op.setLoadFSpec(new FuncSpec(load.getClass().getName()));
    POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
    PhysicalPlan plan = new PhysicalPlan();
    plan.add(prj);
    plan.add(op);
    plan.connect(prj, op);
   
    prj.setResultType(DataType.INTEGER);
    // Plan to test when result type is ByteArray and casting is requested
    // for example casting of values coming out of map lookup.
    POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
    PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Integer i = (Integer) t.get(0);
      Result res = op.getNext(i);
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(i, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(i);
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(i, res.result);
      }
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Float f = ((Integer)t.get(0)).floatValue();
      Result res = op.getNext(f);
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(f, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(f);
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(f, res.result);
      }
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Long l = ((Integer)t.get(0)).longValue();
      Result res = op.getNext(l);
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(l, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(l);
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(l, res.result);
      }
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Double d = ((Integer)t.get(0)).doubleValue();
      Result res = op.getNext(d);
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(d, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(d);
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(d, res.result);
      }
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      String str = ((Integer)t.get(0)).toString();
      Result res = op.getNext(str);
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(str, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(str);
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(str, res.result);
      }
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      DataByteArray dba = new DataByteArray(((Integer)t.get(0)).toString().getBytes());
      Result res = op.getNext(dba);
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(dba, res.result);
      }
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(dba);
      if(res.returnStatus == POStatus.STATUS_OK) {
        assertEquals(dba, res.result);
      }
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Map map = null;
      Result res = op.getNext(map);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Result res = op.getNext(t);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      DataBag b = null;
      Result res = op.getNext(b);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNext(dummyMap);
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNext(dummyTuple);
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNext(dummyBag);
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
  }
View Full Code Here

      Tuple t = TupleFactory.getInstance().newTuple();
      t.append(r.nextLong());
      bag.add(t);
    }
   
    POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
    LoadFunc load = new TestLoader();
    op.setLoadFSpec(new FuncSpec(load.getClass().getName()));
    POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
    PhysicalPlan plan = new PhysicalPlan();
    plan.add(prj);
    plan.add(op);
    plan.connect(prj, op);
   
    prj.setResultType(DataType.LONG);
   
    // Plan to test when result type is ByteArray and casting is requested
    // for example casting of values coming out of map lookup.
    POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
    PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Integer i = ((Long) t.get(0)).intValue();
      Result res = op.getNext(i);
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + i);
        assertEquals(i, res.result);
      }
     
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(i);
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(i, res.result);
     
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Float f = ((Long)t.get(0)).floatValue();
      Result res = op.getNext(f);
      if(res.returnStatus == POStatus.STATUS_OK) {
//         System.out.println(res.result + " : " + f);
        assertEquals(f, res.result);
      }
     
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(f);
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(f, res.result);
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Long l = ((Long)t.get(0)).longValue();
      Result res = op.getNext(l);
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + l);
        assertEquals(l, res.result);
      }
     
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(l);
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(l, res.result);
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Double d = ((Long)t.get(0)).doubleValue();
      Result res = op.getNext(d);
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + d);
        assertEquals(d, res.result);
      }
     
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(d);
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(d, res.result);
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      String str = ((Long)t.get(0)).toString();
      Result res = op.getNext(str);
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + str);
        assertEquals(str, res.result);
      }
     
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(str);
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(str, res.result);
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      DataByteArray dba = new DataByteArray(((Long)t.get(0)).toString().getBytes());
      Result res = op.getNext(dba);
      if(res.returnStatus == POStatus.STATUS_OK) {
        //System.out.println(res.result + " : " + dba);
        assertEquals(dba, res.result);
      }
     
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(dba);
      if(res.returnStatus == POStatus.STATUS_OK)
        assertEquals(dba, res.result);
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Map map = null;
      Result res = op.getNext(map);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      Result res = op.getNext(t);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
   
    for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
      Tuple t = it.next();
      plan.attachInput(t);
      DataBag b = null;
      Result res = op.getNext(b);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNext(dummyMap);
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNext(dummyTuple);
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
        {
            planToTestBACasts.attachInput(dummyTuple);
            try{
                opWithInputTypeAsBA.getNext(dummyBag);
            }catch (Exception e) {
                assertEquals(ExecException.class, e.getClass());
            }
        }
  }
View Full Code Here

TOP

Related Classes of org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POCast

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.