-
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
Changes from 3 commits
8586259
6bb83d5
45e442c
1a352fe
33e1788
50f32b6
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 |
|---|---|---|
| @@ -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 4.0.0 | ||
cloud-fan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public enum TableWritePrivilege { | ||
|
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. I only include write privileges as the full privileges include ALTER, REFERENCE, etc, which is not what we need for |
||
| /** | ||
| * 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 | ||
| } | ||
| 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, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.