Skip to content

Commit

Permalink
Reduce usage of deprecated Locations.appendPath in Delta
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Oct 4, 2024
1 parent faed8db commit c557560
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Verify.verify;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static io.airlift.slice.Slices.wrappedBuffer;
import static io.trino.filesystem.Locations.appendPath;
import static io.trino.plugin.deltalake.DeltaLakeErrorCode.DELTA_LAKE_BAD_WRITE;
import static io.trino.plugin.deltalake.DeltaLakeSessionProperties.getCompressionCodec;
import static io.trino.plugin.deltalake.DeltaLakeSessionProperties.getParquetWriterBlockSize;
Expand Down Expand Up @@ -404,7 +404,13 @@ private int[] getWriterIndexes(Page page)

private String getRelativeFilePath(Optional<String> partitionName, String fileName)
{
return getPathPrefix() + partitionName.map(partition -> appendPath(partition, fileName)).orElse(fileName);
return getPathPrefix() + partitionName
.map(partition -> {
// partition is escaped by makePartName
checkArgument(!partition.endsWith("/"), "Partition name should not end with '/'");
return partition + "/" + fileName;
})
.orElse(fileName);
}

protected void closeWriter(int writerIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.trino.filesystem.hdfs.HdfsFileSystemFactory;
import org.junit.jupiter.api.Test;

import static io.trino.filesystem.Locations.appendPath;
import static io.trino.plugin.deltalake.DeltaTestingConnectorSession.SESSION;
import static io.trino.plugin.deltalake.transactionlog.TransactionLogParser.getMandatoryCurrentVersion;
import static io.trino.plugin.hive.HiveTestUtils.HDFS_ENVIRONMENT;
Expand All @@ -35,10 +34,10 @@ public void testGetCurrentVersion()

String basePath = getClass().getClassLoader().getResource("databricks73").toURI().toString();

assertThat(getMandatoryCurrentVersion(fileSystem, appendPath(basePath, "simple_table_without_checkpoint"), 8)).isEqualTo(9);
assertThat(getMandatoryCurrentVersion(fileSystem, appendPath(basePath, "simple_table_without_checkpoint"), 9)).isEqualTo(9);
assertThat(getMandatoryCurrentVersion(fileSystem, appendPath(basePath, "simple_table_ending_on_checkpoint"), 10)).isEqualTo(10);
assertThat(getMandatoryCurrentVersion(fileSystem, appendPath(basePath, "simple_table_past_checkpoint"), 10)).isEqualTo(11);
assertThat(getMandatoryCurrentVersion(fileSystem, appendPath(basePath, "simple_table_past_checkpoint"), 11)).isEqualTo(11);
assertThat(getMandatoryCurrentVersion(fileSystem, basePath + "/simple_table_without_checkpoint", 8)).isEqualTo(9);
assertThat(getMandatoryCurrentVersion(fileSystem, basePath + "/simple_table_without_checkpoint", 9)).isEqualTo(9);
assertThat(getMandatoryCurrentVersion(fileSystem, basePath + "/simple_table_ending_on_checkpoint", 10)).isEqualTo(10);
assertThat(getMandatoryCurrentVersion(fileSystem, basePath + "/simple_table_past_checkpoint", 10)).isEqualTo(11);
assertThat(getMandatoryCurrentVersion(fileSystem, basePath + "/simple_table_past_checkpoint", 11)).isEqualTo(11);
}
}

0 comments on commit c557560

Please sign in to comment.