-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[BEAM-117] Validate display data registration in Dataflow Runner #325
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...d-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/io/DataflowAvroIOTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.beam.runners.dataflow.io; | ||
|
|
||
| import static org.apache.beam.sdk.transforms.display.DisplayDataMatchers.hasDisplayItem; | ||
|
|
||
| import static org.hamcrest.Matchers.hasItem; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.apache.beam.runners.dataflow.DataflowPipelineRunner; | ||
| import org.apache.beam.runners.dataflow.transforms.DataflowDisplayDataEvaluator; | ||
| import org.apache.beam.sdk.io.AvroIO; | ||
| import org.apache.beam.sdk.transforms.display.DisplayData; | ||
| import org.apache.beam.sdk.transforms.display.DisplayDataEvaluator; | ||
|
|
||
| import org.apache.avro.Schema; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * {@link DataflowPipelineRunner} specific tests for {@link AvroIO} transforms. | ||
| */ | ||
| @RunWith(JUnit4.class) | ||
| public class DataflowAvroIOTest { | ||
| @Test | ||
| public void testPrimitiveWriteDisplayData() { | ||
| DisplayDataEvaluator evaluator = DataflowDisplayDataEvaluator.create(); | ||
|
|
||
| AvroIO.Write.Bound<?> write = AvroIO.Write | ||
| .to("foo") | ||
| .withSchema(Schema.create(Schema.Type.STRING)) | ||
| .withoutValidation(); | ||
|
|
||
| Set<DisplayData> displayData = evaluator.displayDataForPrimitiveTransforms(write); | ||
| assertThat("AvroIO.Write should include the file pattern in its primitive transform", | ||
| displayData, hasItem(hasDisplayItem("fileNamePattern"))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testPrimitiveReadDisplayData() { | ||
| DisplayDataEvaluator evaluator = DataflowDisplayDataEvaluator.create(); | ||
|
|
||
| AvroIO.Read.Bound<?> read = AvroIO.Read.from("foo.*") | ||
| .withSchema(Schema.create(Schema.Type.STRING)) | ||
| .withoutValidation(); | ||
|
|
||
| Set<DisplayData> displayData = evaluator.displayDataForPrimitiveTransforms(read); | ||
| assertThat("AvroIO.Read should include the file pattern in its primitive transform", | ||
| displayData, hasItem(hasDisplayItem("filePattern"))); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ | |
| package org.apache.beam.runners.dataflow.io; | ||
|
|
||
| import static org.apache.beam.sdk.transforms.display.DisplayDataMatchers.hasDisplayItem; | ||
| import static org.apache.beam.sdk.transforms.display.DisplayDataMatchers.hasKey; | ||
|
|
||
| import static org.hamcrest.Matchers.hasItem; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
@@ -39,6 +38,30 @@ | |
| * Unit tests for Dataflow usage of {@link BigQueryIO} transforms. | ||
| */ | ||
| public class DataflowBigQueryIOTest { | ||
| @Test | ||
| public void testTableSourcePrimitiveDisplayData() { | ||
| DisplayDataEvaluator evaluator = DataflowDisplayDataEvaluator.create(); | ||
| BigQueryIO.Read.Bound read = BigQueryIO.Read | ||
| .from("project:dataset.tableId") | ||
| .withoutValidation(); | ||
|
|
||
| Set<DisplayData> displayData = evaluator.displayDataForPrimitiveTransforms(read); | ||
| assertThat("BigQueryIO.Read should include the table spec in its primitive display data", | ||
| displayData, hasItem(hasDisplayItem("table"))); | ||
|
Contributor
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. This assertion reads unfortunately -- |
||
| } | ||
|
|
||
| @Test | ||
| public void testQuerySourcePrimitiveDisplayData() { | ||
| DisplayDataEvaluator evaluator = DataflowDisplayDataEvaluator.create(); | ||
| BigQueryIO.Read.Bound read = BigQueryIO.Read | ||
| .fromQuery("foobar") | ||
| .withoutValidation(); | ||
|
|
||
| Set<DisplayData> displayData = evaluator.displayDataForPrimitiveTransforms(read); | ||
| assertThat("BigQueryIO.Read should include the query in its primitive display data", | ||
| displayData, hasItem(hasDisplayItem("query"))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBatchSinkPrimitiveDisplayData() { | ||
| DataflowPipelineOptions options = DataflowDisplayDataEvaluator.getDefaultOptions(); | ||
|
|
@@ -63,9 +86,9 @@ private void testSinkPrimitiveDisplayData(DataflowPipelineOptions options) { | |
|
|
||
| Set<DisplayData> displayData = evaluator.displayDataForPrimitiveTransforms(write); | ||
| assertThat("BigQueryIO.Write should include the table spec in its primitive display data", | ||
| displayData, hasItem(hasDisplayItem(hasKey("tableSpec")))); | ||
| displayData, hasItem(hasDisplayItem("tableSpec"))); | ||
|
|
||
| assertThat("BigQueryIO.Write should include the table schema in its primitive display data", | ||
| displayData, hasItem(hasDisplayItem(hasKey("schema")))); | ||
| displayData, hasItem(hasDisplayItem("schema"))); | ||
| } | ||
| } | ||
63 changes: 63 additions & 0 deletions
63
...aflow-java/src/test/java/org/apache/beam/runners/dataflow/io/DataflowDatastoreIOTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.beam.runners.dataflow.io; | ||
|
|
||
| import static org.apache.beam.sdk.transforms.display.DisplayDataMatchers.hasDisplayItem; | ||
|
|
||
| import static org.hamcrest.Matchers.hasItem; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.apache.beam.runners.dataflow.transforms.DataflowDisplayDataEvaluator; | ||
| import org.apache.beam.sdk.io.DatastoreIO; | ||
| import org.apache.beam.sdk.transforms.PTransform; | ||
| import org.apache.beam.sdk.transforms.display.DisplayData; | ||
| import org.apache.beam.sdk.transforms.display.DisplayDataEvaluator; | ||
| import org.apache.beam.sdk.values.PCollection; | ||
| import org.apache.beam.sdk.values.PInput; | ||
|
|
||
| import com.google.api.services.datastore.DatastoreV1; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Unit tests for Dataflow usage of {@link DatastoreIO} transforms. | ||
| */ | ||
| public class DataflowDatastoreIOTest { | ||
| @Test | ||
| public void testSourcePrimitiveDisplayData() { | ||
| DisplayDataEvaluator evaluator = DataflowDisplayDataEvaluator.create(); | ||
| PTransform<PInput, ?> read = DatastoreIO.readFrom( | ||
| "myDataset", DatastoreV1.Query.newBuilder().build()); | ||
|
|
||
| Set<DisplayData> displayData = evaluator.displayDataForPrimitiveTransforms(read); | ||
| assertThat("DatastoreIO read should include the dataset in its primitive display data", | ||
| displayData, hasItem(hasDisplayItem("dataset"))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSinkPrimitiveDisplayData() { | ||
| DisplayDataEvaluator evaluator = DataflowDisplayDataEvaluator.create(); | ||
| PTransform<PCollection<DatastoreV1.Entity>, ?> write = DatastoreIO.writeTo("myDataset"); | ||
|
|
||
| Set<DisplayData> displayData = evaluator.displayDataForPrimitiveTransforms(write); | ||
| assertThat("DatastoreIO write should include the dataset in its primitive display data", | ||
| displayData, hasItem(hasDisplayItem("dataset"))); | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
...dataflow-java/src/test/java/org/apache/beam/runners/dataflow/io/DataflowPubsubIOTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.beam.runners.dataflow.io; | ||
|
|
||
| import static org.apache.beam.sdk.transforms.display.DisplayDataMatchers.hasDisplayItem; | ||
|
|
||
| import static org.hamcrest.Matchers.hasItem; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.apache.beam.runners.dataflow.DataflowPipelineRunner; | ||
| import org.apache.beam.runners.dataflow.transforms.DataflowDisplayDataEvaluator; | ||
| import org.apache.beam.sdk.io.PubsubIO; | ||
| import org.apache.beam.sdk.transforms.display.DisplayData; | ||
| import org.apache.beam.sdk.transforms.display.DisplayDataEvaluator; | ||
|
|
||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * {@link DataflowPipelineRunner} specific tests for {@link PubsubIO} transforms. | ||
| */ | ||
| @RunWith(JUnit4.class) | ||
| public class DataflowPubsubIOTest { | ||
| @Test | ||
| public void testPrimitiveWriteDisplayData() { | ||
| DisplayDataEvaluator evaluator = DataflowDisplayDataEvaluator.create(); | ||
| PubsubIO.Write.Bound<?> write = PubsubIO.Write | ||
| .topic("projects/project/topics/topic"); | ||
|
|
||
| Set<DisplayData> displayData = evaluator.displayDataForPrimitiveTransforms(write); | ||
| assertThat("PubsubIO.Write should include the topic in its primitive display data", | ||
| displayData, hasItem(hasDisplayItem("topic"))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testPrimitiveReadDisplayData() { | ||
| DisplayDataEvaluator evaluator = DataflowDisplayDataEvaluator.create(); | ||
| PubsubIO.Read.Bound<String> read = PubsubIO.Read.topic("projects/project/topics/topic"); | ||
|
|
||
| Set<DisplayData> displayData = evaluator.displayDataForPrimitiveTransforms(read); | ||
| assertThat("PubsubIO.Read should include the topic in its primitive display data", | ||
| displayData, hasItem(hasDisplayItem("topic"))); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm surprised this validation required adding dependencies on avro and datastore. Is there a reason these dependencies appeared now but not before?
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.
Previously there was no direct dependency on Avro/Datastore in Dataflow runner. This change adds integration tests which directly reference classes in these packages.