This repository has been archived by the owner on Jan 9, 2020. It is now read-only.
forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-19558][SQL] Add config key to register QueryExecutionListeners…
… automatically. This change adds a new SQL config key that is equivalent to SparkContext's "spark.extraListeners", allowing users to register QueryExecutionListener instances through the Spark configuration system instead of having to explicitly do it in code. The code used by SparkContext to implement the feature was refactored into a helper method in the Utils class, and SQL's ExecutionListenerManager was modified to use it to initialize listener declared in the configuration. Unit tests were added to verify all the new functionality. Author: Marcelo Vanzin <[email protected]> Closes apache#19309 from vanzin/SPARK-19558.
- Loading branch information
1 parent
bfc7e1f
commit bd4eb9c
Showing
9 changed files
with
216 additions
and
40 deletions.
There are no files selected for viewing
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
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
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
69 changes: 69 additions & 0 deletions
69
sql/core/src/test/scala/org/apache/spark/sql/util/ExecutionListenerManagerSuite.scala
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,69 @@ | ||
/* | ||
* 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.sql.util | ||
|
||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
import org.apache.spark._ | ||
import org.apache.spark.sql.execution.QueryExecution | ||
import org.apache.spark.sql.internal.StaticSQLConf._ | ||
|
||
class ExecutionListenerManagerSuite extends SparkFunSuite { | ||
|
||
import CountingQueryExecutionListener._ | ||
|
||
test("register query execution listeners using configuration") { | ||
val conf = new SparkConf(false) | ||
.set(QUERY_EXECUTION_LISTENERS, Seq(classOf[CountingQueryExecutionListener].getName())) | ||
|
||
val mgr = new ExecutionListenerManager(conf) | ||
assert(INSTANCE_COUNT.get() === 1) | ||
mgr.onSuccess(null, null, 42L) | ||
assert(CALLBACK_COUNT.get() === 1) | ||
|
||
val clone = mgr.clone() | ||
assert(INSTANCE_COUNT.get() === 1) | ||
|
||
clone.onSuccess(null, null, 42L) | ||
assert(CALLBACK_COUNT.get() === 2) | ||
} | ||
|
||
} | ||
|
||
private class CountingQueryExecutionListener extends QueryExecutionListener { | ||
|
||
import CountingQueryExecutionListener._ | ||
|
||
INSTANCE_COUNT.incrementAndGet() | ||
|
||
override def onSuccess(funcName: String, qe: QueryExecution, durationNs: Long): Unit = { | ||
CALLBACK_COUNT.incrementAndGet() | ||
} | ||
|
||
override def onFailure(funcName: String, qe: QueryExecution, exception: Exception): Unit = { | ||
CALLBACK_COUNT.incrementAndGet() | ||
} | ||
|
||
} | ||
|
||
private object CountingQueryExecutionListener { | ||
|
||
val CALLBACK_COUNT = new AtomicInteger() | ||
val INSTANCE_COUNT = new AtomicInteger() | ||
|
||
} |