anoopj commented on code in PR #16174:
URL: https://github.com/apache/iceberg/pull/16174#discussion_r3229263089
##########
core/src/test/java/org/apache/iceberg/util/TestLocationUtil.java:
##########
@@ -84,4 +84,103 @@ void testStripTrailingSlashForRootPathWithTrailingSlashes()
{
.as("Should be root path")
.isEqualTo(rootPath);
}
+
+ @Test
+ public void testResolveRelativeLocations() {
+ String tableLocation = "s3://bucket/table";
+
+ assertThat(LocationUtil.resolveLocation(tableLocation,
"/metadata/file.parquet"))
+ .isEqualTo("s3://bucket/table/metadata/file.parquet");
+
+ assertThat(LocationUtil.resolveLocation(tableLocation,
"/data/00000-0.parquet"))
+ .isEqualTo("s3://bucket/table/data/00000-0.parquet");
+ }
+
+ @Test
+ public void testResolveLocationsWithColonsInSegments() {
+ String tableLocation = "s3://bucket/table";
+
+ assertThat(
+ LocationUtil.resolveLocation(tableLocation,
"/data/partition=key:value/file.parquet"))
+ .isEqualTo("s3://bucket/table/data/partition=key:value/file.parquet");
+
+ assertThat(LocationUtil.resolveLocation(tableLocation,
"/metadata/snap-123:456.avro"))
+ .isEqualTo("s3://bucket/table/metadata/snap-123:456.avro");
+ }
+
+ @Test
+ public void testResolveAbsoluteLocationsUnchanged() {
+ String tableLocation = "s3://bucket/table";
+
+ assertThat(LocationUtil.resolveLocation(tableLocation,
"s3://other-bucket/path/file.parquet"))
+ .isEqualTo("s3://other-bucket/path/file.parquet");
+
+ assertThat(LocationUtil.resolveLocation(tableLocation,
"hdfs://namenode/path/file.parquet"))
+ .isEqualTo("hdfs://namenode/path/file.parquet");
+ }
+
+ @Test
+ public void testRelativize() {
+ String tableLocation = "s3://bucket/table";
+
+ assertThat(
+ LocationUtil.relativizeLocation(
+ tableLocation, "s3://bucket/table/metadata/file.parquet"))
+ .isEqualTo("/metadata/file.parquet");
+
+ assertThat(
+ LocationUtil.relativizeLocation(
+ tableLocation, "s3://bucket/table/data/00000-0.parquet"))
+ .isEqualTo("/data/00000-0.parquet");
+ }
+
+ @Test
+ public void testRelativizeLocationNotUnderTableLocation() {
+ String tableLocation = "s3://bucket/table";
+
+ // different bucket
+ assertThat(
+ LocationUtil.relativizeLocation(tableLocation,
"s3://other-bucket/path/file.parquet"))
+ .isEqualTo("s3://other-bucket/path/file.parquet");
+
+ // same bucket, different path
+ assertThat(
+ LocationUtil.relativizeLocation(
+ tableLocation, "s3://bucket/other-table/data/file.parquet"))
+ .isEqualTo("s3://bucket/other-table/data/file.parquet");
+ }
+
+ @Test
+ public void testRelativizeLocationEqualToTableLocation() {
+ String tableLocation = "s3://bucket/table";
+
+ assertThat(LocationUtil.relativizeLocation(tableLocation,
"s3://bucket/table")).isEqualTo("");
+ }
+
+ @Test
+ public void testRelativizeMismatchedFileSchemeNotRelativized() {
+ // mixed file: variants are NOT relativized. Consistent URI forms are the
caller's
+ // responsibility
+ assertThat(
+ LocationUtil.relativizeLocation(
+ "file:/tmp/table", "file:///tmp/table/metadata/file.parquet"))
+ .isEqualTo("file:///tmp/table/metadata/file.parquet");
+
+ assertThat(
+ LocationUtil.relativizeLocation(
+ "file:///tmp/table", "file:/tmp/table/metadata/file.parquet"))
+ .isEqualTo("file:/tmp/table/metadata/file.parquet");
+ }
+
+ @Test
+ public void testRelativizeResolveRoundTrip() {
+ String tableLocation = "s3://bucket/table";
+ String absoluteLocation =
"s3://bucket/table/metadata/root-manifest.parquet";
+
+ String relativized = LocationUtil.relativizeLocation(tableLocation,
absoluteLocation);
+ assertThat(relativized).isEqualTo("/metadata/root-manifest.parquet");
+
+ String resolved = LocationUtil.resolveLocation(tableLocation, relativized);
+ assertThat(resolved).isEqualTo(absoluteLocation);
Review Comment:
1. Good idea. Added.
2. I removed the tests because it wasn't testing any different behavior of
the code. But I think it's worth having explicit tests. Revived them.
3. Added a test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]