Skip to content

Commit 4cbfa16

Browse files
Add DROP TAG sql support
1 parent 6c9b548 commit 4cbfa16

File tree

36 files changed

+435
-2
lines changed

36 files changed

+435
-2
lines changed

presto-analyzer/src/main/java/com/facebook/presto/sql/analyzer/utils/StatementUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.facebook.presto.sql.tree.DropRole;
4242
import com.facebook.presto.sql.tree.DropSchema;
4343
import com.facebook.presto.sql.tree.DropTable;
44+
import com.facebook.presto.sql.tree.DropTag;
4445
import com.facebook.presto.sql.tree.DropView;
4546
import com.facebook.presto.sql.tree.Explain;
4647
import com.facebook.presto.sql.tree.Grant;
@@ -133,6 +134,7 @@ private StatementUtils() {}
133134
builder.put(DropColumn.class, QueryType.DATA_DEFINITION);
134135
builder.put(DropTable.class, QueryType.DATA_DEFINITION);
135136
builder.put(DropBranch.class, QueryType.DATA_DEFINITION);
137+
builder.put(DropTag.class, QueryType.DATA_DEFINITION);
136138
builder.put(DropConstraint.class, QueryType.DATA_DEFINITION);
137139
builder.put(AddConstraint.class, QueryType.DATA_DEFINITION);
138140
builder.put(AlterColumnNotNull.class, QueryType.DATA_DEFINITION);

presto-docs/src/main/sphinx/sql/alter-table.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Synopsis
1616
ALTER TABLE [ IF EXISTS ] name ALTER [ COLUMN ] column_name { SET | DROP } NOT NULL
1717
ALTER TABLE [ IF EXISTS ] name SET PROPERTIES (property_name=value, [, ...])
1818
ALTER TABLE [ IF EXISTS ] name DROP BRANCH [ IF EXISTS ] branch_name
19+
ALTER TABLE [ IF EXISTS ] name DROP TAG [ IF EXISTS ] tag_name
1920
2021
Description
2122
-----------
@@ -99,6 +100,10 @@ Drop branch ``branch1`` from the ``users`` table::
99100

100101
ALTER TABLE users DROP BRANCH 'branch1';
101102

103+
Drop tag ``tag1`` from the ``users`` table::
104+
105+
ALTER TABLE users DROP TAG 'tag1';
106+
102107
See Also
103108
--------
104109

presto-hive/src/main/java/com/facebook/presto/hive/security/LegacyAccessControl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ public void checkCanDropBranch(ConnectorTransactionHandle transactionHandle, Con
281281
{
282282
}
283283

284+
@Override
285+
public void checkCanDropTag(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName)
286+
{
287+
}
288+
284289
@Override
285290
public void checkCanDropConstraint(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName)
286291
{

presto-hive/src/main/java/com/facebook/presto/hive/security/SqlStandardAccessControl.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import static com.facebook.presto.spi.security.AccessDeniedException.denyDropRole;
7070
import static com.facebook.presto.spi.security.AccessDeniedException.denyDropSchema;
7171
import static com.facebook.presto.spi.security.AccessDeniedException.denyDropTable;
72+
import static com.facebook.presto.spi.security.AccessDeniedException.denyDropTag;
7273
import static com.facebook.presto.spi.security.AccessDeniedException.denyDropView;
7374
import static com.facebook.presto.spi.security.AccessDeniedException.denyGrantRoles;
7475
import static com.facebook.presto.spi.security.AccessDeniedException.denyGrantTablePrivilege;
@@ -314,6 +315,24 @@ public void checkCanDropBranch(ConnectorTransactionHandle transaction, Connector
314315
}
315316
}
316317

318+
@Override
319+
public void checkCanDropTag(ConnectorTransactionHandle transaction, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName)
320+
{
321+
MetastoreContext metastoreContext = new MetastoreContext(
322+
identity, context.getQueryId().getId(),
323+
context.getClientInfo(),
324+
context.getClientTags(),
325+
context.getSource(),
326+
Optional.empty(),
327+
false,
328+
HiveColumnConverterProvider.DEFAULT_COLUMN_CONVERTER_PROVIDER,
329+
context.getWarningCollector(),
330+
context.getRuntimeStats());
331+
if (!isTableOwner(transaction, identity, metastoreContext, tableName)) {
332+
denyDropTag(tableName.toString());
333+
}
334+
}
335+
317336
@Override
318337
public void checkCanDropConstraint(ConnectorTransactionHandle transaction, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName)
319338
{

presto-hive/src/main/java/com/facebook/presto/hive/security/SystemTableAwareAccessControl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ public void checkCanDropBranch(ConnectorTransactionHandle transactionHandle, Con
263263
delegate.checkCanDropBranch(transactionHandle, identity, context, tableName);
264264
}
265265

266+
@Override
267+
public void checkCanDropTag(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName)
268+
{
269+
delegate.checkCanDropTag(transactionHandle, identity, context, tableName);
270+
}
271+
266272
@Override
267273
public void checkCanDropConstraint(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName)
268274
{

presto-main-base/src/main/java/com/facebook/presto/metadata/DelegatingMetadataManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,12 @@ public void dropBranch(Session session, TableHandle tableHandle, String branchNa
643643
delegate.dropBranch(session, tableHandle, branchName, branchExists);
644644
}
645645

646+
@Override
647+
public void dropTag(Session session, TableHandle tableHandle, String tagName, boolean tagExists)
648+
{
649+
delegate.dropTag(session, tableHandle, tagName, tagExists);
650+
}
651+
646652
@Override
647653
public void dropConstraint(Session session, TableHandle tableHandle, Optional<String> constraintName, Optional<String> columnName)
648654
{

presto-main-base/src/main/java/com/facebook/presto/metadata/Metadata.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ default TableLayoutFilterCoverage getTableLayoutFilterCoverage(Session session,
524524

525525
void dropBranch(Session session, TableHandle tableHandle, String branchName, boolean branchExists);
526526

527+
void dropTag(Session session, TableHandle tableHandle, String tagName, boolean tagExists);
528+
527529
void dropConstraint(Session session, TableHandle tableHandle, Optional<String> constraintName, Optional<String> columnName);
528530

529531
void addConstraint(Session session, TableHandle tableHandle, TableConstraint<String> tableConstraint);

presto-main-base/src/main/java/com/facebook/presto/metadata/MetadataManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,14 @@ public void dropBranch(Session session, TableHandle tableHandle, String branchNa
14711471
metadata.dropBranch(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle(), branchName, branchExists);
14721472
}
14731473

1474+
@Override
1475+
public void dropTag(Session session, TableHandle tableHandle, String tagName, boolean tagExists)
1476+
{
1477+
ConnectorId connectorId = tableHandle.getConnectorId();
1478+
ConnectorMetadata metadata = getMetadataForWrite(session, connectorId);
1479+
metadata.dropTag(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle(), tagName, tagExists);
1480+
}
1481+
14741482
@Override
14751483
public void dropConstraint(Session session, TableHandle tableHandle, Optional<String> constraintName, Optional<String> columnName)
14761484
{

presto-main-base/src/main/java/com/facebook/presto/security/AccessControlManager.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,22 @@ public void checkCanDropBranch(TransactionId transactionId, Identity identity, A
786786
}
787787
}
788788

789+
@Override
790+
public void checkCanDropTag(TransactionId transactionId, Identity identity, AccessControlContext context, QualifiedObjectName tableName)
791+
{
792+
requireNonNull(identity, "identity is null");
793+
requireNonNull(tableName, "tableName is null");
794+
795+
authenticationCheck(() -> checkCanAccessCatalog(identity, context, tableName.getCatalogName()));
796+
797+
authorizationCheck(() -> systemAccessControl.get().checkCanDropTag(identity, context, toCatalogSchemaTableName(tableName)));
798+
799+
CatalogAccessControlEntry entry = getConnectorAccessControl(transactionId, tableName.getCatalogName());
800+
if (entry != null) {
801+
authorizationCheck(() -> entry.getAccessControl().checkCanDropTag(entry.getTransactionHandle(transactionId), identity.toConnectorIdentity(tableName.getCatalogName()), context, toSchemaTableName(tableName)));
802+
}
803+
}
804+
789805
@Override
790806
public void checkCanDropConstraint(TransactionId transactionId, Identity identity, AccessControlContext context, QualifiedObjectName tableName)
791807
{

presto-main-base/src/main/java/com/facebook/presto/security/AllowAllSystemAccessControl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ public void checkCanDropBranch(Identity identity, AccessControlContext context,
231231
{
232232
}
233233

234+
@Override
235+
public void checkCanDropTag(Identity identity, AccessControlContext context, CatalogSchemaTableName table)
236+
{
237+
}
238+
234239
@Override
235240
public void checkCanDropConstraint(Identity identity, AccessControlContext context, CatalogSchemaTableName table)
236241
{

0 commit comments

Comments
 (0)