0
# Output Handlers
1
2
Result output system supporting multiple formats for algorithm results including console display, file export, and verification utilities. All outputs implement the standardized Output interface.
3
4
## Capabilities
5
6
### Output Interface
7
8
Base interface that all result output handlers must implement.
9
10
```java { .api }
11
/**
12
* Base interface for all result output handlers
13
* @param <T> Result data type
14
*/
15
public interface Output<T> extends Parameterized {
16
/** Write algorithm results to specified destination */
17
void write(String executionName, PrintStream out, DataSet<T> data) throws Exception;
18
}
19
```
20
21
### Output Base Class
22
23
Base implementation providing common functionality for output handlers.
24
25
```java { .api }
26
/**
27
* Base class for output handlers with common parameter handling
28
*/
29
public abstract class OutputBase<T> extends ParameterizedBase implements Output<T> {
30
// Common functionality for all output implementations
31
}
32
```
33
34
### Console Output
35
36
#### Print Output
37
38
Displays algorithm results directly to console with optional execution plan visualization.
39
40
```java { .api }
41
/**
42
* Console output handler for displaying results to stdout
43
*/
44
public class Print extends OutputBase<T> {
45
/** Print Flink execution plan before results */
46
BooleanParameter printExecutionPlan;
47
}
48
```
49
50
**Usage Examples:**
51
52
```bash
53
# Basic console output
54
--output Print
55
56
# Print with execution plan
57
--output Print --print_execution_plan
58
```
59
60
**Output Format Examples:**
61
62
```
63
PageRank Results:
64
Vertex(1, 0.234567)
65
Vertex(2, 0.456789)
66
Vertex(3, 0.123456)
67
68
Analytics:
69
- Total vertices: 1000
70
- Total edges: 499500
71
- Iterations: 12
72
- Convergence achieved: true
73
```
74
75
## File-Based Output
76
77
### CSV Output
78
79
Writes algorithm results to CSV files with configurable formatting.
80
81
```java { .api }
82
/**
83
* CSV file output for writing results to comma-separated files
84
*/
85
public class CSV extends OutputBase<T> {
86
/** Output file path */
87
StringParameter outputFilename;
88
89
/** Field separator character (default: comma) */
90
StringParameter fieldDelimiter;
91
92
/** Include header row in output */
93
BooleanParameter includeHeader;
94
95
/** Number format for floating-point values */
96
StringParameter numberFormat;
97
}
98
```
99
100
**Usage Examples:**
101
102
```bash
103
# Basic CSV output
104
--output CSV --output_filename results.csv
105
106
# CSV with custom delimiter and formatting
107
--output CSV --output_filename results.tsv --field_delimiter "\t" --include_header
108
```
109
110
**CSV Output Format Examples:**
111
112
```csv
113
# PageRank results
114
vertex_id,pagerank_score
115
1,0.234567
116
2,0.456789
117
3,0.123456
118
119
# Edge list results
120
source,target,weight
121
1,2,0.5
122
2,3,1.0
123
3,1,0.8
124
125
# Connected components results
126
vertex_id,component_id
127
1,1
128
2,1
129
3,2
130
```
131
132
## Verification and Testing
133
134
### Hash Output
135
136
Computes cryptographic hash of results for verification and testing purposes.
137
138
```java { .api }
139
/**
140
* Hash output for result verification and testing
141
* Computes deterministic hash of algorithm results
142
*/
143
public class Hash extends OutputBase<T> {
144
/** Hash algorithm to use (default: MD5) */
145
StringParameter hashAlgorithm;
146
147
/** Output hash to file instead of console */
148
StringParameter hashOutputFile;
149
}
150
```
151
152
**Usage Examples:**
153
154
```bash
155
# Compute MD5 hash of results
156
--output Hash
157
158
# Use SHA-256 and save to file
159
--output Hash --hash_algorithm SHA-256 --hash_output_file results.hash
160
```
161
162
**Hash Output Format:**
163
164
```
165
Result Hash (MD5): a1b2c3d4e5f6789012345678901234567890abcd
166
Record Count: 1000
167
```
168
169
## Output Configuration
170
171
### Common Parameters
172
173
All output handlers support common configuration options inherited from their base classes.
174
175
```java { .api }
176
// Common parameters available across output types
177
public abstract class OutputBase<T> extends ParameterizedBase implements Output<T> {
178
// Inherits getName(), getUsage(), configure() from ParameterizedBase
179
}
180
```
181
182
### Output Selection
183
184
Output handlers are selected by name through the command-line interface or programmatically.
185
186
```java { .api }
187
// Output factory for dynamic selection
188
ParameterizedFactory<Output> outputFactory = new ParameterizedFactory<Output>()
189
.addClass(Print.class)
190
.addClass(CSV.class)
191
.addClass(Hash.class);
192
```
193
194
## Usage Patterns
195
196
### Basic Output Usage
197
198
```java
199
// Configure print output
200
Print printOutput = new Print();
201
printOutput.configure(ParameterTool.fromArgs(new String[]{
202
"--print_execution_plan"
203
}));
204
205
// Write results
206
printOutput.write("PageRank Analysis", System.out, resultDataSet);
207
```
208
209
### File Output
210
211
```java
212
// Configure CSV output
213
CSV csvOutput = new CSV();
214
csvOutput.configure(ParameterTool.fromArgs(new String[]{
215
"--output_filename", "pagerank_results.csv",
216
"--field_delimiter", ",",
217
"--include_header"
218
}));
219
220
// Write results to file
221
csvOutput.write("Connected Components", System.out, componentResults);
222
```
223
224
### Verification Output
225
226
```java
227
// Configure hash output for testing
228
Hash hashOutput = new Hash();
229
hashOutput.configure(ParameterTool.fromArgs(new String[]{
230
"--hash_algorithm", "SHA-256"
231
}));
232
233
// Compute and display hash
234
hashOutput.write("Algorithm Verification", System.out, testResults);
235
```
236
237
### Output Selection by Name
238
239
```java
240
// Get output handler from factory
241
ParameterizedFactory<Output> factory = createOutputFactory();
242
Output output = factory.get("CSV");
243
244
if (output != null) {
245
output.configure(parameters);
246
output.write(executionName, System.out, results);
247
}
248
```
249
250
### Multiple Output Handling
251
252
```java
253
// Write results to multiple destinations
254
List<Output> outputs = Arrays.asList(
255
factory.get("Print"),
256
factory.get("CSV"),
257
factory.get("Hash")
258
);
259
260
for (Output output : outputs) {
261
output.configure(parameters);
262
output.write(executionName, System.out, results);
263
}
264
```
265
266
## Output Data Types
267
268
Different algorithms produce different result types that outputs must handle:
269
270
```java { .api }
271
// Common result types handled by outputs
272
DataSet<Vertex<K, VV>> // Vertex-centric results (PageRank, ConnectedComponents)
273
DataSet<Edge<K, EV>> // Edge-centric results (EdgeList)
274
DataSet<Tuple3<K, K, Double>> // Similarity scores (AdamicAdar, JaccardIndex)
275
DataSet<Tuple2<K, Double>> // Clustering coefficients
276
DataSet<Tuple3<K, K, K>> // Triangle listings
277
DataSet<String> // Graph metrics and statistics
278
```
279
280
## Error Handling
281
282
Output handlers provide comprehensive error handling for common failure scenarios:
283
284
- **File I/O Errors**: Clear messages for permission issues, disk space, invalid paths
285
- **Format Errors**: Validation of output formats and parameter combinations
286
- **Data Serialization**: Proper handling of complex data types and null values
287
- **Resource Management**: Automatic cleanup of file handles and temporary resources