-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-49246][SQL] TableCatalog#loadTable should indicate if it's for writing #47772
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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8586259
loadTable should indicate if it's for writing
cloud-fan 6bb83d5
address comments
cloud-fan 45e442c
Merge remote-tracking branch 'origin/master' into write
cloud-fan 1a352fe
Apply suggestions from code review
cloud-fan 33e1788
Merge remote-tracking branch 'origin/master' into write
cloud-fan 50f32b6
Merge remote-tracking branch 'my/write' into write
cloud-fan 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
40 changes: 40 additions & 0 deletions
40
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableWritePrivilege.java
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,40 @@ | ||
| /* | ||
| * 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.connector.catalog; | ||
|
|
||
| /** | ||
| * The table write privileges that will be provided when loading a table. | ||
| * | ||
| * @since 3.5.3 | ||
| */ | ||
| public enum TableWritePrivilege { | ||
| /** | ||
| * The privilege for adding rows to the table. | ||
| */ | ||
| INSERT, | ||
|
|
||
| /** | ||
| * The privilege for changing existing rows in th table. | ||
| */ | ||
| UPDATE, | ||
|
|
||
| /** | ||
| * The privilege for deleting rows from the table. | ||
| */ | ||
| DELETE | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import org.apache.spark.sql.catalyst.plans.logical.{CTERelationDef, LeafNode, Lo | |
| import org.apache.spark.sql.catalyst.trees.TreePattern._ | ||
| import org.apache.spark.sql.catalyst.util._ | ||
| import org.apache.spark.sql.catalyst.util.TypeUtils.toSQLId | ||
| import org.apache.spark.sql.connector.catalog.TableWritePrivilege | ||
| import org.apache.spark.sql.errors.{QueryCompilationErrors, QueryExecutionErrors} | ||
| import org.apache.spark.sql.types.{DataType, Metadata, StructType} | ||
| import org.apache.spark.sql.util.CaseInsensitiveStringMap | ||
|
|
@@ -134,10 +135,36 @@ case class UnresolvedRelation( | |
|
|
||
| override def name: String = tableName | ||
|
|
||
| def requireWritePrivileges(privileges: Seq[TableWritePrivilege]): UnresolvedRelation = { | ||
| if (privileges.nonEmpty) { | ||
| val newOptions = new java.util.HashMap[String, String] | ||
| newOptions.putAll(options) | ||
| newOptions.put(UnresolvedRelation.REQUIRED_WRITE_PRIVILEGES, privileges.mkString(",")) | ||
| copy(options = new CaseInsensitiveStringMap(newOptions)) | ||
| } else { | ||
| this | ||
| } | ||
| } | ||
|
|
||
| def clearWritePrivileges: UnresolvedRelation = { | ||
| if (options.containsKey(UnresolvedRelation.REQUIRED_WRITE_PRIVILEGES)) { | ||
| val newOptions = new java.util.HashMap[String, String] | ||
| newOptions.putAll(options) | ||
| newOptions.remove(UnresolvedRelation.REQUIRED_WRITE_PRIVILEGES) | ||
| copy(options = new CaseInsensitiveStringMap(newOptions)) | ||
| } else { | ||
| this | ||
| } | ||
| } | ||
|
|
||
| final override val nodePatterns: Seq[TreePattern] = Seq(UNRESOLVED_RELATION) | ||
| } | ||
|
|
||
| object UnresolvedRelation { | ||
| // An internal option of `UnresolvedRelation` to specify the required write privileges when | ||
|
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. We can add a new field to |
||
| // writing data to this relation. | ||
| val REQUIRED_WRITE_PRIVILEGES = "__required_write_privileges__" | ||
|
|
||
| def apply( | ||
| tableIdentifier: TableIdentifier, | ||
| extraOptions: CaseInsensitiveStringMap, | ||
|
|
||
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
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
Oops, something went wrong.
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.
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 only include write privileges as the full privileges include ALTER, REFERENCE, etc, which is not what we need for
loadTable.