-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-41432][UI][SQL] Protobuf serializer for SparkPlanGraphWrapper #39164
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
Closed
techaddict
wants to merge
17
commits into
apache:master
from
techaddict:SPARK-41432-SparkPlanGraphWrapper
Closed
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
743cd10
[SPARK-41432][UI][SQL] Protobuf serializer for SparkPlanGraphWrapper
techaddict 4e6f9b2
Merge branch 'master' into SPARK-41432-SparkPlanGraphWrapper
techaddict 25b63fa
add mvn and sbt config
techaddict 558ad23
Address comments
techaddict 0f9f767
Merge branch 'master' into SPARK-41432-SparkPlanGraphWrapper
techaddict f9b0c13
address comments
techaddict 72e658a
add tests
techaddict c721cca
fix name/desc
techaddict 98e0ebb
Merge branch 'master' into SPARK-41432-SparkPlanGraphWrapper
techaddict ab51bef
fix maven build
techaddict a34dd22
Merge branch 'master' into SPARK-41432-SparkPlanGraphWrapper
techaddict 49ef0ed
Merge remote-tracking branch 'upstream/master' into SPARK-41432-Spark…
techaddict ce8621d
reuse SQLPlanMetricSerializer
techaddict 4a8e9d3
Merge branch 'master' into SPARK-41432-SparkPlanGraphWrapper
techaddict f8ffa42
Merge branch 'master' into SPARK-41432-SparkPlanGraphWrapper
techaddict 7c0d6be
fix imports
techaddict 29c4ef4
address comment
techaddict 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
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
152 changes: 152 additions & 0 deletions
152
...src/main/scala/org/apache/spark/status/protobuf/sql/SparkPlanGraphWrapperSerializer.scala
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,152 @@ | ||
| /* | ||
| * 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.spark.status.protobuf.sql | ||
|
|
||
| import collection.JavaConverters._ | ||
|
|
||
| import org.apache.spark.sql.execution.ui.{SparkPlanGraphClusterWrapper, SparkPlanGraphEdge, SparkPlanGraphNode, SparkPlanGraphNodeWrapper, SparkPlanGraphWrapper, SQLPlanMetric} | ||
| import org.apache.spark.status.protobuf.ProtobufSerDe | ||
| import org.apache.spark.status.protobuf.StoreTypes | ||
|
|
||
| class SparkPlanGraphWrapperSerializer extends ProtobufSerDe { | ||
|
|
||
| override val supportClass: Class[_] = classOf[SparkPlanGraphWrapper] | ||
|
|
||
| override def serialize(input: Any): Array[Byte] = | ||
| serialize(input.asInstanceOf[SparkPlanGraphWrapper]) | ||
|
|
||
| private def serialize(plan: SparkPlanGraphWrapper): Array[Byte] = { | ||
| val builder = StoreTypes.SparkPlanGraphWrapper.newBuilder() | ||
| builder.setExecutionId(plan.executionId) | ||
| plan.nodes.foreach { node => | ||
| builder.addNodes(serializeSparkPlanGraphNodeWrapper(node)) | ||
| } | ||
| plan.edges.foreach {edge => | ||
| builder.addEdges(serializeSparkPlanGraphEdge(edge)) | ||
| } | ||
| builder.build().toByteArray | ||
| } | ||
|
|
||
| def deserialize(bytes: Array[Byte]): SparkPlanGraphWrapper = { | ||
| val wrapper = StoreTypes.SparkPlanGraphWrapper.parseFrom(bytes) | ||
| new SparkPlanGraphWrapper( | ||
| executionId = wrapper.getExecutionId, | ||
| nodes = wrapper.getNodesList.asScala.map(deserializeSparkPlanGraphNodeWrapper).toSeq, | ||
| edges = wrapper.getEdgesList.asScala.map(deserializeSparkPlanGraphEdge).toSeq | ||
| ) | ||
| } | ||
|
|
||
| private def serializeSparkPlanGraphNodeWrapper(input: SparkPlanGraphNodeWrapper): | ||
| StoreTypes.SparkPlanGraphNodeWrapper = { | ||
|
|
||
| val builder = StoreTypes.SparkPlanGraphNodeWrapper.newBuilder() | ||
| builder.setNode(serializeSparkPlanGraphNode(input.node)) | ||
| builder.setCluster(serializeSparkPlanGraphClusterWrapper(input.cluster)) | ||
| builder.build() | ||
| } | ||
|
|
||
| private def deserializeSparkPlanGraphNodeWrapper(input: StoreTypes.SparkPlanGraphNodeWrapper): | ||
| SparkPlanGraphNodeWrapper = { | ||
|
|
||
| new SparkPlanGraphNodeWrapper( | ||
| node = deserializeSparkPlanGraphNode(input.getNode), | ||
| cluster = deserializeSparkPlanGraphClusterWrapper(input.getCluster) | ||
| ) | ||
| } | ||
|
|
||
| private def serializeSparkPlanGraphEdge(edge: SparkPlanGraphEdge): | ||
| StoreTypes.SparkPlanGraphEdge = { | ||
| val builder = StoreTypes.SparkPlanGraphEdge.newBuilder() | ||
| builder.setFromId(edge.fromId) | ||
| builder.setToId(edge.toId) | ||
| builder.build() | ||
| } | ||
|
|
||
| private def deserializeSparkPlanGraphEdge(edge: StoreTypes.SparkPlanGraphEdge): | ||
| SparkPlanGraphEdge = { | ||
| SparkPlanGraphEdge( | ||
| fromId = edge.getFromId, | ||
| toId = edge.getToId) | ||
| } | ||
|
|
||
| private def serializeSparkPlanGraphNode(node: SparkPlanGraphNode): | ||
| StoreTypes.SparkPlanGraphNode = { | ||
| val builder = StoreTypes.SparkPlanGraphNode.newBuilder() | ||
| builder.setId(node.id) | ||
| builder.setName(node.name) | ||
| builder.setDesc(node.desc) | ||
| node.metrics.foreach { metric => | ||
| builder.addMetrics(serializeSQLPlanMetric(metric)) | ||
| } | ||
| builder.build() | ||
| } | ||
|
|
||
| private def deserializeSparkPlanGraphNode(node: StoreTypes.SparkPlanGraphNode): | ||
| SparkPlanGraphNode = { | ||
|
|
||
| new SparkPlanGraphNode( | ||
| id = node.getId, | ||
| name = node.getName, | ||
| desc = node.getDesc, | ||
| metrics = node.getMetricsList.asScala.map(deserializeSQLPlanMetric).toSeq | ||
| ) | ||
| } | ||
|
|
||
| private def serializeSparkPlanGraphClusterWrapper(cluster: SparkPlanGraphClusterWrapper): | ||
| StoreTypes.SparkPlanGraphClusterWrapper = { | ||
| val builder = StoreTypes.SparkPlanGraphClusterWrapper.newBuilder() | ||
| builder.setId(cluster.id) | ||
| builder.setName(cluster.name) | ||
| builder.setDesc(cluster.desc) | ||
| cluster.nodes.foreach { node => | ||
| builder.addNodes(serializeSparkPlanGraphNodeWrapper(node)) | ||
| } | ||
| cluster.metrics.foreach { metric => | ||
| builder.addMetrics(serializeSQLPlanMetric(metric)) | ||
| } | ||
| builder.build() | ||
| } | ||
|
|
||
| private def deserializeSparkPlanGraphClusterWrapper( | ||
| cluster: StoreTypes.SparkPlanGraphClusterWrapper): SparkPlanGraphClusterWrapper = { | ||
|
|
||
| new SparkPlanGraphClusterWrapper( | ||
| id = cluster.getId, | ||
| name = cluster.getName, | ||
| desc = cluster.getDesc, | ||
| nodes = cluster.getNodesList.asScala.map(deserializeSparkPlanGraphNodeWrapper).toSeq, | ||
| metrics = cluster.getMetricsList.asScala.map(deserializeSQLPlanMetric).toSeq | ||
| ) | ||
| } | ||
|
|
||
| private def serializeSQLPlanMetric(metric: SQLPlanMetric): StoreTypes.SQLPlanMetric = { | ||
techaddict marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| val builder = StoreTypes.SQLPlanMetric.newBuilder() | ||
| builder.setName(metric.name) | ||
| builder.setAccumulatorId(metric.accumulatorId) | ||
| builder.setMetricType(metric.metricType) | ||
| builder.build() | ||
| } | ||
|
|
||
| private def deserializeSQLPlanMetric(metric: StoreTypes.SQLPlanMetric): SQLPlanMetric = { | ||
| SQLPlanMetric( | ||
| name = metric.getName, | ||
| accumulatorId = metric.getAccumulatorId, | ||
| metricType = metric.getMetricType | ||
| ) | ||
| } | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.