-
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.
Optimized SparkRunner ParDo Operation (#32546)
* Optimize to skip filter application when there is only a single output * Make SparkTransformOverrides class public for testing * add related test * Touch trigger files * add CHANGES.md
- Loading branch information
Showing
10 changed files
with
333 additions
and
14 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
.github/trigger_files/beam_PostCommit_Java_ValidatesRunner_Spark.json
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"comment": "Modify this file in a trivial way to cause this test suite to run", | ||
"https://github.com/apache/beam/pull/31156": "noting that PR #31156 should run this test", | ||
"https://github.com/apache/beam/pull/31798": "noting that PR #31798 should run this test" | ||
"https://github.com/apache/beam/pull/31798": "noting that PR #31798 should run this test", | ||
"https://github.com/apache/beam/pull/32546": "noting that PR #32546 should run this test" | ||
} |
3 changes: 2 additions & 1 deletion
3
.github/trigger_files/beam_PostCommit_Java_ValidatesRunner_SparkStructuredStreaming.json
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"comment": "Modify this file in a trivial way to cause this test suite to run", | ||
"https://github.com/apache/beam/pull/31156": "noting that PR #31156 should run this test", | ||
"https://github.com/apache/beam/pull/31798": "noting that PR #31798 should run this test" | ||
"https://github.com/apache/beam/pull/31798": "noting that PR #31798 should run this test", | ||
"https://github.com/apache/beam/pull/32546": "noting that PR #32546 should run this test" | ||
} |
3 changes: 2 additions & 1 deletion
3
.github/trigger_files/beam_PostCommit_Java_ValidatesRunner_Spark_Java11.json
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"comment": "Modify this file in a trivial way to cause this test suite to run", | ||
"https://github.com/apache/beam/pull/31156": "noting that PR #31156 should run this test", | ||
"https://github.com/apache/beam/pull/31798": "noting that PR #31798 should run this test" | ||
"https://github.com/apache/beam/pull/31798": "noting that PR #31798 should run this test", | ||
"https://github.com/apache/beam/pull/32546": "noting that PR #32546 should run this test" | ||
} |
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
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
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
91 changes: 91 additions & 0 deletions
91
runners/spark/src/test/java/org/apache/beam/runners/spark/translation/PassThrough.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,91 @@ | ||
/* | ||
* 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.spark.translation; | ||
|
||
import org.apache.beam.sdk.coders.Coder; | ||
import org.apache.beam.sdk.transforms.DoFn; | ||
import org.apache.beam.sdk.transforms.PTransform; | ||
import org.apache.beam.sdk.transforms.ParDo; | ||
import org.apache.beam.sdk.values.PCollection; | ||
import org.apache.beam.sdk.values.PCollectionTuple; | ||
import org.apache.beam.sdk.values.TupleTag; | ||
import org.apache.beam.sdk.values.TupleTagList; | ||
|
||
public class PassThrough { | ||
|
||
public static <InputT> SingleOutput<InputT> ofSingleOutput(Coder<InputT> inputCoder) { | ||
return new SingleOutput<>(inputCoder); | ||
} | ||
|
||
public static <InputT> MultipleOutput<InputT> ofMultipleOutput( | ||
TupleTag<InputT> tag1, TupleTag<InputT> tag2) { | ||
return new MultipleOutput<>(tag1, tag2); | ||
} | ||
|
||
public static class SingleOutput<InputT> | ||
extends PTransform<PCollection<InputT>, PCollection<InputT>> { | ||
private final Coder<InputT> inputCoder; | ||
|
||
public SingleOutput(Coder<InputT> inputCoder) { | ||
this.inputCoder = inputCoder; | ||
} | ||
|
||
@Override | ||
public PCollection<InputT> expand(PCollection<InputT> input) { | ||
return input | ||
.apply( | ||
ParDo.of( | ||
new DoFn<InputT, InputT>() { | ||
@ProcessElement | ||
public void process(@Element InputT input, OutputReceiver<InputT> output) { | ||
output.output(input); | ||
} | ||
})) | ||
.setCoder(inputCoder); | ||
} | ||
} | ||
|
||
public static class MultipleOutput<InputT> | ||
extends PTransform<PCollection<InputT>, PCollectionTuple> { | ||
|
||
private final TupleTag<InputT> tag1; | ||
private final TupleTag<InputT> tag2; | ||
|
||
public MultipleOutput(TupleTag<InputT> tag1, TupleTag<InputT> tag2) { | ||
this.tag1 = tag1; | ||
this.tag2 = tag2; | ||
} | ||
|
||
@Override | ||
public PCollectionTuple expand(PCollection<InputT> input) { | ||
return input.apply( | ||
ParDo.of( | ||
new DoFn<InputT, InputT>() { | ||
@ProcessElement | ||
public void process(@Element InputT input, MultiOutputReceiver output) { | ||
if (input.hashCode() % 2 == 0) { | ||
output.get(tag1).output(input); | ||
} else { | ||
output.get(tag2).output(input); | ||
} | ||
} | ||
}) | ||
.withOutputTags(tag1, TupleTagList.of(tag2))); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
runners/spark/src/test/java/org/apache/beam/runners/spark/translation/RDDNode.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,65 @@ | ||
/* | ||
* 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.spark.translation; | ||
|
||
class RDDNode { | ||
private final int id; | ||
private final String name; | ||
private final String operator; | ||
private final String location; | ||
|
||
public RDDNode(int id, String name, String operator, String location) { | ||
this.id = id; | ||
this.name = name; | ||
this.operator = operator; | ||
this.location = location; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getOperator() { | ||
return operator; | ||
} | ||
|
||
public String getLocation() { | ||
return location; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RDDNode{" | ||
+ "id=" | ||
+ id | ||
+ ", name='" | ||
+ name | ||
+ '\'' | ||
+ ", operator='" | ||
+ operator | ||
+ '\'' | ||
+ ", location='" | ||
+ location | ||
+ '\'' | ||
+ '}'; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
runners/spark/src/test/java/org/apache/beam/runners/spark/translation/RDDTreeParser.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,55 @@ | ||
/* | ||
* 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.spark.translation; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** Utility class for parsing RDD Debug String. */ | ||
@SuppressWarnings("StringSplitter") | ||
class RDDTreeParser { | ||
|
||
public static List<RDDNode> parse(String debugString) { | ||
List<RDDNode> list = new ArrayList<>(); | ||
String[] lines = debugString.split("\n"); | ||
|
||
for (String line : lines) { | ||
line = line.trim(); | ||
if (line.isEmpty()) { | ||
continue; | ||
} | ||
|
||
int id = extractId(line); | ||
final String[] parsedString = line.replace("|", "").split(" at "); | ||
String name = parsedString[0].replaceAll("[+\\-]", "").replaceAll("\\(\\d+\\)", "").trim(); | ||
String operation = parsedString[1].trim(); | ||
String location = parsedString[2].trim(); | ||
|
||
RDDNode node = new RDDNode(id, name, operation, location); | ||
|
||
list.add(node); | ||
} | ||
|
||
return list; | ||
} | ||
|
||
private static int extractId(String line) { | ||
String idPart = line.substring(line.indexOf('[') + 1, line.indexOf(']')); | ||
return Integer.parseInt(idPart); | ||
} | ||
} |
Oops, something went wrong.