Skip to content

Commit 1e47c05

Browse files
Add support for drop tag for Iceberg Table
1 parent 8a539d8 commit 1e47c05

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-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
@@ -1113,6 +1113,8 @@ Alter table operations are supported in the Iceberg connector::
11131113

11141114
ALTER TABLE iceberg.web.page_views DROP BRANCH 'branch1';
11151115

1116+
ALTER TABLE iceberg.web.page_views DROP TAG 'tag1';
1117+
11161118
To add a new column as a partition column, identify the transform functions for the column.
11171119
The table is partitioned by the transformed value of the column::
11181120

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,20 @@ public void dropBranch(ConnectorSession session, ConnectorTableHandle tableHandl
647647
}
648648
}
649649

650+
@Override
651+
public void dropTag(ConnectorSession session, ConnectorTableHandle tableHandle, Optional<String> tagName)
652+
{
653+
IcebergTableHandle icebergTableHandle = (IcebergTableHandle) tableHandle;
654+
verify(icebergTableHandle.getIcebergTableName().getTableType() == DATA, "only the data table can have tag dropped");
655+
Table icebergTable = getIcebergTable(session, icebergTableHandle.getSchemaTableName());
656+
if (icebergTable.refs().containsKey(tagName.get()) && icebergTable.refs().get(tagName.get()).isTag()) {
657+
icebergTable.manageSnapshots().removeTag(tagName.get()).commit();
658+
}
659+
else {
660+
throw new PrestoException(NOT_FOUND, format("Tag %s doesn't exist in table %s", tagName.get(), icebergTableHandle.getSchemaTableName().getTableName()));
661+
}
662+
}
663+
650664
@Override
651665
public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column)
652666
{

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
@@ -1649,6 +1649,33 @@ public void testDropBranch()
16491649
assertQuerySucceeds("DROP TABLE test_table_branch");
16501650
}
16511651

1652+
@Test
1653+
public void testDropTag()
1654+
{
1655+
assertUpdate("CREATE TABLE test_table_tag (id1 BIGINT, id2 BIGINT)");
1656+
assertUpdate("INSERT INTO test_table_tag VALUES (0, 00), (1, 10)", 2);
1657+
1658+
Table icebergTable = loadTable("test_table_tag");
1659+
icebergTable.manageSnapshots().createTag("testTag1", icebergTable.currentSnapshot().snapshotId()).commit();
1660+
1661+
assertUpdate("INSERT INTO test_table_tag VALUES (2, 30), (3, 30)", 2);
1662+
icebergTable.manageSnapshots().createTag("testTag2", icebergTable.currentSnapshot().snapshotId()).commit();
1663+
assertUpdate("INSERT INTO test_table_tag VALUES (4, 40), (5, 50)", 2);
1664+
assertEquals(icebergTable.refs().size(), 3);
1665+
1666+
assertQuery("SELECT count(*) FROM test_table_tag FOR SYSTEM_VERSION AS OF 'testTag1'", "VALUES 2");
1667+
assertQuery("SELECT count(*) FROM test_table_tag FOR SYSTEM_VERSION AS OF 'testTag2'", "VALUES 4");
1668+
assertQuery("SELECT count(*) FROM test_table_tag FOR SYSTEM_VERSION AS OF 'main'", "VALUES 6");
1669+
1670+
assertQuerySucceeds("ALTER TABLE test_table_tag DROP TAG 'testTag1'");
1671+
icebergTable = loadTable("test_table_tag");
1672+
assertEquals(icebergTable.refs().size(), 2);
1673+
assertQueryFails("ALTER TABLE test_table_tag DROP TAG 'testTagNotExist'", "Tag testTagNotExist doesn't exist in table test_table_tag");
1674+
assertQuerySucceeds("ALTER TABLE test_table_tag DROP TAG IF EXISTS 'testTag2'");
1675+
assertQueryFails("ALTER TABLE test_table_tag DROP TAG IF EXISTS 'testTagNotExist'", "Tag testTagNotExist doesn't exist in table test_table_tag");
1676+
assertQuerySucceeds("DROP TABLE test_table_tag");
1677+
}
1678+
16521679
@Test
16531680
public void testRefsTable()
16541681
{

0 commit comments

Comments
 (0)