Skip to content
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

Cleans up PTransform validation across Beam #3730

Closed
wants to merge 1 commit into from

Conversation

jkff
Copy link
Contributor

@jkff jkff commented Aug 18, 2017

  • Moves validation from validate() to expand() when possible
  • Replaces checkNotNull() with checkArgument() when possible
  • Shortens overly verbose validation messages in a few IOs

As a piggyback, one of the sites to be cleaned up was AssignWindows which happened to be unused (it is also unused by Dataflow Worker), so I deleted it.

R: @tgroh

public void validate() {
spec.validate(null);
}
public void validate() {}
Copy link
Member

Choose a reason for hiding this comment

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

rm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (had to introduce a default empty validate() method in Source, which is probably a good thing anyway, and I removed a bunch more empty validate() methods)

return builder().setMaxReadTime(maxReadTime).build();
}

@Override
public PCollection<byte[]> expand(PBegin input) {
checkArgument(maxReadTime() == null,
"withMaxNumRecords() and withMaxReadTime() are exclusive");
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem to check both

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

public void validate() {
spec.validate(null);
}
public void validate() {}
Copy link
Member

Choose a reason for hiding this comment

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

rm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -282,9 +270,7 @@ private BoundedMongoDbSource(Read spec) {
}

@Override
public void validate() {
spec.validate(null);
}
Copy link
Member

Choose a reason for hiding this comment

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

rm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

checkArgument(numSplits >= 0, "MongoDbIO.read().withNumSplits(numSplits) called with "
+ "invalid number. The number of splits has to be a positive value (currently %d)",
numSplits);
checkArgument(numSplits >= 0, "invalid num_splits: must be > 0, but was %d", numSplits);
Copy link
Member

Choose a reason for hiding this comment

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

This message and check don't agree on the requirement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

checkNotNull(parseFn, "parseFn");
checkNotNull(parseFn, "coder");
checkArgument(parseFn != null, "parseFn can not be null");
checkArgument(parseFn != null, "parseFn can not be null");
Copy link
Member

Choose a reason for hiding this comment

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

coder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

table != null || getQuery() != null,
"Invalid BigQueryIO.Read: one of table reference and query must be set");

if (table != null) {
Copy link
Member

Choose a reason for hiding this comment

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

We may be able to collapse these a bit;

if (table == null) {
checkArgument(query != null, ...)
// query validation
} else {
checkArgument(query == null, ...)
// table validation
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -540,6 +512,37 @@ public void validate(PipelineOptions options) {

@Override
public PCollection<TableRow> expand(PBegin input) {
ValueProvider<TableReference> table = getTableProvider();

checkState(
Copy link
Member

Choose a reason for hiding this comment

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

checkArguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

type != null,
"ConnectionConfiguration.create(addresses, index, type) called with null type");
checkArgument(addresses != null, "addresses can not be null");
checkArgument(addresses.length != 0, "addresses can not be empty");
Copy link
Member

Choose a reason for hiding this comment

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

length > 0, ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

public void validate() {
spec.validate(null);
}
public void validate() {}
Copy link
Member

Choose a reason for hiding this comment

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

rm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling e9bbabd on jkff:validate-cleanup into ** on apache:master**.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 70.005% when pulling 0a83f83 on jkff:validate-cleanup into d261d6b on apache:master.

@jkff jkff force-pushed the validate-cleanup branch 2 times, most recently from 6ff7b24 to 45b267b Compare August 29, 2017 23:54
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 69.984% when pulling 45b267b on jkff:validate-cleanup into d64f2cc on apache:master.

- Moves validation from validate() to expand() when possible
- Replaces checkNotNull() with checkArgument() when possible
- Shortens overly verbose validation messages in a few IOs
@jkff
Copy link
Contributor Author

jkff commented Sep 7, 2017

Rebased, PTAL.

@jkff
Copy link
Contributor Author

jkff commented Sep 11, 2017

retest this please

Copy link
Member

@tgroh tgroh left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -1130,6 +1122,12 @@ public DeleteKey withProjectId(ValueProvider<String> projectId) {

@Override
public PDone expand(PCollection<T> input) {
checkArgument(projectId != null, "withProjectId() is required");
if (projectId.isAccessible()) {
Copy link
Member

Choose a reason for hiding this comment

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

My meaning is that it fits the appropriate mental model of when validation occurs rather than it will accept more pipelines properly

@asfgit asfgit closed this in e8bf045 Sep 11, 2017
@jkff jkff deleted the validate-cleanup branch September 11, 2017 22:39
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 69.489% when pulling 7b81dcb on jkff:validate-cleanup into 6dfd3a2 on apache:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants