rdblue commented on code in PR #16174:
URL: https://github.com/apache/iceberg/pull/16174#discussion_r3285009961


##########
core/src/test/java/org/apache/iceberg/util/TestLocationUtil.java:
##########
@@ -84,4 +84,170 @@ 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 testRelativizeLocationWithSharedPrefix() {
+    // sibling locations that share a byte prefix with the table location but 
are not
+    // children of it must not be relativized (e.g. "table" vs "table_v2")
+    String tableLocation = "s3://bucket/table";
+
+    assertThat(
+            LocationUtil.relativizeLocation(
+                tableLocation, "s3://bucket/table_v2/data/00000-0.parquet"))
+        .isEqualTo("s3://bucket/table_v2/data/00000-0.parquet");
+  }
+
+  @Test
+  public void testRelativizeLocationEqualToTableLocation() {

Review Comment:
   I agree with this decision.



-- 
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]

Reply via email to