Skip to content

Commit e333bb1

Browse files
Add support for drop tag for Iceberg Table
1 parent 4cbfa16 commit e333bb1

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

14071407
ALTER TABLE iceberg.web.page_views DROP BRANCH 'branch1';
14081408

1409+
ALTER TABLE iceberg.web.page_views DROP TAG 'tag1';
1410+
14091411
To add a new column as a partition column, identify the transform functions for the column.
14101412
The table is partitioned by the transformed value of the column::
14111413

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
@@ -860,6 +860,22 @@ public void dropBranch(ConnectorSession session, ConnectorTableHandle tableHandl
860860
}
861861
}
862862

863+
@Override
864+
public void dropTag(ConnectorSession session, ConnectorTableHandle tableHandle, String tagName, boolean tagExists)
865+
{
866+
IcebergTableHandle icebergTableHandle = (IcebergTableHandle) tableHandle;
867+
verify(icebergTableHandle.getIcebergTableName().getTableType() == DATA, "only the data table can have tag dropped");
868+
Table icebergTable = getIcebergTable(session, icebergTableHandle.getSchemaTableName());
869+
if (icebergTable.refs().containsKey(tagName) && icebergTable.refs().get(tagName).isTag()) {
870+
icebergTable.manageSnapshots().removeTag(tagName).commit();
871+
}
872+
else {
873+
if (!tagExists) {
874+
throw new PrestoException(NOT_FOUND, format("Tag %s doesn't exist in table %s", tagName, icebergTableHandle.getSchemaTableName().getTableName()));
875+
}
876+
}
877+
}
878+
863879
@Override
864880
public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column)
865881
{

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
@@ -1844,6 +1844,33 @@ public void testDropBranch()
18441844
assertQuerySucceeds("DROP TABLE test_table_branch");
18451845
}
18461846

1847+
@Test
1848+
public void testDropTag()
1849+
{
1850+
assertUpdate("CREATE TABLE test_table_tag (id1 BIGINT, id2 BIGINT)");
1851+
assertUpdate("INSERT INTO test_table_tag VALUES (0, 00), (1, 10)", 2);
1852+
1853+
Table icebergTable = loadTable("test_table_tag");
1854+
icebergTable.manageSnapshots().createTag("testTag1", icebergTable.currentSnapshot().snapshotId()).commit();
1855+
1856+
assertUpdate("INSERT INTO test_table_tag VALUES (2, 30), (3, 30)", 2);
1857+
icebergTable.manageSnapshots().createTag("testTag2", icebergTable.currentSnapshot().snapshotId()).commit();
1858+
assertUpdate("INSERT INTO test_table_tag VALUES (4, 40), (5, 50)", 2);
1859+
assertEquals(icebergTable.refs().size(), 3);
1860+
1861+
assertQuery("SELECT count(*) FROM test_table_tag FOR SYSTEM_VERSION AS OF 'testTag1'", "VALUES 2");
1862+
assertQuery("SELECT count(*) FROM test_table_tag FOR SYSTEM_VERSION AS OF 'testTag2'", "VALUES 4");
1863+
assertQuery("SELECT count(*) FROM test_table_tag FOR SYSTEM_VERSION AS OF 'main'", "VALUES 6");
1864+
1865+
assertQuerySucceeds("ALTER TABLE test_table_tag DROP TAG 'testTag1'");
1866+
icebergTable = loadTable("test_table_tag");
1867+
assertEquals(icebergTable.refs().size(), 2);
1868+
assertQueryFails("ALTER TABLE test_table_tag DROP TAG 'testTagNotExist'", "Tag testTagNotExist doesn't exist in table test_table_tag");
1869+
assertQuerySucceeds("ALTER TABLE test_table_tag DROP TAG IF EXISTS 'testTag2'");
1870+
assertQuerySucceeds("ALTER TABLE test_table_tag DROP TAG IF EXISTS 'testTagNotExist'");
1871+
assertQuerySucceeds("DROP TABLE test_table_tag");
1872+
}
1873+
18471874
@Test
18481875
public void testRefsTable()
18491876
{

0 commit comments

Comments
 (0)