Skip to content

Commit

Permalink
Add set properties support for iceberg
Browse files Browse the repository at this point in the history
  • Loading branch information
pratyakshsharma committed Oct 4, 2024
1 parent 251e3c0 commit d200ddc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
10 changes: 8 additions & 2 deletions presto-docs/src/main/sphinx/connector/iceberg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ that is stored using the ORC file format, partitioned by ``ds`` and
partitioning = ARRAY['ds', 'country']
)

Create an Iceberg table with Iceberg format version 2::
Create an Iceberg table with Iceberg format version 2 and with commit_retries set to 5::

CREATE TABLE iceberg.web.page_views_v2 (
view_time timestamp,
Expand All @@ -1055,7 +1055,8 @@ Create an Iceberg table with Iceberg format version 2::
WITH (
format = 'ORC',
partitioning = ARRAY['ds', 'country'],
format_version = '2'
format_version = '2',
commit_retries = 5
)

Partition Column Transform
Expand Down Expand Up @@ -1190,6 +1191,11 @@ The table is partitioned by the transformed value of the column::

ALTER TABLE iceberg.web.page_views ADD COLUMN ts timestamp WITH (partitioning = 'hour');

Table properties can be modified for an Iceberg table using an ALTER TABLE SET PROPERTIES statement. Only `commit_retries` can be modified at present.
For example, to set `commit_retries` to 6 for the table `iceberg.web.page_views_v2`, use::

ALTER TABLE iceberg.web.page_views_v2 SET PROPERTIES (commit_retries = 6);

TRUNCATE
^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@
import org.apache.iceberg.Schema;
import org.apache.iceberg.SchemaParser;
import org.apache.iceberg.Table;
import org.apache.iceberg.TableProperties;
import org.apache.iceberg.Transaction;
import org.apache.iceberg.UpdateProperties;
import org.apache.iceberg.types.Type;
import org.apache.iceberg.types.TypeUtil;
import org.apache.iceberg.types.Types;
Expand Down Expand Up @@ -119,6 +121,7 @@
import static com.facebook.presto.iceberg.IcebergPartitionType.ALL;
import static com.facebook.presto.iceberg.IcebergSessionProperties.getCompressionCodec;
import static com.facebook.presto.iceberg.IcebergSessionProperties.isPushdownFilterEnabled;
import static com.facebook.presto.iceberg.IcebergTableProperties.COMMIT_RETRIES;
import static com.facebook.presto.iceberg.IcebergTableProperties.DELETE_MODE;
import static com.facebook.presto.iceberg.IcebergTableProperties.FILE_FORMAT_PROPERTY;
import static com.facebook.presto.iceberg.IcebergTableProperties.FORMAT_VERSION;
Expand Down Expand Up @@ -953,6 +956,28 @@ public OptionalLong metadataDelete(ConnectorSession session, ConnectorTableHandl
return removeScanFiles(icebergTable, domainPredicate);
}

@Override
public void setTableProperties(ConnectorSession session, ConnectorTableHandle tableHandle, Map<String, Object> properties)
{
IcebergTableHandle handle = (IcebergTableHandle) tableHandle;
Table icebergTable = getIcebergTable(session, handle.getSchemaTableName());
transaction = icebergTable.newTransaction();

UpdateProperties updateProperties = transaction.updateProperties();
for (Map.Entry<String, Object> entry : properties.entrySet()) {
switch (entry.getKey()) {
case COMMIT_RETRIES:
updateProperties.set(TableProperties.COMMIT_NUM_RETRIES, String.valueOf(entry.getValue()));
break;
default:
throw new PrestoException(NOT_SUPPORTED, "Updating property " + entry.getKey() + " is not supported currently");
}
}

updateProperties.commit();
transaction.commitTransaction();
}

/**
* Deletes all the files for a specific predicate
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static java.util.stream.Collectors.joining;
import static java.util.stream.IntStream.range;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
Expand Down Expand Up @@ -1809,4 +1810,39 @@ private Session sessionForTimezone(String zoneId, boolean legacyTimestamp)
}
return sessionBuilder.build();
}

@Test
public void testUpdatingInvalidProperty()
{
Session session = getSession();
String tableName = "test_invalid_property_update";
assertUpdate(session, "CREATE TABLE " + tableName + " (c1 integer, c2 varchar) WITH(commit_retries = 4)");
assertThatThrownBy(() -> assertUpdate("ALTER TABLE " + tableName + " SET PROPERTIES (format = 'PARQUET')"))
.hasMessage("Updating property format is not supported currently");
assertUpdate("DROP TABLE " + tableName);
}

@Test
public void testUpdatingRandomProperty()
{
Session session = getSession();
String tableName = "test_random_property_update";
assertUpdate(session, "CREATE TABLE " + tableName + " (c1 integer, c2 varchar) WITH(commit_retries = 4)");
assertThatThrownBy(() -> assertUpdate("ALTER TABLE " + tableName + " SET PROPERTIES (some_config = 2)"))
.hasMessage("Catalog 'iceberg' does not support table property 'some_config'");
assertUpdate("DROP TABLE " + tableName);
}

@Test
public void testUpdatingCommitRetries()
{
Session session = getSession();
String tableName = "test_commit_retries_update";
assertUpdate(session, "CREATE TABLE " + tableName + " (c1 integer, c2 varchar) WITH(commit_retries = 4)");
assertQuery("SELECT value FROM \"" + tableName + "$properties\" WHERE key = 'commit.retry.num-retries'", "VALUES 4");
assertUpdate("ALTER TABLE " + tableName + " SET PROPERTIES (commit_retries = 5)");
assertUpdate("ALTER TABLE IF EXISTS " + tableName + " SET PROPERTIES (commit_retries = 6)");
assertQuery("SELECT value FROM \"" + tableName + "$properties\" WHERE key = 'commit.retry.num-retries'", "VALUES 6");
assertUpdate("DROP TABLE " + tableName);
}
}

0 comments on commit d200ddc

Please sign in to comment.