Skip to content

Commit

Permalink
cmake: arrow: temporary workaround for 0.8.0+ build support
Browse files Browse the repository at this point in the history
Use static RecordBatch constructor from Arrow >= 0.8.0

We internally need to support building with 0.7.x for a bit longer, so
CMake will attempt to figure out which API to use and then #ifdef in the
correct one.

Official releases will continue to be built against 0.7.1 until we debug
a few issues with 0.9.0+. This commit is a workaround so we can easily
continue to build with 0.7.1 while testing 0.9.0+.
  • Loading branch information
andrewseidl committed Jun 12, 2018
1 parent 981cbf6 commit 7251443
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -233,6 +233,9 @@ add_subdirectory(ThirdParty/googletest)
# Arrow
find_package(Arrow REQUIRED)
add_definitions("-DARROW_NO_DEPRECATED_API")
if(HAVE_ARROW_STATIC_RECORDBATCH_CTOR)
add_definitions("-DHAVE_ARROW_STATIC_RECORDBATCH_CTOR")
endif()
include_directories(${Arrow_INCLUDE_DIRS})

# RapidJSON
Expand Down
10 changes: 8 additions & 2 deletions QueryEngine/ResultSetConversion.cpp
Expand Up @@ -46,6 +46,12 @@ typedef boost::variant<std::vector<bool>,
std::vector<std::string>>
ValueArray;

#ifdef HAVE_ARROW_STATIC_RECORDBATCH_CTOR
#define ARROW_RECORDBATCH_MAKE arrow::RecordBatch::Make
#else
#define ARROW_RECORDBATCH_MAKE std::make_shared<arrow::RecordBatch>
#endif

namespace {

bool is_dict_enc_str(const SQLTypeInfo& ti) {
Expand Down Expand Up @@ -347,7 +353,7 @@ std::shared_ptr<arrow::RecordBatch> ResultSet::getArrowBatch(const std::shared_p

const auto entry_count = entryCount();
if (!entry_count) {
return std::make_shared<arrow::RecordBatch>(schema, 0, result_columns);
return ARROW_RECORDBATCH_MAKE(schema, 0, result_columns);
}
const auto col_count = colCount();
size_t row_count = 0;
Expand Down Expand Up @@ -460,7 +466,7 @@ std::shared_ptr<arrow::RecordBatch> ResultSet::getArrowBatch(const std::shared_p
for (size_t i = 0; i < col_count; ++i) {
result_columns.push_back(builders[i].finish());
}
return std::make_shared<arrow::RecordBatch>(schema, row_count, result_columns);
return ARROW_RECORDBATCH_MAKE(schema, row_count, result_columns);
}

std::shared_ptr<arrow::RecordBatch> ResultSet::convertToArrow(const std::vector<std::string>& col_names,
Expand Down
6 changes: 6 additions & 0 deletions cmake/Modules/FindArrow.cmake
Expand Up @@ -73,5 +73,11 @@ set(Arrow_GPU_LIBRARIES ${Arrow_GPU_LIBRARY})
set(Arrow_LIBRARY_DIRS ${Arrow_LIBRARY_DIR})
set(Arrow_INCLUDE_DIRS ${Arrow_LIBRARY_DIR}/../include)

try_compile(HAVE_ARROW_STATIC_RECORDBATCH_CTOR
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/cmake/Modules/arrow_static_recordbatch.cpp
COMPILE_DEFINITIONS -I${Arrow_INCLUDE_DIRS}
LINK_LIBRARIES ${Arrow_LIBRARY})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Arrow REQUIRED_VARS Arrow_LIBRARY)
10 changes: 10 additions & 0 deletions cmake/Modules/arrow_static_recordbatch.cpp
@@ -0,0 +1,10 @@
#include "arrow/api.h"
#include "arrow/io/memory.h"
#include "arrow/ipc/api.h"

int main(int argc, char** argv) {
std::vector<std::shared_ptr<arrow::Array>> result_columns;
std::shared_ptr<arrow::Schema> schema;
auto record = arrow::RecordBatch::Make(schema, 0, result_columns);
// auto record = std::make_shared<arrow::RecordBatch>(schema, 0, result_columns);
}

0 comments on commit 7251443

Please sign in to comment.