Skip to content

Commit 3c6198c

Browse files
cloud-fangatorsmile
authored andcommitted
[SPARK-21987][SQL] fix a compatibility issue of sql event logs
## What changes were proposed in this pull request? In apache#18600 we removed the `metadata` field from `SparkPlanInfo`. This causes a problem when we replay event logs that are generated by older Spark versions. ## How was this patch tested? a regression test. Author: Wenchen Fan <[email protected]> Closes apache#19237 from cloud-fan/event.
1 parent 4decedf commit 3c6198c

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlanInfo.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.spark.sql.execution
1919

20+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
21+
2022
import org.apache.spark.annotation.DeveloperApi
2123
import org.apache.spark.sql.execution.exchange.ReusedExchangeExec
2224
import org.apache.spark.sql.execution.metric.SQLMetricInfo
@@ -26,6 +28,7 @@ import org.apache.spark.sql.execution.metric.SQLMetricInfo
2628
* Stores information about a SQL SparkPlan.
2729
*/
2830
@DeveloperApi
31+
@JsonIgnoreProperties(Array("metadata")) // The metadata field was removed in Spark 2.3.
2932
class SparkPlanInfo(
3033
val nodeName: String,
3134
val simpleString: String,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.sql.execution
19+
20+
import org.json4s.jackson.JsonMethods.parse
21+
22+
import org.apache.spark.SparkFunSuite
23+
import org.apache.spark.sql.execution.ui.SparkListenerSQLExecutionStart
24+
import org.apache.spark.util.JsonProtocol
25+
26+
class SQLJsonProtocolSuite extends SparkFunSuite {
27+
28+
test("SparkPlanGraph backward compatibility: metadata") {
29+
val SQLExecutionStartJsonString =
30+
"""
31+
|{
32+
| "Event":"org.apache.spark.sql.execution.ui.SparkListenerSQLExecutionStart",
33+
| "executionId":0,
34+
| "description":"test desc",
35+
| "details":"test detail",
36+
| "physicalPlanDescription":"test plan",
37+
| "sparkPlanInfo": {
38+
| "nodeName":"TestNode",
39+
| "simpleString":"test string",
40+
| "children":[],
41+
| "metadata":{},
42+
| "metrics":[]
43+
| },
44+
| "time":0
45+
|}
46+
""".stripMargin
47+
val reconstructedEvent = JsonProtocol.sparkEventFromJson(parse(SQLExecutionStartJsonString))
48+
val expectedEvent = SparkListenerSQLExecutionStart(0, "test desc", "test detail", "test plan",
49+
new SparkPlanInfo("TestNode", "test string", Nil, Nil), 0)
50+
assert(reconstructedEvent == expectedEvent)
51+
}
52+
}

0 commit comments

Comments
 (0)