Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/trigger_files/beam_PostCommit_XVR_Samza.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"modification": 1}
{"modification": 2}
1 change: 1 addition & 0 deletions .github/trigger_files/beam_PostCommit_XVR_Spark3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
Expand Up @@ -33,56 +33,55 @@
import org.apache.beam.sdk.schemas.SchemaTranslation;
import org.apache.beam.sdk.schemas.logicaltypes.MicrosInstant;
import org.apache.beam.sdk.testing.PAssert;
import org.apache.beam.sdk.testing.TestPipeline;
import org.apache.beam.sdk.testing.UsesPythonExpansionService;
import org.apache.beam.sdk.testing.ValidatesRunner;
import org.apache.beam.sdk.transforms.Create;
import org.apache.beam.sdk.transforms.Keys;
import org.apache.beam.sdk.util.PythonCallableSource;
import org.apache.beam.sdk.util.construction.BaseExternalTest;
import org.apache.beam.sdk.values.KV;
import org.apache.beam.sdk.values.PCollection;
import org.apache.beam.sdk.values.Row;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class PythonExternalTransformTest implements Serializable {
@Rule public transient TestPipeline testPipeline = TestPipeline.create();

@Test
@Category({ValidatesRunner.class, UsesPythonExpansionService.class})
public void trivialPythonTransform() {
PCollection<String> output =
testPipeline
.apply(Create.of(KV.of("A", "x"), KV.of("A", "y"), KV.of("B", "z")))
.apply(
PythonExternalTransform
.<PCollection<KV<String, String>>, PCollection<KV<String, Iterable<String>>>>
from("apache_beam.GroupByKey"))
.apply(Keys.create());
PAssert.that(output).containsInAnyOrder("A", "B");
testPipeline.run();
}

@Test
@Category({ValidatesRunner.class, UsesPythonExpansionService.class})
public void pythonTransformWithDependencies() {
PCollection<String> output =
testPipeline
.apply(Create.of("elephant", "mouse", "sheep"))
.apply(
PythonExternalTransform.<PCollection<String>, PCollection<String>>from(
"apache_beam.Map")
.withArgs(PythonCallableSource.of("import inflection\ninflection.pluralize"))
.withExtraPackages(ImmutableList.of("inflection"))
.withOutputCoder(StringUtf8Coder.of()));
PAssert.that(output).containsInAnyOrder("elephants", "mice", "sheep");
testPipeline.run();
@RunWith(JUnit4.class)
public static class RunPipelineTest extends BaseExternalTest {

@Test
@Category({ValidatesRunner.class, UsesPythonExpansionService.class})
public void trivialPythonTransform() {
PCollection<String> output =
testPipeline
.apply(Create.of(KV.of("A", "x"), KV.of("A", "y"), KV.of("B", "z")))
.apply(
PythonExternalTransform
.<PCollection<KV<String, String>>, PCollection<KV<String, Iterable<String>>>>
from("apache_beam.GroupByKey"))
.apply(Keys.create());
PAssert.that(output).containsInAnyOrder("A", "B");
}

@Test
@Category({ValidatesRunner.class, UsesPythonExpansionService.class})
public void pythonTransformWithDependencies() {
PCollection<String> output =
testPipeline
.apply(Create.of("elephant", "mouse", "sheep"))
.apply(
PythonExternalTransform.<PCollection<String>, PCollection<String>>from(
"apache_beam.Map")
.withArgs(PythonCallableSource.of("import inflection\ninflection.pluralize"))
.withExtraPackages(ImmutableList.of("inflection"))
.withOutputCoder(StringUtf8Coder.of()));
PAssert.that(output).containsInAnyOrder("elephants", "mice", "sheep");
}
}

@Test
Expand Down
Loading