Skip to content

Commit

Permalink
apacheGH-40855: [C++][ORC] Don't use std::filesystem with ORC 2.0.0 o…
Browse files Browse the repository at this point in the history
…r later

If we use `std::filesystem`, we need `-lstdc++fs` with GCC 8 and
`-lc++fs` for clang 7. We don't want to maintain CMake code for GCC
8/clang 7. So this avoids using `std::filesystem` with ORC 2.0.0 or
later.
  • Loading branch information
kou committed Apr 5, 2024
1 parent 139afe5 commit 9987fb6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
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})
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

0 comments on commit 9987fb6

Please sign in to comment.