-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-20420][SQL] Add events to the external catalog
## What changes were proposed in this pull request? It is often useful to be able to track changes to the `ExternalCatalog`. This PR makes the `ExternalCatalog` emit events when a catalog object is changed. Events are fired before and after the change. The following events are fired per object: - Database - CreateDatabasePreEvent: event fired before the database is created. - CreateDatabaseEvent: event fired after the database has been created. - DropDatabasePreEvent: event fired before the database is dropped. - DropDatabaseEvent: event fired after the database has been dropped. - Table - CreateTablePreEvent: event fired before the table is created. - CreateTableEvent: event fired after the table has been created. - RenameTablePreEvent: event fired before the table is renamed. - RenameTableEvent: event fired after the table has been renamed. - DropTablePreEvent: event fired before the table is dropped. - DropTableEvent: event fired after the table has been dropped. - Function - CreateFunctionPreEvent: event fired before the function is created. - CreateFunctionEvent: event fired after the function has been created. - RenameFunctionPreEvent: event fired before the function is renamed. - RenameFunctionEvent: event fired after the function has been renamed. - DropFunctionPreEvent: event fired before the function is dropped. - DropFunctionPreEvent: event fired after the function has been dropped. The current events currently only contain the names of the object modified. We add more events, and more details at a later point. A user can monitor changes to the external catalog by adding a listener to the Spark listener bus checking for `ExternalCatalogEvent`s using the `SparkListener.onOtherEvent` hook. A more direct approach is add listener directly to the `ExternalCatalog`. ## How was this patch tested? Added the `ExternalCatalogEventSuite`. Author: Herman van Hovell <[email protected]> Closes #17710 from hvanhovell/SPARK-20420.
- Loading branch information
1 parent
48d760d
commit e2b3d23
Showing
6 changed files
with
457 additions
and
25 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
158 changes: 158 additions & 0 deletions
158
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/events.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,158 @@ | ||
/* | ||
* 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.catalyst.catalog | ||
|
||
import org.apache.spark.scheduler.SparkListenerEvent | ||
|
||
/** | ||
* Event emitted by the external catalog when it is modified. Events are either fired before or | ||
* after the modification (the event should document this). | ||
*/ | ||
trait ExternalCatalogEvent extends SparkListenerEvent | ||
|
||
/** | ||
* Listener interface for external catalog modification events. | ||
*/ | ||
trait ExternalCatalogEventListener { | ||
def onEvent(event: ExternalCatalogEvent): Unit | ||
} | ||
|
||
/** | ||
* Event fired when a database is create or dropped. | ||
*/ | ||
trait DatabaseEvent extends ExternalCatalogEvent { | ||
/** | ||
* Database of the object that was touched. | ||
*/ | ||
val database: String | ||
} | ||
|
||
/** | ||
* Event fired before a database is created. | ||
*/ | ||
case class CreateDatabasePreEvent(database: String) extends DatabaseEvent | ||
|
||
/** | ||
* Event fired after a database has been created. | ||
*/ | ||
case class CreateDatabaseEvent(database: String) extends DatabaseEvent | ||
|
||
/** | ||
* Event fired before a database is dropped. | ||
*/ | ||
case class DropDatabasePreEvent(database: String) extends DatabaseEvent | ||
|
||
/** | ||
* Event fired after a database has been dropped. | ||
*/ | ||
case class DropDatabaseEvent(database: String) extends DatabaseEvent | ||
|
||
/** | ||
* Event fired when a table is created, dropped or renamed. | ||
*/ | ||
trait TableEvent extends DatabaseEvent { | ||
/** | ||
* Name of the table that was touched. | ||
*/ | ||
val name: String | ||
} | ||
|
||
/** | ||
* Event fired before a table is created. | ||
*/ | ||
case class CreateTablePreEvent(database: String, name: String) extends TableEvent | ||
|
||
/** | ||
* Event fired after a table has been created. | ||
*/ | ||
case class CreateTableEvent(database: String, name: String) extends TableEvent | ||
|
||
/** | ||
* Event fired before a table is dropped. | ||
*/ | ||
case class DropTablePreEvent(database: String, name: String) extends TableEvent | ||
|
||
/** | ||
* Event fired after a table has been dropped. | ||
*/ | ||
case class DropTableEvent(database: String, name: String) extends TableEvent | ||
|
||
/** | ||
* Event fired before a table is renamed. | ||
*/ | ||
case class RenameTablePreEvent( | ||
database: String, | ||
name: String, | ||
newName: String) | ||
extends TableEvent | ||
|
||
/** | ||
* Event fired after a table has been renamed. | ||
*/ | ||
case class RenameTableEvent( | ||
database: String, | ||
name: String, | ||
newName: String) | ||
extends TableEvent | ||
|
||
/** | ||
* Event fired when a function is created, dropped or renamed. | ||
*/ | ||
trait FunctionEvent extends DatabaseEvent { | ||
/** | ||
* Name of the function that was touched. | ||
*/ | ||
val name: String | ||
} | ||
|
||
/** | ||
* Event fired before a function is created. | ||
*/ | ||
case class CreateFunctionPreEvent(database: String, name: String) extends FunctionEvent | ||
|
||
/** | ||
* Event fired after a function has been created. | ||
*/ | ||
case class CreateFunctionEvent(database: String, name: String) extends FunctionEvent | ||
|
||
/** | ||
* Event fired before a function is dropped. | ||
*/ | ||
case class DropFunctionPreEvent(database: String, name: String) extends FunctionEvent | ||
|
||
/** | ||
* Event fired after a function has been dropped. | ||
*/ | ||
case class DropFunctionEvent(database: String, name: String) extends FunctionEvent | ||
|
||
/** | ||
* Event fired before a function is renamed. | ||
*/ | ||
case class RenameFunctionPreEvent( | ||
database: String, | ||
name: String, | ||
newName: String) | ||
extends FunctionEvent | ||
|
||
/** | ||
* Event fired after a function has been renamed. | ||
*/ | ||
case class RenameFunctionEvent( | ||
database: String, | ||
name: String, | ||
newName: String) | ||
extends FunctionEvent |
Oops, something went wrong.