diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/LocationPath.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/LocationPath.java index c7558938711ca2..452fc9b91a1794 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/util/LocationPath.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/LocationPath.java @@ -149,6 +149,9 @@ public static LocationPath of(String location, String encodedLocation = encodedLocation(normalizedLocation); URI uri = URI.create(encodedLocation); String fsIdentifier = Strings.nullToEmpty(uri.getScheme()) + "://" + Strings.nullToEmpty(uri.getAuthority()); + if (StringUtils.isBlank(schema)) { + schema = Strings.nullToEmpty(uri.getScheme()); + } return new LocationPath(schema, normalizedLocation, fsIdentifier, storageProperties); } @@ -193,6 +196,9 @@ public static LocationPath of(String location, URI uri = URI.create(encodedLocation); String fsIdentifier = Strings.nullToEmpty(uri.getScheme()) + "://" + Strings.nullToEmpty(uri.getAuthority()); + if (StringUtils.isBlank(schema)) { + schema = Strings.nullToEmpty(uri.getScheme()); + } return new LocationPath(schema, normalizedLocation, fsIdentifier, storageProperties); } catch (UserException e) { throw new StoragePropertiesException("Failed to create LocationPath for location: " + location, e); @@ -234,6 +240,7 @@ public static LocationPath ofWithCache(String location, String normalizedLocation = storageProperties.validateAndNormalizeUri(location); String fsIdentifier; + String schema = cachedSchema; if (cachedFsIdPrefix != null && normalizedLocation.startsWith(cachedFsIdPrefix)) { // Fast path: extract authority from normalized location without full URI parsing int authorityStart = cachedFsIdPrefix.length(); @@ -246,6 +253,9 @@ public static LocationPath ofWithCache(String location, throw new StoragePropertiesException("Invalid location, missing authority: " + normalizedLocation); } fsIdentifier = cachedFsIdPrefix + authority; + if (StringUtils.isBlank(schema)) { + schema = cachedFsIdPrefix.substring(0, cachedFsIdPrefix.length() - SCHEME_DELIM.length()); + } } else { // Fallback to full URI parsing String encodedLocation = encodedLocation(normalizedLocation); @@ -256,9 +266,11 @@ public static LocationPath ofWithCache(String location, } fsIdentifier = Strings.nullToEmpty(uri.getScheme()) + "://" + authority; + if (StringUtils.isBlank(schema)) { + schema = Strings.nullToEmpty(uri.getScheme()); + } } - String schema = cachedSchema != null ? cachedSchema : extractScheme(location); return new LocationPath(schema, normalizedLocation, fsIdentifier, storageProperties); } catch (UserException e) { throw new StoragePropertiesException("Failed to create LocationPath for location: " + location, e); diff --git a/fe/fe-core/src/test/java/org/apache/doris/common/util/LocationPathTest.java b/fe/fe-core/src/test/java/org/apache/doris/common/util/LocationPathTest.java index 1e5d404a7f6b75..8f311225fcf013 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/common/util/LocationPathTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/common/util/LocationPathTest.java @@ -334,6 +334,21 @@ public void testLocationPathWithCacheFallback() { Assertions.assertEquals(full.getSchema(), cached.getSchema()); } + @Test + public void testLocationPathWithCacheUsesDefaultFsForHdfsPath() { + StorageProperties storageProperties = STORAGE_PROPERTIES_MAP.get(StorageProperties.Type.HDFS); + String location = "/hadoop_catalog/fdm/f_csm_t_consume_info/data/data_dt=20220407/file.parquet"; + LocationPath cached = LocationPath.ofWithCache(location, storageProperties, null, null); + LocationPath full = LocationPath.of(location, STORAGE_PROPERTIES_MAP); + Assertions.assertEquals(full.getNormalizedLocation(), cached.getNormalizedLocation()); + Assertions.assertEquals("hdfs://namenode:8020/hadoop_catalog/fdm/f_csm_t_consume_info/data/" + + "data_dt=20220407/file.parquet", cached.getNormalizedLocation()); + Assertions.assertEquals("hdfs://namenode:8020", cached.getFsIdentifier()); + Assertions.assertEquals("hdfs", cached.getSchema()); + Assertions.assertEquals(TFileType.FILE_HDFS, cached.getTFileTypeForBE()); + Assertions.assertEquals(FileSystemType.HDFS, cached.getFileSystemType()); + } + @Test public void testLocationPathWithCacheMissingAuthority() { StorageProperties storageProperties = STORAGE_PROPERTIES_MAP.get(StorageProperties.Type.S3);