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());
}
}
}