-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Add DDL statements to drop branches and tags #23614
base: master
Are you sure you want to change the base?
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed 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 com.facebook.presto.execution; | ||
|
||
import com.facebook.presto.Session; | ||
import com.facebook.presto.common.QualifiedObjectName; | ||
import com.facebook.presto.metadata.Metadata; | ||
import com.facebook.presto.spi.ConnectorId; | ||
import com.facebook.presto.spi.MaterializedViewDefinition; | ||
import com.facebook.presto.spi.PrestoException; | ||
import com.facebook.presto.spi.TableHandle; | ||
import com.facebook.presto.spi.WarningCollector; | ||
import com.facebook.presto.spi.security.AccessControl; | ||
import com.facebook.presto.sql.analyzer.SemanticException; | ||
import com.facebook.presto.sql.tree.DropBranch; | ||
import com.facebook.presto.sql.tree.Expression; | ||
import com.facebook.presto.transaction.TransactionManager; | ||
import com.google.common.util.concurrent.ListenableFuture; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName; | ||
import static com.facebook.presto.spi.StandardErrorCode.NOT_FOUND; | ||
import static com.facebook.presto.sql.analyzer.SemanticErrorCode.MISSING_TABLE; | ||
import static com.facebook.presto.sql.analyzer.SemanticErrorCode.NOT_SUPPORTED; | ||
import static com.google.common.util.concurrent.Futures.immediateFuture; | ||
|
||
public class DropBranchTask | ||
implements DDLDefinitionTask<DropBranch> | ||
{ | ||
@Override | ||
public String getName() | ||
{ | ||
return "DROP BRANCH"; | ||
} | ||
|
||
@Override | ||
public ListenableFuture<?> execute(DropBranch statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) | ||
{ | ||
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName()); | ||
Optional<TableHandle> tableHandleOptional = metadata.getMetadataResolver(session).getTableHandle(tableName); | ||
|
||
if (!tableHandleOptional.isPresent()) { | ||
if (!statement.isTableExists()) { | ||
throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName); | ||
} | ||
return immediateFuture(null); | ||
} | ||
|
||
Optional<MaterializedViewDefinition> optionalMaterializedView = metadata.getMetadataResolver(session).getMaterializedView(tableName); | ||
if (optionalMaterializedView.isPresent()) { | ||
if (!statement.isTableExists()) { | ||
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. should we throw an error in cases when 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. Alternate way of handling this can be introducing an enum Type in DropBranch and have only TABLE as the supported type. |
||
throw new SemanticException(NOT_SUPPORTED, statement, "'%s' is a materialized view, and drop branch is not supported", tableName); | ||
} | ||
return immediateFuture(null); | ||
} | ||
|
||
ConnectorId connectorId = metadata.getCatalogHandle(session, tableName.getCatalogName()) | ||
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. nit: the variable connectorId is not getting used and can be removed. Also I have refactored and extracted this piece of code in MetadataUtil class in this commit - dec2952. |
||
.orElseThrow(() -> new PrestoException(NOT_FOUND, "Catalog does not exist: " + tableName.getCatalogName())); | ||
accessControl.checkCanDropBranch(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName); | ||
|
||
metadata.dropBranch(session, tableHandleOptional.get(), statement.getBranchName(), statement.isBranchExists()); | ||
return immediateFuture(null); | ||
} | ||
} |
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 wonder about the granularity of these methods. In other implementation (e.g. spark?) at what granularity do they enforce the ability to do CRUD operations on tags and branches?
I'm thinking about a few cases
I know we're only implementing
DROP
but I want to understand the whole story for access control around branches and tags. Would we ever need to pass the branch/tag to these methods?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 think the granularity of access control methods in Spark for CRUD operations on Iceberg tags and branches is limited by Spark's integration with external systems (such as file systems, catalogs, and security frameworks like Apache Ranger).
For example, Ranger policies can define access controls at the table level, which could be extended to manage specific branches or tag-based access.
And like for cloud-based catalogs like AWS Glue, you can control access to Iceberg metadata (branches and tags) via IAM policies that grant or restrict specific operations.
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.
Thanks for the info. Would the parameters passed here as context have enough information for us to act at a similar granularity? I don't see anything in the method parameters that contains the branch name which I assume we would need to perform access control at a similar level.
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 would like to discuss around this, Systems like Ranger can define access controls at the table level, column level. So in this case I think access of drop branch & tags could be table based. As per I can think of branch & tag level policies then has to be maintained on engine side if we introduce branch name / tag name in here?
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.
@tdcmeehan What do you think about access control for branches and tags? Would be based on the parent table itself or based on the tags/branches?
My thinking was that since no policies are enforced based on branch/tags via security frameworks, should this honor the same access policies as table? Or if we don't even need access control exposed for dropTag & dropBranch?