Skip to content

Commit

Permalink
Add support for drop tag for Iceberg Table
Browse files Browse the repository at this point in the history
  • Loading branch information
agrawalreetika committed Sep 8, 2024
1 parent dbd295b commit 3fe4d56
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions presto-docs/src/main/sphinx/connector/iceberg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,8 @@ Alter table operations are supported in the Iceberg connector::

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

ALTER TABLE iceberg.web.page_views DROP TAG 'tag1';

To add a new column as a partition column, identify the transform functions for the column.
The table is partitioned by the transformed value of the column::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,21 @@ public void dropBranch(ConnectorSession session, ConnectorTableHandle tableHandl
}
}

@Override
public void dropTag(ConnectorSession session, ConnectorTableHandle tableHandle, Optional<String> tagName)
{
String tag = tagName.get().replace("'", "");
IcebergTableHandle icebergTableHandle = (IcebergTableHandle) tableHandle;
verify(icebergTableHandle.getIcebergTableName().getTableType() == DATA, "only the data table can have tag dropped");
Table icebergTable = getIcebergTable(session, icebergTableHandle.getSchemaTableName());
if (icebergTable.refs().containsKey(tag) && icebergTable.refs().get(tag).isTag()) {
icebergTable.manageSnapshots().removeTag(tag).commit();
}
else {
throw new PrestoException(NOT_FOUND, format("Tag %s doesn't exist in table %s", tagName.get(), icebergTableHandle.getSchemaTableName().getTableName()));
}
}

@Override
public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,31 @@ public void testDropBranch()
assertQuerySucceeds("DROP TABLE test_table_branch");
}

@Test
public void testDropTag()
{
assertUpdate("CREATE TABLE test_table_tag (id1 BIGINT, id2 BIGINT)");
assertUpdate("INSERT INTO test_table_tag VALUES (0, 00), (1, 10)", 2);

Table icebergTable = loadTable("test_table_tag");
icebergTable.manageSnapshots().createTag("testTag1", icebergTable.currentSnapshot().snapshotId()).commit();

assertUpdate("INSERT INTO test_table_tag VALUES (2, 30), (3, 30)", 2);
icebergTable.manageSnapshots().createTag("testTag2", icebergTable.currentSnapshot().snapshotId()).commit();
assertUpdate("INSERT INTO test_table_tag VALUES (4, 40), (5, 50)", 2);
assertEquals(icebergTable.refs().size(), 3);

assertQuery("SELECT count(*) FROM test_table_tag FOR SYSTEM_VERSION AS OF 'testTag1'", "VALUES 2");
assertQuery("SELECT count(*) FROM test_table_tag FOR SYSTEM_VERSION AS OF 'testTag2'", "VALUES 4");
assertQuery("SELECT count(*) FROM test_table_tag FOR SYSTEM_VERSION AS OF 'main'", "VALUES 6");

assertQuerySucceeds("ALTER TABLE test_table_tag DROP TAG 'testTag1'");
icebergTable = loadTable("test_table_tag");
assertEquals(icebergTable.refs().size(), 2);
assertQueryFails("ALTER TABLE test_table_tag DROP TAG 'testTagNotExist'", "Tag 'testTagNotExist' doesn't exist in table test_table_tag");
assertQuerySucceeds("DROP TABLE test_table_tag");
}

@Test
public void testRefsTable()
{
Expand Down

0 comments on commit 3fe4d56

Please sign in to comment.