Skip to content

Commit 5af0a0d

Browse files
Add support for drop tag for Iceberg Table
1 parent 464303e commit 5af0a0d

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

presto-docs/src/main/sphinx/connector/iceberg.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,8 @@ Alter table operations are supported in the Iceberg connector::
11751175

11761176
ALTER TABLE iceberg.web.page_views DROP BRANCH 'branch1';
11771177

1178+
ALTER TABLE iceberg.web.page_views DROP TAG 'tag1';
1179+
11781180
To add a new column as a partition column, identify the transform functions for the column.
11791181
The table is partitioned by the transformed value of the column::
11801182

presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,22 @@ public void dropBranch(ConnectorSession session, ConnectorTableHandle tableHandl
653653
}
654654
}
655655

656+
@Override
657+
public void dropTag(ConnectorSession session, ConnectorTableHandle tableHandle, String tagName, boolean tagExists)
658+
{
659+
IcebergTableHandle icebergTableHandle = (IcebergTableHandle) tableHandle;
660+
verify(icebergTableHandle.getIcebergTableName().getTableType() == DATA, "only the data table can have tag dropped");
661+
Table icebergTable = getIcebergTable(session, icebergTableHandle.getSchemaTableName());
662+
if (icebergTable.refs().containsKey(tagName) && icebergTable.refs().get(tagName).isTag()) {
663+
icebergTable.manageSnapshots().removeTag(tagName).commit();
664+
}
665+
else {
666+
if (!tagExists) {
667+
throw new PrestoException(NOT_FOUND, format("Tag %s doesn't exist in table %s", tagName, icebergTableHandle.getSchemaTableName().getTableName()));
668+
}
669+
}
670+
}
671+
656672
@Override
657673
public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column)
658674
{

presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedTestBase.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,33 @@ public void testDropBranch()
16601660
assertQuerySucceeds("DROP TABLE test_table_branch");
16611661
}
16621662

1663+
@Test
1664+
public void testDropTag()
1665+
{
1666+
assertUpdate("CREATE TABLE test_table_tag (id1 BIGINT, id2 BIGINT)");
1667+
assertUpdate("INSERT INTO test_table_tag VALUES (0, 00), (1, 10)", 2);
1668+
1669+
Table icebergTable = loadTable("test_table_tag");
1670+
icebergTable.manageSnapshots().createTag("testTag1", icebergTable.currentSnapshot().snapshotId()).commit();
1671+
1672+
assertUpdate("INSERT INTO test_table_tag VALUES (2, 30), (3, 30)", 2);
1673+
icebergTable.manageSnapshots().createTag("testTag2", icebergTable.currentSnapshot().snapshotId()).commit();
1674+
assertUpdate("INSERT INTO test_table_tag VALUES (4, 40), (5, 50)", 2);
1675+
assertEquals(icebergTable.refs().size(), 3);
1676+
1677+
assertQuery("SELECT count(*) FROM test_table_tag FOR SYSTEM_VERSION AS OF 'testTag1'", "VALUES 2");
1678+
assertQuery("SELECT count(*) FROM test_table_tag FOR SYSTEM_VERSION AS OF 'testTag2'", "VALUES 4");
1679+
assertQuery("SELECT count(*) FROM test_table_tag FOR SYSTEM_VERSION AS OF 'main'", "VALUES 6");
1680+
1681+
assertQuerySucceeds("ALTER TABLE test_table_tag DROP TAG 'testTag1'");
1682+
icebergTable = loadTable("test_table_tag");
1683+
assertEquals(icebergTable.refs().size(), 2);
1684+
assertQueryFails("ALTER TABLE test_table_tag DROP TAG 'testTagNotExist'", "Tag testTagNotExist doesn't exist in table test_table_tag");
1685+
assertQuerySucceeds("ALTER TABLE test_table_tag DROP TAG IF EXISTS 'testTag2'");
1686+
assertQuerySucceeds("ALTER TABLE test_table_tag DROP TAG IF EXISTS 'testTagNotExist'");
1687+
assertQuerySucceeds("DROP TABLE test_table_tag");
1688+
}
1689+
16631690
@Test
16641691
public void testRefsTable()
16651692
{

0 commit comments

Comments
 (0)