-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-22405][SQL] Add new alter table and alter database related ExternalCatalogEvent #19649
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,7 +87,14 @@ abstract class ExternalCatalog | |
| * Note: If the underlying implementation does not support altering a certain field, | ||
| * this becomes a no-op. | ||
| */ | ||
| def alterDatabase(dbDefinition: CatalogDatabase): Unit | ||
| final def alterDatabase(dbDefinition: CatalogDatabase): Unit = { | ||
| val db = dbDefinition.name | ||
| postToAll(AlterDatabasePreEvent(db)) | ||
| doAlterDatabase(dbDefinition) | ||
| postToAll(AlterDatabaseEvent(db)) | ||
| } | ||
|
|
||
| protected def doAlterDatabase(dbDefinition: CatalogDatabase): Unit | ||
|
|
||
| def getDatabase(db: String): CatalogDatabase | ||
|
|
||
|
|
@@ -147,7 +154,15 @@ abstract class ExternalCatalog | |
| * Note: If the underlying implementation does not support altering a certain field, | ||
| * this becomes a no-op. | ||
| */ | ||
| def alterTable(tableDefinition: CatalogTable): Unit | ||
| final def alterTable(tableDefinition: CatalogTable): Unit = { | ||
| val db = tableDefinition.database | ||
| val name = tableDefinition.identifier.table | ||
| postToAll(AlterTablePreEvent(db, name, AlterTableKind.TABLE)) | ||
| doAlterTable(tableDefinition) | ||
| postToAll(AlterTableEvent(db, name, AlterTableKind.TABLE)) | ||
| } | ||
|
|
||
| protected def doAlterTable(tableDefinition: CatalogTable): Unit | ||
|
|
||
| /** | ||
| * Alter the data schema of a table identified by the provided database and table name. The new | ||
|
|
@@ -158,10 +173,22 @@ abstract class ExternalCatalog | |
| * @param table Name of table to alter schema for | ||
| * @param newDataSchema Updated data schema to be used for the table. | ||
| */ | ||
| def alterTableDataSchema(db: String, table: String, newDataSchema: StructType): Unit | ||
| final def alterTableDataSchema(db: String, table: String, newDataSchema: StructType): Unit = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about |
||
| postToAll(AlterTablePreEvent(db, table, AlterTableKind.DATASCHEMA)) | ||
| doAlterTableDataSchema(db, table, newDataSchema) | ||
| postToAll(AlterTableEvent(db, table, AlterTableKind.DATASCHEMA)) | ||
| } | ||
|
|
||
| protected def doAlterTableDataSchema(db: String, table: String, newDataSchema: StructType): Unit | ||
|
|
||
| /** Alter the statistics of a table. If `stats` is None, then remove all existing statistics. */ | ||
| def alterTableStats(db: String, table: String, stats: Option[CatalogStatistics]): Unit | ||
| final def alterTableStats(db: String, table: String, stats: Option[CatalogStatistics]): Unit = { | ||
| postToAll(AlterTablePreEvent(db, table, AlterTableKind.STATS)) | ||
| doAlterTableStats(db, table, stats) | ||
| postToAll(AlterTableEvent(db, table, AlterTableKind.STATS)) | ||
| } | ||
|
|
||
| protected def doAlterTableStats(db: String, table: String, stats: Option[CatalogStatistics]): Unit | ||
|
|
||
| def getTable(db: String, table: String): CatalogTable | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,16 @@ case class DropDatabasePreEvent(database: String) extends DatabaseEvent | |
| */ | ||
| case class DropDatabaseEvent(database: String) extends DatabaseEvent | ||
|
|
||
| /** | ||
| * Event fired before a database is altered. | ||
| */ | ||
| case class AlterDatabasePreEvent(database: String) extends DatabaseEvent | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @jerryshao .
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I will update the title. |
||
|
|
||
| /** | ||
| * Event fired after a database is altered. | ||
| */ | ||
| case class AlterDatabaseEvent(database: String) extends DatabaseEvent | ||
|
|
||
| /** | ||
| * Event fired when a table is created, dropped or renamed. | ||
| */ | ||
|
|
@@ -110,7 +120,33 @@ case class RenameTableEvent( | |
| extends TableEvent | ||
|
|
||
| /** | ||
| * Event fired when a function is created, dropped or renamed. | ||
| * String to indicate which part of table is altered. If a plain alterTable API is called, then | ||
| * type will generally be Table. | ||
| */ | ||
| object AlterTableKind extends Enumeration { | ||
| val TABLE = "table" | ||
| val DATASCHEMA = "dataSchema" | ||
| val STATS = "stats" | ||
| } | ||
|
|
||
| /** | ||
| * Event fired before a table is altered. | ||
| */ | ||
| case class AlterTablePreEvent( | ||
| database: String, | ||
| name: String, | ||
| kind: String) extends TableEvent | ||
|
|
||
| /** | ||
| * Event fired after a table is altered. | ||
| */ | ||
| case class AlterTableEvent( | ||
| database: String, | ||
| name: String, | ||
| kind: String) extends TableEvent | ||
|
|
||
| /** | ||
| * Event fired when a function is created, dropped, altered or renamed. | ||
| */ | ||
| trait FunctionEvent extends DatabaseEvent { | ||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest we leave it for now and watch other
alterTableXXXevents instead. I feel it's an overkill to have a heavyalterTablemethod to handling all table metadata updating, I think we will add more and more fine-grained alter table methods in the future, likealterTableStats,alterTableDataSchema, etc. and eventually thisalterTablemethod will go away.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depends on which level of details we wanna collect in the event. Are there any guidelines or documentation of what events spark should monitor?
Besides, partition changes are missing, I think it's necessary to monitor these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cloud-fan , since now we expose
alterTableinterface for other components to leverage, if we don't track this, then looks like we missed a piece ofExternalCatalogEvents. I think for now we can add thisAlterTableEvent, later on if we removed this method, then we can make this event a no-op (only kept for compatibility), what do you think?@wzhfy , I was thinking to add partition related events, but I'm not clearly sure why this whole piece is missing and is it necessary to add partition related events? If we have an agreement on such events, I'm OK to add them.