Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
// description: Demonstration of View transform usage.
// multifile: false
// default_example: false
// context_line: 49
// context_line: 50
// categories:
// - Core Transforms
// complexity: MEDIUM
Expand Down Expand Up @@ -99,12 +99,12 @@ public void processElement(
.withSideInput("citiesToCountries", citiesToCountriesView));
// [END main_section]

output.apply("Log", ParDo.of(new LogOutput<>("Output: ")));
output.apply("Log", ParDo.of(new LogOutput("Output: ")));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the Playground CI environment has issues with type inference or the diamond operator, it is better to provide explicit type arguments while keeping the utility class generic. This preserves the reusability of the LogOutput class.

Suggested change
output.apply("Log", ParDo.of(new LogOutput("Output: ")));
output.apply("Log", ParDo.of(new LogOutput<KV<String, String>>("Output: ")));


pipeline.run();
}

static class LogOutput<T> extends DoFn<T, T> {
static class LogOutput extends DoFn<KV<String, String>, KV<String, String>> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Changing LogOutput from a generic class to one hardcoded for KV<String, String> reduces its maintainability and reusability. It is generally better to keep such utility classes generic, especially in example code which serves as a reference for best practices.

Suggested change
static class LogOutput extends DoFn<KV<String, String>, KV<String, String>> {
static class LogOutput<T> extends DoFn<T, T> {

private static final Logger LOG = LoggerFactory.getLogger(LogOutput.class);
private final String prefix;

Expand Down
Loading