DataBag newInputData = newBaseData.get(op);
if(newInputData == null) {
newInputData = BagFactory.getInstance().newDefaultBag();
newBaseData.put(op, newInputData);
}
TupleSchema schema = op.outputSchema();
// first of all, we are required to guarantee that there is at least one output tuple
if (outputConstraints.cardinality() == 0 && inputData.cardinality() == 0) {
outputConstraints.add(new Tuple(schema.numFields())); // add an output constraint for one tuple
}
// create example tuple to steal values from when we encounter "don't care" fields (i.e. null fields)
Tuple exampleTuple;
if (inputData.cardinality() > 0) {
// select first tuple from input data
exampleTuple = inputData.iterator().next();
} else {
// input data is empty, so make up a tuple
Tuple exampleT = new Tuple(schema.numFields());
exampleTuple = new ExampleTuple();
exampleTuple.copyFrom(exampleT);
for (int i = 0; i < exampleTuple.arity(); i++) exampleTuple.setField(i, "0");
}
// run through output constraints; for each one synthesize a tuple and add it to the base data
// (while synthesizing individual fields, try to match fields that exist in the real data)
for (Iterator<Tuple> it = outputConstraints.iterator(); it.hasNext(); ) {
Tuple outputConstraint = it.next();
// sanity check:
if (outputConstraint.arity() != schema.numFields()) throw new RuntimeException("Internal error: incorrect number of fields in constraint tuple.");
Tuple inputT = new Tuple(outputConstraint.arity());
ExampleTuple inputTuple = new ExampleTuple();
inputTuple.copyFrom(inputT);
for (int i = 0; i < inputTuple.arity(); i++) {