Skip to content

Commit

Permalink
Fix matching file prefixes for FILE based catalogs (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyashanker22 authored Dec 5, 2024
1 parent 3a8d7fe commit b5685ef
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/** An abstraction over a storage location */
public class StorageLocation {
private final String location;
public static final String LOCAL_PATH_PREFIX = "file:///";

/** Create a StorageLocation from a String path */
public static StorageLocation of(String location) {
Expand All @@ -39,8 +40,10 @@ public static StorageLocation of(String location) {
protected StorageLocation(@Nonnull String location) {
if (location == null) {
this.location = null;
} else if (location.startsWith("file:/") && !location.startsWith("file:///")) {
this.location = URI.create(location.replaceFirst("file:/+", "file:///")).toString();
} else if (location.startsWith("file:/") && !location.startsWith(LOCAL_PATH_PREFIX)) {
this.location = URI.create(location.replaceFirst("file:/+", LOCAL_PATH_PREFIX)).toString();
} else if (location.startsWith("/")) {
this.location = URI.create(location.replaceFirst("/+", LOCAL_PATH_PREFIX)).toString();
} else {
this.location = URI.create(location).toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.polaris.service.storage;

import org.apache.polaris.core.storage.StorageLocation;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class StorageLocationTest {

@Test
public void testOfDifferentPrefixes() {
StorageLocation StandardLocation = StorageLocation.of("file:///path/to/file");
StorageLocation slashLeadingLocation = StorageLocation.of("/path/to/file");
StorageLocation fileSingleSlashLocation = StorageLocation.of("file:/path/to/file");
Assertions.assertThat(slashLeadingLocation.equals(StandardLocation)).isTrue();
Assertions.assertThat(fileSingleSlashLocation.equals(StandardLocation)).isTrue();
}
}

0 comments on commit b5685ef

Please sign in to comment.