Skip to content

Commit 5894d3e

Browse files
committed
fix windows linking error
Signed-off-by: Junwang Zhao <[email protected]>
1 parent 12ae034 commit 5894d3e

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

src/iceberg/arrow/arrow_error_transform_internal.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ inline ErrorKind ToErrorKind(const ::arrow::Status& status) {
3939
#define ICEBERG_INTERNAL_ASSIGN_OR_RETURN_IMPL(result_name, lhs, rexpr, error_transform) \
4040
auto&& result_name = (rexpr); \
4141
if (!result_name.ok()) { \
42-
return unexpected( \
43-
Error(error_transform(result_name.status()), result_name.status().ToString())); \
42+
return unexpected<Error>{{.kind = error_transform(result_name.status()), \
43+
.message = result_name.status().ToString()}}; \
4444
} \
4545
lhs = std::move(result_name).ValueOrDie();
4646

@@ -53,7 +53,8 @@ inline ErrorKind ToErrorKind(const ::arrow::Status& status) {
5353
do { \
5454
auto&& _status = (expr); \
5555
if (!_status.ok()) { \
56-
return unexpected(Error(internal::ToErrorKind(_status), _status.ToString())); \
56+
return unexpected<Error>{ \
57+
{.kind = internal::ToErrorKind(_status), .message = _status.ToString()}}; \
5758
} \
5859
} while (0)
5960

src/iceberg/arrow/io/local_file_io.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ expected<std::string, Error> LocalFileIO::ReadFile(const std::string& file_locat
5050
expected<void, Error> LocalFileIO::WriteFile(const std::string& file_location,
5151
std::string_view content, bool overwrite) {
5252
if (!overwrite && FileExists(file_location)) {
53-
return unexpected(Error(ErrorKind::kAlreadyExists, ""));
53+
return unexpected(
54+
Error(ErrorKind::kAlreadyExists, std::format("File {} exists", file_location)));
5455
}
5556
ICEBERG_INTERNAL_ASSIGN_OR_RETURN(auto file,
5657
local_fs_->OpenOutputStream(file_location));

src/iceberg/demo.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "iceberg/avro.h" // include to export symbols
2323
#include "iceberg/catalog.h"
24+
#include "iceberg/file_io.h"
2425
#include "iceberg/location_provider.h"
2526
#include "iceberg/table.h"
2627
#include "iceberg/transaction.h"

src/iceberg/error.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,14 @@ enum class ErrorKind {
3535
kCommitStateUnknown,
3636
kInvalidArgument,
3737
kIOError,
38+
kNotImplemented,
3839
kUnknownError,
3940
};
4041

4142
/// \brief Error with a kind and a message.
4243
struct ICEBERG_EXPORT [[nodiscard]] Error {
4344
ErrorKind kind;
4445
std::string message;
45-
46-
explicit Error(ErrorKind kind, std::string message)
47-
: kind(kind), message(std::move(message)) {};
4846
};
4947

5048
} // namespace iceberg

src/iceberg/file_io.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ class ICEBERG_EXPORT FileIO {
4747
/// \return The content of the file if the read succeeded, an error code if the read
4848
/// failed.
4949
virtual expected<std::string, Error> ReadFile(const std::string& file_location,
50-
std::optional<size_t> length) = 0;
50+
std::optional<size_t> length) {
51+
// The following line is to avoid Windows linker error LNK2019.
52+
// If this function is defined as pure virtual function, the `unexpected<Error>` will
53+
// not be instantiated and exported in libiceberg.
54+
return unexpected<Error>{
55+
{.kind = ErrorKind::kNotImplemented, .message = "ReadFile not implemented"}};
56+
}
5157

5258
/// \brief Write the given content to the file at the given location.
5359
///
@@ -57,7 +63,13 @@ class ICEBERG_EXPORT FileIO {
5763
/// file exists.
5864
/// \return void if the write succeeded, an error code if the write failed.
5965
virtual expected<void, Error> WriteFile(const std::string& file_location,
60-
std::string_view content, bool overwrite) = 0;
66+
std::string_view content, bool overwrite) {
67+
// The following line is to avoid Windows linker error LNK2019.
68+
// If this function is defined as pure virtual function, the `unexpected<Error>` will
69+
// not be instantiated and exported in libiceberg.
70+
return unexpected<Error>{
71+
{.kind = ErrorKind::kNotImplemented, .message = "WriteFile not implemented"}};
72+
}
6173

6274
/// \brief Delete a file at the given location.
6375
///

test/local_file_io_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class LocalFileIOTest : public testing::Test {
3535
std::filesystem::path tmpfile = std::filesystem::temp_directory_path() / "123.txt";
3636
};
3737

38-
TEST_F(LocalFileIOTest, readWriteFile) {
38+
TEST_F(LocalFileIOTest, ReadWriteFile) {
3939
auto read_res = file_io_->ReadFile(tmpfile.string(), 1024);
4040
EXPECT_EQ(read_res.error().kind, iceberg::ErrorKind::kInvalidArgument);
4141

@@ -49,7 +49,7 @@ TEST_F(LocalFileIOTest, readWriteFile) {
4949
EXPECT_EQ(read_res.value(), "hello world");
5050
}
5151

52-
TEST_F(LocalFileIOTest, deleteFile) {
52+
TEST_F(LocalFileIOTest, DeleteFile) {
5353
auto del_res = file_io_->DeleteFile(tmpfile.string());
5454
EXPECT_TRUE(del_res.has_value());
5555

0 commit comments

Comments
 (0)