Apex DAG Java API
The low-level DAG API is defined by the Apex engine. Any application that runs on Apex, irrespective of the original specification format, will be translated into this API. It is sometimes also referred to as compositional, as it represents the logical DAG, which will be translated into a physical plan and mapped to the execution layer by the Apex runtime.
The following is the Word Count example application, briefly introduced in the Stream Processing section earlier written with the DAG API:
LineReader lineReader = dag.addOperator("input", new LineReader()); Parser parser = dag.addOperator("parser", new Parser()); UniqueCounter counter = dag.addOperator("counter", new UniqueCounter()); ConsoleOutputOperator cons = dag.addOperator("console", new
ConsoleOutputOperator()); dag.addStream("lines", lineReader.output, parser.input); dag.addStream("words", parser.output, counter.data); dag.addStream("counts", counter.count, cons.input);
The developer implements a method that is provided with a DAG handle by the engine (in this case, dag) through which operators are added and then connected with streams.
As mentioned, the Apex library provides many prebuilt operators. Operators can also be custom and encapsulate use case specific logic, or they can come from a library of an organization to share reusable logic across applications.
The DAG API is referred to as low level because many aspects are explicit. The developer identifies the operators and is aware of the ports for stream connections. In the case of larger applications, the wiring code can become more challenging to navigate. At the same time, the DAG API offers the most flexibility to the developer and is often used in larger projects that typically involve significant operator development and customization and where the complexity of wiring the DAG is normally not a concern.