Skip to content

Commit 90126cd

Browse files
committed
tmp1
1 parent 03893b7 commit 90126cd

File tree

2 files changed

+14
-61
lines changed

2 files changed

+14
-61
lines changed

src/Storages/ObjectStorage/Utils.cpp

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace ErrorCodes
3333
namespace
3434
{
3535

36-
inline std::string normalizeSchema(const std::string & schema)
36+
std::string normalizeSchema(const std::string & schema)
3737
{
3838
auto schema_lowercase = Poco::toLower(schema);
3939

@@ -45,12 +45,12 @@ inline std::string normalizeSchema(const std::string & schema)
4545
return schema_lowercase;
4646
}
4747

48-
inline std::string endpoint_cache_key(const std::string & normalized_scheme, const std::string & authority)
48+
std::string endpoint_cache_key(const std::string & normalized_scheme, const std::string & authority)
4949
{
5050
return normalized_scheme + "://" + authority;
5151
}
5252

53-
static std::string factoryTypeForScheme(const std::string & normalized_scheme)
53+
std::string factoryTypeForScheme(const std::string & normalized_scheme)
5454
{
5555
if (normalized_scheme == "s3") return "s3";
5656
if (normalized_scheme == "abfs") return "azure";
@@ -59,6 +59,14 @@ static std::string factoryTypeForScheme(const std::string & normalized_scheme)
5959
return "";
6060
}
6161

62+
bool isAbsolutePath(const std::string & path)
63+
{
64+
if (!path.empty() && (path.front() == '/' || path.find("://") != std::string_view::npos))
65+
return true;
66+
67+
return false;
68+
}
69+
6270
}
6371

6472
// TODO: handle https://s3.amazonaws.com/bucketname/... properly
@@ -196,54 +204,6 @@ void validateSupportedColumns(
196204
}
197205
}
198206

199-
inline bool isSameStorageSchema(const std::string & schema1, const std::string & schema2)
200-
{
201-
return normalizeSchema(schema1) == normalizeSchema(schema2);
202-
}
203-
204-
std::string extractStorageType(const std::string & path)
205-
{
206-
if (path.empty())
207-
return "";
208-
209-
// Absolute POSIX path -> file
210-
if (path.front() == '/')
211-
return "file";
212-
213-
// Look for "scheme://..."
214-
if (auto pos = path.find("://"); pos != std::string_view::npos && pos > 0)
215-
return Poco::toLower(path.substr(0, pos));
216-
217-
// Tolerant: "scheme:..." with no slash before colon (avoid Windows drive letters like "C:\")
218-
{
219-
auto colon_pos = path.find(':');
220-
auto slash_pos = path.find('/');
221-
if (colon_pos != std::string_view::npos && (slash_pos == std::string_view::npos || colon_pos < slash_pos))
222-
{
223-
auto maybe_scheme = path.substr(0, colon_pos);
224-
// Heuristic: treat single-letter prefix followed by ":\\" as Windows drive, not a scheme
225-
if (!(maybe_scheme.size() == 1 && colon_pos + 1 < path.size() && (path[colon_pos + 1] == '\\' || path[colon_pos + 1] == '/')))
226-
return Poco::toLower(maybe_scheme);
227-
}
228-
}
229-
230-
// Relative path or unknown
231-
return "";
232-
}
233-
234-
bool isRelativePath(const std::string & path)
235-
{
236-
if (path.empty())
237-
return true;
238-
239-
// Non-relative if it has a scheme (e.g., s3://, file://)
240-
if (!extractStorageType(path).empty())
241-
return false;
242-
243-
return true;
244-
}
245-
246-
247207
std::string normalizePathToStorageRoot(const std::string & table_location, const std::string & path)
248208
{
249209
if (table_location.empty())
@@ -255,7 +215,7 @@ std::string normalizePathToStorageRoot(const std::string & table_location, const
255215
return result;
256216
}
257217

258-
if (!isRelativePath(path))
218+
if (isAbsolutePath(path))
259219
{
260220
SchemeAuthorityKey target{path};
261221
return target.key;
@@ -326,7 +286,7 @@ std::string normalizePathToStorageRoot(const std::string & table_location, const
326286

327287
std::string makeAbsolutePath(const std::string & table_location, const std::string & path)
328288
{
329-
if (!isRelativePath(path))
289+
if (isAbsolutePath(path))
330290
return path;
331291

332292
auto base = SchemeAuthorityKey(table_location);
@@ -348,7 +308,7 @@ std::pair<DB::ObjectStoragePtr, std::string> resolveObjectStorageForPath(
348308
std::map<std::string, DB::ObjectStoragePtr> & secondary_storages,
349309
const DB::ContextPtr & context)
350310
{
351-
if (isRelativePath(path))
311+
if (!isAbsolutePath(path))
352312
{
353313
// For relative paths, normalize to storage root
354314
std::string normalized_key = normalizePathToStorageRoot(table_location, path);

src/Storages/ObjectStorage/Utils.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ std::unique_ptr<ReadBufferFromFileBase> createReadBuffer(
4747
const LoggerPtr & log,
4848
const std::optional<ReadSettings> & read_settings = std::nullopt);
4949

50-
bool isRelativePath(const std::string & path);
51-
52-
bool isSameStorageSchema(const std::string & schema1, const std::string & schema2);
53-
54-
// Returns lowercased and normalized schema / storage type (e.g. s3:// -> "s3")
55-
std::string extractStorageType(const std::string & path);
56-
5750
std::string makeAbsolutePath(const std::string & table_location, const std::string & path);
5851

5952
// Normalize a path that may be relative to table location to be relative to storage root

0 commit comments

Comments
 (0)