-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BEAM-240] Display data links for input and output files #300
Changes from 7 commits
c95a61a
6ff5bae
ca40e25
28739a7
fefc3ef
c28c447
f369a33
0c4e94d
b3e23ea
a453d71
6c83566
abcfce4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
import org.apache.beam.sdk.runners.PipelineRunner; | ||
import org.apache.beam.sdk.transforms.PTransform; | ||
import org.apache.beam.sdk.transforms.display.DisplayData; | ||
import org.apache.beam.sdk.util.IOChannelFactory; | ||
import org.apache.beam.sdk.util.IOChannelUtils; | ||
import org.apache.beam.sdk.util.MimeTypes; | ||
import org.apache.beam.sdk.values.PCollection; | ||
|
@@ -330,9 +331,12 @@ public PCollection<T> apply(PInput input) { | |
@Override | ||
public void populateDisplayData(DisplayData.Builder builder) { | ||
super.populateDisplayData(builder); | ||
builder | ||
.addIfNotNull(DisplayData.item("filePattern", filepattern)) | ||
.addIfNotDefault(DisplayData.item("validation", validate), true); | ||
if (filepattern != null) { | ||
builder.add(DisplayData.item("filePattern", filepattern) | ||
.withLinkUrl(getBrowseUrl(filepattern))); | ||
} | ||
|
||
builder.addIfNotDefault(DisplayData.item("validation", validate), true); | ||
} | ||
|
||
@Override | ||
|
@@ -693,9 +697,16 @@ public PDone apply(PCollection<T> input) { | |
@Override | ||
public void populateDisplayData(DisplayData.Builder builder) { | ||
super.populateDisplayData(builder); | ||
if (filenamePrefix != null) { | ||
// Append wildcard to browseUrl input since this is a prefix | ||
// for shardNameTemplate + fileSuffix. | ||
String browseUrl = getBrowseUrl(filenamePrefix + "*"); | ||
builder.add(DisplayData.item("filePrefix", filenamePrefix) | ||
.withLinkUrl(browseUrl)); | ||
} | ||
|
||
builder | ||
.add(DisplayData.item("schema", type)) | ||
.addIfNotNull(DisplayData.item("filePrefix", filenamePrefix)) | ||
.addIfNotDefault( | ||
DisplayData.item("shardNameTemplate", shardTemplate), | ||
DEFAULT_SHARD_TEMPLATE) | ||
|
@@ -760,6 +771,18 @@ private static void validateOutputComponent(String partialFilePattern) { | |
+ partialFilePattern); | ||
} | ||
|
||
private static String getBrowseUrl(String filePattern) { | ||
IOChannelFactory factory; | ||
try { | ||
factory = IOChannelUtils.getFactory(filePattern); | ||
} catch (IOException e) { | ||
throw new IllegalStateException( | ||
String.format("Invalid filePattern: %s", filePattern), e); | ||
} | ||
|
||
return factory.getBrowseUrl(filePattern); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move into the try block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason? I prefer to keep try blocks tight so it's clear which operation can throw and to not catch more than expected. |
||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
/** Disallow construction of utility class. */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My impression of the current code is that the
IOChannelFactory
is never interrogated unlessvalidate
is true. This should probably stick to that discipline.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated AvroIO and TextIO to be resilient to bad file schemes when their validation is disabled. I didn't update sources and sinks, but now I think they probably need the same treatment. I'll work on that now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.