Circular Reference in Graph

Hi,

Is there anyway to put a loop in the graph as I am doing something which seems to make a lot of sense but getting no-where as the graph is being thrown out becuase of a circular ref.

I have a file with various fields, one of which is an account number.

I am passing this to a Simple Gather (Port 0) and then on to a DEDUP (port 0). If the account number is not a duplicate it then passes it to a file, if not I have a link back to the Simple Gather (Port 1) which processes it again.

The main goal behind this is to build a file where there are no two account numbers the same consecutively.

The error message I am getting is…

10:13:53,207 DEBUG [main] - Dump of references between nodes:
10:13:53,207 DEBUG [main] - Detected loop when encountered node SIMPLE_GATHER1
10:13:53,207 DEBUG [main] - Chain of references:
10:13:53,207 DEBUG [main] - DATA_READER1 → SIMPLE_GATHER1 → DEDUP0 → SIMPLE_COPY0 → SIMPLE_GATHER1
10:13:53,207 ERROR [main] - Circular reference found in graph !
org.jetel.exception.GraphConfigurationException: Circular reference found in graph !
at org.jetel.graph.TransformationGraphAnalyzer.analyzeGraphTopology(TransformationGraphAnalyzer.java:101)
at org.jetel.graph.TransformationGraph.init(TransformationGraph.java:466)
at org.jetel.main.runGraph.main(runGraph.java:313)
10:13:53,207 ERROR [main] - Error - graph’s configuration invalid !
org.jetel.exception.GraphConfigurationException: Graph initialization failed.
at org.jetel.main.runGraph.main(runGraph.java:314)

Any ideas?

Thanks

Mike

ps By passing file unsorted as it comes… I am hoping that this will work as it will only look at the first two lines?

Is that correct.

Hi,
loops in graph are not allowed. You can use reformat component with following transformation to do what you need:

 
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.jetel.component.DataRecordTransform;
import org.jetel.data.DataRecord;
import org.jetel.exception.TransformException;
import org.jetel.graph.OutputPort;


public class transformation extends DataRecordTransform {
	
	List<DataRecord> records = new ArrayList<DataRecord>();
	Integer lastKey = null;

	@Override
	public boolean transform(DataRecord[] inputRecords,
			DataRecord[] outputRecords) throws TransformException {
		if (lastKey == null || !inputRecords[0].getField("no").getValue().equals(lastKey)) {
			lastKey = (Integer)inputRecords[0].getField("no").getValue();
			return defaultTransform(inputRecords, outputRecords);
		}
		outputRecords[0].reset();
		for (DataRecord record : records) {
			if (!record.getField("no").getValue().equals(lastKey)) {
				records.remove(record);
				outputRecords[0].copyFrom(record);
				break;
			}
		}
		records.add(inputRecords[0].duplicate());
		return true;
	}
	
	@Override
	public void finished() {
		OutputPort out = getGraph().getNodes().get("REFORMAT0").getOutputPort(0);
		for (DataRecord record : records) {
			try {
				out.writeRecord(record);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		super.finished();
	}

}

Only problem is that some output records can be empty.