Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-40855: [C++][ORC] Fix std::filesystem related link error with ORC 2.0.0 or later #41023

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cpp/cmake_modules/FindorcAlt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ endif()
find_package(orc ${find_package_args})
if(orc_FOUND)
set(orcAlt_FOUND TRUE)
set(orcAlt_VERSION ${orc_VERSION})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with conan?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope so...
Do you know conan's ORC recipe provide valid(?) CMake package for ORC?

(BTW, is there a plan that ORC provides its CMake package?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know conan's ORC recipe provide valid(?) CMake package for ORC?

I suppose it does. It was added by me: https://github.com/conan-io/conan-center-index/blob/master/recipes/orc/all/conanfile.py#L145

is there a plan that ORC provides its CMake package?

I'm not sure if I understand the question correctly, do you mean the ORC community provides an official FindOrc.cmake file or something similar?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
(orcConfig.cmake will be better than FindOrc.cmake.)

FYI: Apache Arrow provides ArrowConfig.cmake, ArrowFlightConfig.cmake, ParquetConfig.cmake and so on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let me investigate how does it work and add it to ORC.

return()
endif()

Expand All @@ -51,8 +52,17 @@ else()
NAMES orc/orc-config.hh
PATH_SUFFIXES ${ARROW_INCLUDE_PATH_SUFFIXES})
endif()
if(ORC_INCLUDE_DIR)
file(READ "${ORC_INCLUDE_DIR}/orc/orc-config.hh" ORC_CONFIG_HH_CONTENT)
string(REGEX MATCH "#define ORC_VERSION \"[0-9.]+\"" ORC_VERSION_DEFINITION
"${ORC_CONFIG_HH_CONTENT}")
string(REGEX MATCH "[0-9.]+" ORC_VERSION "${ORC_VERSION_DEFINITION}")
endif()

find_package_handle_standard_args(orcAlt REQUIRED_VARS ORC_STATIC_LIB ORC_INCLUDE_DIR)
find_package_handle_standard_args(
orcAlt
REQUIRED_VARS ORC_STATIC_LIB ORC_INCLUDE_DIR
VERSION_VAR ORC_VERSION)

if(orcAlt_FOUND)
if(NOT TARGET orc::orc)
Expand Down
14 changes: 14 additions & 0 deletions cpp/cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4559,6 +4559,15 @@ macro(build_orc)
endif()
target_link_libraries(orc::orc INTERFACE ${CMAKE_DL_LIBS})
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9")
target_link_libraries(orc::orc INTERFACE stdc++fs)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8")
target_link_libraries(orc::orc INTERFACE c++fs)
endif()
endif()

add_dependencies(orc::orc orc_ep)

Expand All @@ -4568,6 +4577,11 @@ endmacro()
if(ARROW_ORC)
resolve_dependency(orc HAVE_ALT TRUE)
target_link_libraries(orc::orc INTERFACE ${ARROW_PROTOBUF_LIBPROTOBUF})
if(ORC_VENDORED)
set(ARROW_ORC_VERSION ${ARROW_ORC_BUILD_VERSION})
else()
set(ARROW_ORC_VERSION ${orcAlt_VERSION})
endif()
message(STATUS "Found ORC static library: ${ORC_STATIC_LIB}")
message(STATUS "Found ORC headers: ${ORC_INCLUDE_DIR}")
endif()
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,10 @@ if(ARROW_ORC)
adapters/orc/util.cc)
foreach(ARROW_ORC_TARGET ${ARROW_ORC_TARGETS})
target_link_libraries(${ARROW_ORC_TARGET} PRIVATE orc::orc)
if(ARROW_ORC_VERSION VERSION_LESS "2.0.0")
target_compile_definitions(${ARROW_ORC_TARGET}
PRIVATE ARROW_ORC_NEED_TIME_ZONE_DATABASE_CHECK)
endif()
endforeach()
else()
set(ARROW_ORC_TARGET_SHARED)
Expand Down
14 changes: 10 additions & 4 deletions cpp/src/arrow/adapters/orc/adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
#include "arrow/adapters/orc/adapter.h"

#include <algorithm>
#include <filesystem>
#include <list>
#include <memory>
#include <sstream>
#include <string>
#include <vector>

#ifdef ARROW_ORC_NEED_TIME_ZONE_DATABASE_CHECK
#include <filesystem>
#endif

#include "arrow/adapters/orc/util.h"
#include "arrow/builder.h"
#include "arrow/io/interfaces.h"
Expand Down Expand Up @@ -183,11 +186,9 @@ liborc::RowReaderOptions DefaultRowReaderOptions() {
return options;
}

#ifdef ARROW_ORC_NEED_TIME_ZONE_DATABASE_CHECK
// Proactively check timezone database availability for ORC versions older than 2.0.0
Status CheckTimeZoneDatabaseAvailability() {
if (GetOrcMajorVersion() >= 2) {
return Status::OK();
}
auto tz_dir = std::getenv("TZDIR");
bool is_tzdb_avaiable = tz_dir != nullptr
? std::filesystem::exists(tz_dir)
Expand All @@ -200,6 +201,7 @@ Status CheckTimeZoneDatabaseAvailability() {
}
return Status::OK();
}
#endif

} // namespace

Expand Down Expand Up @@ -559,7 +561,9 @@ ORCFileReader::~ORCFileReader() {}

Result<std::unique_ptr<ORCFileReader>> ORCFileReader::Open(
const std::shared_ptr<io::RandomAccessFile>& file, MemoryPool* pool) {
#ifdef ARROW_ORC_NEED_TIME_ZONE_DATABASE_CHECK
RETURN_NOT_OK(CheckTimeZoneDatabaseAvailability());
#endif
auto result = std::unique_ptr<ORCFileReader>(new ORCFileReader());
RETURN_NOT_OK(result->impl_->Open(file, pool));
return std::move(result);
Expand Down Expand Up @@ -826,7 +830,9 @@ ORCFileWriter::ORCFileWriter() { impl_.reset(new ORCFileWriter::Impl()); }

Result<std::unique_ptr<ORCFileWriter>> ORCFileWriter::Open(
io::OutputStream* output_stream, const WriteOptions& writer_options) {
#ifdef ARROW_ORC_NEED_TIME_ZONE_DATABASE_CHECK
RETURN_NOT_OK(CheckTimeZoneDatabaseAvailability());
#endif
std::unique_ptr<ORCFileWriter> result =
std::unique_ptr<ORCFileWriter>(new ORCFileWriter());
Status status = result->impl_->Open(output_stream, writer_options);
Expand Down
Loading