From bb364a7a983b27abc5222386e97ff1f11e0db0d8 Mon Sep 17 00:00:00 2001 From: Sunyi Xu <94rbmyftn9@privaterelay.appleid.com> Date: Tue, 24 Nov 2026 01:15:26 +0800 Subject: [PATCH 1/2] fix: accept single-slash local file URIs in Arrow FileIO Generated-by: OpenAI Codex (GPT-6.2 Sol, xhigh) --- src/iceberg/arrow/arrow_io.cc | 34 ++++++++++++++++--------------- src/iceberg/test/arrow_io_test.cc | 18 ++++++++++++++++ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/iceberg/arrow/arrow_io.cc b/src/iceberg/arrow/arrow_io.cc index 998f8c5ce8..7c9a990435 100644 --- a/src/iceberg/arrow/arrow_io.cc +++ b/src/iceberg/arrow/arrow_io.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include #include "iceberg/arrow/arrow_io_internal.h" @@ -484,26 +486,26 @@ class ArrowOutputFile : public OutputFile { } // namespace Result ArrowFileSystemFileIO::ResolvePath(const std::string& file_location) { - const auto pos = file_location.find("://"); - if (pos == std::string::npos) { - return file_location; + const std::string_view uri(file_location); + if (::arrow::internal::AsciiEqualsCaseInsensitive(uri.substr(0, 6), "file:/") && + !uri.substr(6).starts_with('/')) { + ICEBERG_ARROW_ASSIGN_OR_RETURN( + auto path, arrow_fs_->PathFromUri("file:" + file_location.substr(5))); + return path; } - auto path = arrow_fs_->PathFromUri(file_location); - if (path.ok()) { - return std::move(path).ValueOrDie(); + const auto pos = uri.find("://"); + if (pos == uri.npos) { + return file_location; } - - // Foreign alias (s3a/s3n): validate via Arrow's parser, then percent-decode the - // scheme-less key (substring keeps a Windows drive letter's ':' that host() drops). - if (auto parsed = ::arrow::util::Uri::FromString(file_location); !parsed.ok()) { - const auto& status = parsed.status(); - return ::iceberg::unexpected{ - {.kind = ToErrorKind(status), .message = status.ToString()}}; + if (auto path = arrow_fs_->PathFromUri(file_location); path.ok()) { + return std::move(path).ValueOrDie(); } - std::string bucket_key = file_location.substr(pos + 3); - bucket_key = bucket_key.substr(0, bucket_key.find_first_of("?#")); - return ::arrow::util::UriUnescape(bucket_key); + // Keep drive letters in alias keys. + ::arrow::util::Uri parsed; + ICEBERG_ARROW_RETURN_NOT_OK(parsed.Parse(file_location)); + const auto key = uri.substr(pos + 3); + return ::arrow::util::UriUnescape(key.substr(0, key.find_first_of("?#"))); } Result> OpenArrowInputStream( diff --git a/src/iceberg/test/arrow_io_test.cc b/src/iceberg/test/arrow_io_test.cc index 7bc9ebba53..d7dbbe8178 100644 --- a/src/iceberg/test/arrow_io_test.cc +++ b/src/iceberg/test/arrow_io_test.cc @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "iceberg/arrow/arrow_io_internal.h" @@ -356,6 +357,23 @@ TEST_F(LocalFileIOTest, ReadWriteFile) { EXPECT_THAT(read_res, HasValue(::testing::Eq("hello world"))); } +TEST_F(LocalFileIOTest, ReadsLocalFileUriWithOneOrThreeSlashes) { + ASSERT_THAT(file_io_->WriteFile(temp_filepath_, "metadata bytes"), IsOk()); + const auto uri = ::arrow::util::UriFromAbsolutePath(temp_filepath_); + ASSERT_TRUE(uri.ok()) << uri.status(); + ASSERT_TRUE(uri->starts_with("file:///")); + + for (const auto prefix : {"file:", "FiLe:", "file://"}) { + EXPECT_THAT(file_io_->ReadFile(prefix + uri->substr(7), std::nullopt), + HasValue(::testing::Eq("metadata bytes"))); + } +} + +TEST_F(LocalFileIOTest, RejectsMalformedShortFileUri) { + EXPECT_THAT(file_io_->ReadFile("file:/tmp/%ZZ", std::nullopt), + HasErrorMessage("Cannot parse URI")); +} + TEST_F(LocalFileIOTest, DeleteFile) { auto write_res = file_io_->WriteFile(temp_filepath_, "hello world"); EXPECT_THAT(write_res, IsOk()); From 4e1f21f8e9dbf3e6ddb814eacf71912da29dede1 Mon Sep 17 00:00:00 2001 From: Sunyi Xu <94rbmyftn9@privaterelay.appleid.com> Date: Tue, 1 Dec 2026 18:31:23 +0800 Subject: [PATCH 2/2] fix: align local file URI handling in Arrow FileIO Use the Iceberg string helper and report backend URI parser errors consistently for one- and three-slash local paths. Cover mixed-case URIs and backend rejection. Prepared and tested with OpenAI Codex. Reviewed by the PR author before this update. --- src/iceberg/arrow/arrow_io.cc | 8 +++++--- src/iceberg/test/arrow_io_test.cc | 28 ++++++++++++++++++---------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/iceberg/arrow/arrow_io.cc b/src/iceberg/arrow/arrow_io.cc index 7c9a990435..b821e89620 100644 --- a/src/iceberg/arrow/arrow_io.cc +++ b/src/iceberg/arrow/arrow_io.cc @@ -31,13 +31,13 @@ #include #include #include -#include #include #include "iceberg/arrow/arrow_io_internal.h" #include "iceberg/arrow/arrow_io_util.h" #include "iceberg/arrow/arrow_status_internal.h" #include "iceberg/util/macros.h" +#include "iceberg/util/string_util.h" namespace iceberg::arrow { @@ -487,8 +487,10 @@ class ArrowOutputFile : public OutputFile { Result ArrowFileSystemFileIO::ResolvePath(const std::string& file_location) { const std::string_view uri(file_location); - if (::arrow::internal::AsciiEqualsCaseInsensitive(uri.substr(0, 6), "file:/") && - !uri.substr(6).starts_with('/')) { + // Absolute local file URIs have one slash or an empty authority (three slashes). + // Do not fall back to alias handling when the filesystem rejects either form. + if (StringUtils::EqualsIgnoreCase(uri.substr(0, 6), "file:/") && + (!uri.substr(6).starts_with('/') || uri.substr(6).starts_with("//"))) { ICEBERG_ARROW_ASSIGN_OR_RETURN( auto path, arrow_fs_->PathFromUri("file:" + file_location.substr(5))); return path; diff --git a/src/iceberg/test/arrow_io_test.cc b/src/iceberg/test/arrow_io_test.cc index d7dbbe8178..fdb4254ebf 100644 --- a/src/iceberg/test/arrow_io_test.cc +++ b/src/iceberg/test/arrow_io_test.cc @@ -363,17 +363,12 @@ TEST_F(LocalFileIOTest, ReadsLocalFileUriWithOneOrThreeSlashes) { ASSERT_TRUE(uri.ok()) << uri.status(); ASSERT_TRUE(uri->starts_with("file:///")); - for (const auto prefix : {"file:", "FiLe:", "file://"}) { + for (const auto prefix : {"file:", "FiLe:", "file://", "FiLe://"}) { EXPECT_THAT(file_io_->ReadFile(prefix + uri->substr(7), std::nullopt), HasValue(::testing::Eq("metadata bytes"))); } } -TEST_F(LocalFileIOTest, RejectsMalformedShortFileUri) { - EXPECT_THAT(file_io_->ReadFile("file:/tmp/%ZZ", std::nullopt), - HasErrorMessage("Cannot parse URI")); -} - TEST_F(LocalFileIOTest, DeleteFile) { auto write_res = file_io_->WriteFile(temp_filepath_, "hello world"); EXPECT_THAT(write_res, IsOk()); @@ -477,10 +472,23 @@ TEST_F(LocalFileIOTest, ResolvesForeignSchemeToUnderlyingPath) { EXPECT_THAT(with_query, HasValue(::testing::Eq("hello world"))); } -TEST_F(LocalFileIOTest, PropagatesNonSchemeMismatchUriError) { - auto read_res = file_io_->ReadFile("file:///tmp/%ZZ", std::nullopt); - EXPECT_THAT(read_res, IsError(ErrorKind::kUnknownError)); - EXPECT_THAT(read_res, HasErrorMessage("Cannot parse URI")); +TEST_F(LocalFileIOTest, RejectsMalformedLocalFileUris) { + for (const auto uri : {"file:/tmp/%ZZ", "file:///tmp/%ZZ"}) { + SCOPED_TRACE(uri); + auto read_res = file_io_->ReadFile(uri, std::nullopt); + EXPECT_THAT(read_res, IsError(ErrorKind::kUnknownError)); + EXPECT_THAT(read_res, HasErrorMessage("Cannot parse URI")); + } +} + +TEST(ArrowFileIOTest, PropagatesBackendRejectionOfLocalFileUris) { + auto file_io = arrow::ArrowFileSystemFileIO::MakeMockFileIO(); + for (const auto uri : + {"file:/example", "FiLe:/example", "file:///example", "FiLe:///example"}) { + SCOPED_TRACE(uri); + EXPECT_THAT(file_io->NewInputFile(uri), + HasErrorMessage("The filesystem expected a URI with one of the schemes")); + } } TEST_F(LocalFileIOTest, FallbackDecodesPercentEncodingInKey) {