-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
learning+website: add
Tee
to java catalog
Signed-off-by: Mohamed Awnallah <[email protected]>
- Loading branch information
1 parent
41aea91
commit fa580e9
Showing
8 changed files
with
217 additions
and
1 deletion.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...a/Core Transforms/Tee/Tee/src/org/apache/beam/learning/katas/coretransforms/tee/Task.java
This file contains 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,41 @@ | ||
package org.apache.beam.learning.katas.coretransforms.tee; | ||
|
||
import org.apache.beam.learning.katas.util.Log; | ||
import org.apache.beam.sdk.Pipeline; | ||
import org.apache.beam.sdk.options.PipelineOptions; | ||
import org.apache.beam.sdk.options.PipelineOptionsFactory; | ||
import org.apache.beam.sdk.transforms.*; | ||
import org.apache.beam.sdk.values.PCollection; | ||
|
||
public class Task { | ||
public static void main(String[] args) { | ||
PipelineOptions options = PipelineOptionsFactory.fromArgs(args).create(); | ||
Pipeline pipeline = Pipeline.create(options); | ||
|
||
PCollection<Integer> inputData = pipeline.apply("Create Input", Create.of(1, 2, 3, 4, 5)); | ||
|
||
PCollection<Integer> output = applyTransform(inputData); | ||
|
||
output.apply(Log.ofElements()); | ||
|
||
pipeline.run(); | ||
} | ||
|
||
|
||
static PCollection<Integer> applyTransform(PCollection<Integer> data) { | ||
Tee<Integer> tee = Tee.of( | ||
consumer -> { | ||
consumer.apply("Filter Even", Filter.by((Integer x) -> x % 2 == 0)); | ||
consumer.apply("Filter Odd", Filter.by((Integer x) -> x % 2 != 0)); | ||
} | ||
); | ||
return data | ||
.apply("Tee Operations", tee) | ||
.apply("Continue Pipeline", MapElements.via(new SimpleFunction<Integer, Integer>() { | ||
@Override | ||
public Integer apply(Integer input) { | ||
return input * 10; | ||
} | ||
})); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
learning/katas/java/Core Transforms/Tee/Tee/task-info.yaml
This file contains 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,29 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
type: edu | ||
files: | ||
- name: src/org/apache/beam/learning/katas/coretransforms/tee/Task.java | ||
visible: true | ||
placeholders: | ||
- offset: 2294 | ||
length: 85 | ||
placeholder_text: TODO() | ||
- name: test/org/apache/beam/learning/katas/coretransforms/tee/TaskTest.java | ||
visible: false |
This file contains 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,39 @@ | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
Tee | ||
------- | ||
|
||
Tee is a Beam transform that allows for splitting the pipeline flow into | ||
multiple branches while preserving the main pipeline. It is similar to the Unix | ||
`tee` command, which outputs data to multiple destinations. | ||
|
||
**Kata:** Implement a | ||
[tee](https://beam.apache.org/releases/javadoc/current/org/apache/beam/sdk/transforms/Tee.html) | ||
transform that applies side transformations to a PCollection without breaking the linear flow of the main pipeline. | ||
|
||
<div class="hint"> | ||
Refer to <a href="https://beam.apache.org/releases/javadoc/current/org/apache/beam/sdk/transforms/Tee.html"> | ||
Tee</a> to solve this problem. | ||
</div> | ||
|
||
<div class="hint"> | ||
Refer to the Beam Programming Guide | ||
<a href="https://beam.apache.org/documentation/programming-guide/#tee"> | ||
"Tee"</a> section for more information. | ||
</div> |
45 changes: 45 additions & 0 deletions
45
...e Transforms/Tee/Tee/test/org/apache/beam/learning/katas/coretransforms/tee/TaskTest.java
This file contains 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,45 @@ | ||
/* | ||
* 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.learning.katas.coretransforms.tee; | ||
|
||
import org.apache.beam.sdk.testing.PAssert; | ||
import org.apache.beam.sdk.testing.TestPipeline; | ||
import org.apache.beam.sdk.transforms.Create; | ||
import org.apache.beam.sdk.values.PCollection; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class TaskTest { | ||
|
||
@Rule | ||
public final transient TestPipeline testPipeline = TestPipeline.create(); | ||
|
||
@Test | ||
public void tee() { | ||
PCollection<Integer> inputData = testPipeline.apply("Create Input", Create.of(1, 2, 3, 4, 5)); | ||
|
||
PCollection<Integer> results = Task.applyTransform(inputData); | ||
|
||
PAssert.that(results) | ||
.containsInAnyOrder(10, 20, 30, 40, 50); | ||
|
||
testPipeline.run().waitUntilFinish(); | ||
} | ||
|
||
} |
This file contains 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,21 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
content: | ||
- Tee |
This file contains 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 |
---|---|---|
|
@@ -29,3 +29,4 @@ content: | |
- Branching | ||
- Composite Transform | ||
- DoFn Additional Parameters | ||
- Tee |
This file contains 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
40 changes: 40 additions & 0 deletions
40
website/www/site/content/en/documentation/transforms/java/other/tee.md
This file contains 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,40 @@ | ||
--- | ||
title: "Tee" | ||
--- | ||
<!-- | ||
Licensed 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. | ||
--> | ||
# Tee | ||
<table align="left"> | ||
<a target="_blank" class="button" | ||
href="https://beam.apache.org/releases/javadoc/current/index.html?org/apache/beam/sdk/transforms/Tee.html"> | ||
<img src="/images/logos/sdks/java.png" width="20px" height="20px" | ||
alt="Javadoc" /> | ||
Javadoc | ||
</a> | ||
</table> | ||
<br><br> | ||
|
||
|
||
The `Tee` transform allows for splitting the pipeline flow into multiple branches, | ||
enabling the application of side transformations while preserving the main pipeline. | ||
This is similar to the Unix `tee` command, which duplicates input and sends it to | ||
multiple outputs without interrupting the main flow. | ||
|
||
See more information in the [Beam Programming Guide](/documentation/programming-guide/#tee). | ||
|
||
## Examples | ||
|
||
{{< playground height="700px" >}} | ||
{{< playground_snippet language="java" path="PG_BEAMDOC_SDK_JAVA_Tee" show="main_section" >}} | ||
{{< /playground >}} |