Skip to content

Commit

Permalink
Populate split offset in Iceberg OPTIMIZE procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Aug 8, 2024
1 parent a824609 commit 1301057
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,7 @@ private void finishOptimize(ConnectorSession session, IcebergTableExecuteHandle
.withFileSizeInBytes(task.fileSizeInBytes())
.withFormat(optimizeHandle.fileFormat().toIceberg())
.withMetrics(task.metrics().metrics());
task.fileSplitOffsets().ifPresent(builder::withSplitOffsets);

if (!icebergTable.spec().fields().isEmpty()) {
String partitionDataJson = task.partitionDataJson()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import io.trino.spi.statistics.DoubleRange;
import io.trino.spi.statistics.Estimate;
import io.trino.spi.statistics.TableStatistics;
import io.trino.spi.type.ArrayType;
import io.trino.spi.type.TestingTypeManager;
import io.trino.spi.type.TypeManager;
import io.trino.testing.AbstractTestQueryFramework;
Expand Down Expand Up @@ -97,7 +98,9 @@
import static io.trino.plugin.iceberg.IcebergTestUtils.getFileSystemFactory;
import static io.trino.plugin.iceberg.util.EqualityDeleteUtils.writeEqualityDeleteForTable;
import static io.trino.plugin.iceberg.util.EqualityDeleteUtils.writeEqualityDeleteForTableWithSchema;
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.spi.type.IntegerType.INTEGER;
import static io.trino.testing.MaterializedResult.resultBuilder;
import static io.trino.testing.TestingConnectorSession.SESSION;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static io.trino.tpch.TpchTable.NATION;
Expand Down Expand Up @@ -347,6 +350,19 @@ public void testSelectivelyOptimizingLeavesEqualityDeletes()
assertThat(loadTable(tableName).currentSnapshot().summary()).containsEntry("total-equality-deletes", "1");
}

@Test
public void testOptimizePopulateSplitOffsets()
{
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_optimize_split_offsets", "AS SELECT * FROM tpch.tiny.nation")) {
assertUpdate("ALTER TABLE " + table.getName() + " EXECUTE optimize");
assertThat(computeActual("SELECT split_offsets FROM \"" + table.getName() + "$files\""))
.isEqualTo(resultBuilder(getSession(), ImmutableList.of(new ArrayType(BIGINT)))
.row(ImmutableList.of(4L))
.row(ImmutableList.of(4L))
.build());
}
}

@Test
public void testMultipleEqualityDeletes()
throws Exception
Expand Down

0 comments on commit 1301057

Please sign in to comment.