Skip to content
Closed
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
6 changes: 5 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,12 @@ Note that this requires linking Boost statically"

set(BROTLI_MSVC_STATIC_LIB_SUFFIX "-static" CACHE STRING
"Brotli static lib suffix used on Windows with MSVC (default -static)")
set(PROTOBUF_MSVC_STATIC_LIB_SUFFIX "" CACHE STRING
"Protobuf static lib suffix used on Windows with MSVC (default is empty string)")
set(RE2_MSVC_STATIC_LIB_SUFFIX "_static" CACHE STRING
"re2 static lib suffix used on Windows with MSVC (default is _static)")
set(SNAPPY_MSVC_STATIC_LIB_SUFFIX "_static" CACHE STRING
"Snappy static lib suffix used on Windows with MSVC (default is empty string)")
"Snappy static lib suffix used on Windows with MSVC (default is _static)")
set(LZ4_MSVC_STATIC_LIB_SUFFIX "_static" CACHE STRING
"Lz4 static lib suffix used on Windows with MSVC (default _static)")
set(ZSTD_MSVC_STATIC_LIB_SUFFIX "_static" CACHE STRING
Expand Down
26 changes: 15 additions & 11 deletions cpp/build-support/lint_cpp_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ def _strip_comments(line):
return m.group(0)


def _path(*tokens):
return os.path.sep.join(tokens)


def lint_file(path):
fail_rules = [
# rule, error message, rule-specific exclusions list
(lambda x: '<mutex>' in x, 'Uses <mutex>', []),
(lambda x: re.match(_NULLPTR_REGEX, x), 'Uses nullptr', []),
(lambda x: re.match(_RETURN_NOT_OK_REGEX, x),
'Use ARROW_RETURN_NOT_OK in header files',
['arrow/status.h',
[_path('arrow', 'status.h'),
'test',
'arrow/util/hash.h',
'arrow/python/util'])
_path('arrow', 'util', 'hash.h'),
_path('arrow', 'python', 'util')])
]

with open(path) as f:
Expand All @@ -69,14 +73,14 @@ def lint_file(path):


EXCLUSIONS = [
'arrow/python/iterators.h',
'arrow/util/hashing.h',
'arrow/util/macros.h',
'arrow/util/parallel.h',
'arrow/vendored',
'arrow/visitor_inline.h',
'gandiva/cache.h',
'gandiva/jni',
_path('arrow', 'python', 'iterators.h'),
_path('arrow', 'util', 'hashing.h'),
_path('arrow', 'util', 'macros.h'),
_path('arrow', 'util', 'parallel.h'),
_path('arrow', 'vendored'),
_path('arrow', 'visitor_inline.h'),
_path('gandiva', 'cache.h'),
_path('gandiva', 'jni'),
'test',
'internal'
]
Expand Down
9 changes: 4 additions & 5 deletions cpp/cmake_modules/FindProtobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ if (EXISTS "${_protobuf_path}/lib/${CMAKE_LIBRARY_ARCHITECTURE}")
set (lib_dirs "lib/${CMAKE_LIBRARY_ARCHITECTURE}" ${lib_dirs})
endif ()

find_library (PROTOBUF_LIBRARY NAMES protobuf PATHS
find_library (PROTOBUF_LIBRARY NAMES protobuf libprotobuf PATHS
${_protobuf_path}
NO_DEFAULT_PATH
PATH_SUFFIXES ${lib_dirs})

find_library (PROTOC_LIBRARY NAMES protoc PATHS
find_library (PROTOC_LIBRARY NAMES protoc libprotoc PATHS
${_protobuf_path}
NO_DEFAULT_PATH
PATH_SUFFIXES ${lib_dirs})
Expand All @@ -66,7 +66,7 @@ if (PROTOBUF_INCLUDE_DIR AND PROTOBUF_LIBRARY AND PROTOC_LIBRARY AND PROTOBUF_EX
get_filename_component (PROTOBUF_LIBS ${PROTOBUF_LIBRARY} PATH)
set (PROTOBUF_LIB_NAME protobuf)
set (PROTOC_LIB_NAME protoc)
set (PROTOBUF_STATIC_LIB ${PROTOBUF_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${PROTOBUF_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
set (PROTOBUF_STATIC_LIB ${PROTOBUF_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${PROTOBUF_LIB_NAME}${PROTOBUF_MSVC_STATIC_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX})
set (PROTOC_STATIC_LIB ${PROTOBUF_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${PROTOC_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
else ()
set (PROTOBUF_FOUND FALSE)
Expand All @@ -81,7 +81,7 @@ if (PROTOBUF_FOUND)
message (STATUS "Found the Protoc executable: ${PROTOBUF_EXECUTABLE}")
else()
if (_protobuf_path)
set (PROTOBUF_ERR_MSG "Could not find Protobuf. Looked in ${_protobuf_path}.")
set (PROTOBUF_ERR_MSG "Could not find Protobuf. Looked in ${_protobuf_path}")
else ()
set (PROTOBUF_ERR_MSG "Could not find Protobuf in system search paths.")
endif()
Expand All @@ -100,4 +100,3 @@ mark_as_advanced (
PROTOBUF_STATIC_LIB
PROTOC_STATIC_LIB
)

8 changes: 6 additions & 2 deletions cpp/cmake_modules/FindRE2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ if (EXISTS "${_re2_path}/lib/${CMAKE_LIBRARY_ARCHITECTURE}")
set (lib_dirs "lib/${CMAKE_LIBRARY_ARCHITECTURE}" ${lib_dirs})
endif ()

find_library(RE2_STATIC_LIB NAMES libre2${CMAKE_STATIC_LIBRARY_SUFFIX}
set(RE2_LIB_NAME re2)
set(RE2_STATIC_LIB_NAME ${CMAKE_STATIC_LIBRARY_PREFIX}${RE2_LIB_NAME}${RE2_MSVC_STATIC_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX})
set(RE2_SHARED_LIB_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}${RE2_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})

find_library(RE2_STATIC_LIB NAMES ${RE2_STATIC_LIB_NAME}
PATHS ${_re2_path}
NO_DEFAULT_PATH
PATH_SUFFIXES ${lib_dirs}
DOC "Google's re2 regex static library"
)

find_library(RE2_SHARED_LIB NAMES libre2${CMAKE_SHARED_LIBRARY_SUFFIX}
find_library(RE2_SHARED_LIB NAMES ${RE2_SHARED_LIB_NAME}
PATHS ${_re2_path}
NO_DEFAULT_PATH
PATH_SUFFIXES ${lib_dirs}
Expand Down
24 changes: 24 additions & 0 deletions cpp/src/arrow/util/bit-util-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,30 @@ TEST(BitUtil, CountLeadingZeros) {
EXPECT_EQ(BitUtil::CountLeadingZeros(U64(ULLONG_MAX)), 0);
}

TEST(BitUtil, CountTrailingZeros) {
EXPECT_EQ(BitUtil::CountTrailingZeros(U32(0)), 32);
EXPECT_EQ(BitUtil::CountTrailingZeros(U32(1) << 31), 31);
EXPECT_EQ(BitUtil::CountTrailingZeros(U32(1) << 30), 30);
EXPECT_EQ(BitUtil::CountTrailingZeros(U32(1) << 29), 29);
EXPECT_EQ(BitUtil::CountTrailingZeros(U32(1) << 28), 28);
EXPECT_EQ(BitUtil::CountTrailingZeros(U32(8)), 3);
EXPECT_EQ(BitUtil::CountTrailingZeros(U32(4)), 2);
EXPECT_EQ(BitUtil::CountTrailingZeros(U32(2)), 1);
EXPECT_EQ(BitUtil::CountTrailingZeros(U32(1)), 0);
EXPECT_EQ(BitUtil::CountTrailingZeros(U32(ULONG_MAX)), 0);

EXPECT_EQ(BitUtil::CountTrailingZeros(U64(0)), 64);
EXPECT_EQ(BitUtil::CountTrailingZeros(U64(1) << 63), 63);
EXPECT_EQ(BitUtil::CountTrailingZeros(U64(1) << 62), 62);
EXPECT_EQ(BitUtil::CountTrailingZeros(U64(1) << 61), 61);
EXPECT_EQ(BitUtil::CountTrailingZeros(U64(1) << 60), 60);
EXPECT_EQ(BitUtil::CountTrailingZeros(U64(8)), 3);
EXPECT_EQ(BitUtil::CountTrailingZeros(U64(4)), 2);
EXPECT_EQ(BitUtil::CountTrailingZeros(U64(2)), 1);
EXPECT_EQ(BitUtil::CountTrailingZeros(U64(1)), 0);
EXPECT_EQ(BitUtil::CountTrailingZeros(U64(ULLONG_MAX)), 0);
}

#undef U32
#undef U64

Expand Down
43 changes: 43 additions & 0 deletions cpp/src/arrow/util/bit-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#if defined(_MSC_VER)
#include <intrin.h>
#pragma intrinsic(_BitScanReverse)
#pragma intrinsic(_BitScanForward)
#define ARROW_BYTE_SWAP64 _byteswap_uint64
#define ARROW_BYTE_SWAP32 _byteswap_ulong
#else
Expand Down Expand Up @@ -183,6 +184,48 @@ static inline int CountLeadingZeros(uint64_t value) {
#endif
}

static inline int CountTrailingZeros(uint32_t value) {
#if defined(__clang__) || defined(__GNUC__)
if (value == 0) return 32;
return static_cast<int>(__builtin_ctzl(value));
#elif defined(_MSC_VER)
unsigned long index; // NOLINT
if (_BitScanForward(&index, value)) {
return static_cast<int>(index);
} else {
return 32;
}
#else
int bitpos = 0;
while (value != 0) {
value >>= 1;
++bitpos;
}
return bitpos;
#endif
}

static inline int CountTrailingZeros(uint64_t value) {
#if defined(__clang__) || defined(__GNUC__)
if (value == 0) return 64;
return static_cast<int>(__builtin_ctzll(value));
#elif defined(_MSC_VER)
unsigned long index; // NOLINT
if (_BitScanForward64(&index, value)) {
return static_cast<int>(index);
} else {
return 64;
}
#else
int bitpos = 0;
while (value != 0) {
value >>= 1;
++bitpos;
}
return bitpos;
#endif
}

// Returns the minimum number of bits needed to represent an unsigned value
static inline int NumRequiredBits(uint64_t x) { return 64 - CountLeadingZeros(x); }

Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/util/visibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4251)
#else
#pragma GCC diagnostic ignored "-Wattributes"
Expand Down
55 changes: 32 additions & 23 deletions cpp/src/gandiva/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,29 @@ configure_file(bc_file_path.cc.in ${BC_FILE_PATH_CC})
add_definitions(-DGANDIVA_BYTE_COMPILE_FILE_PATH="${GANDIVA_BC_OUTPUT_PATH}")

set(SRC_FILES annotator.cc
bitmap_accumulator.cc
configuration.cc
context_helper.cc
engine.cc
date_utils.cc
expr_decomposer.cc
expr_validator.cc
expression.cc
expression_registry.cc
exported_funcs_registry.cc
filter.cc
function_registry.cc
function_signature.cc
gdv_function_stubs.cc
llvm_generator.cc
llvm_types.cc
like_holder.cc
projector.cc
regex_util.cc
selection_vector.cc
tree_expr_builder.cc
to_date_holder.cc
${BC_FILE_PATH_CC})
bitmap_accumulator.cc
configuration.cc
context_helper.cc
engine.cc
date_utils.cc
expr_decomposer.cc
expr_validator.cc
expression.cc
expression_registry.cc
exported_funcs_registry.cc
filter.cc
function_registry.cc
function_signature.cc
gdv_function_stubs.cc
llvm_generator.cc
llvm_types.cc
like_holder.cc
projector.cc
regex_util.cc
selection_vector.cc
tree_expr_builder.cc
to_date_holder.cc
${BC_FILE_PATH_CC})

set(GANDIVA_SHARED_PRIVATE_LINK_LIBS
arrow_shared
Expand Down Expand Up @@ -95,6 +95,15 @@ ADD_ARROW_LIB(gandiva
SHARED_PRIVATE_LINK_LIBS ${GANDIVA_SHARED_PRIVATE_LINK_LIBS}
STATIC_LINK_LIBS ${GANDIVA_STATIC_LINK_LIBS})

foreach(LIB_TARGET ${GANDIVA_LIBRARIES})
target_compile_definitions(${LIB_TARGET}
PRIVATE GANDIVA_EXPORTING)
endforeach()

if (ARROW_BUILD_STATIC AND WIN32)
target_compile_definitions(gandiva_static PUBLIC GANDIVA_STATIC)
endif()

add_dependencies(gandiva ${GANDIVA_LIBRARIES})

# install for gandiva
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/gandiva/annotator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
#include "gandiva/eval_batch.h"
#include "gandiva/gandiva_aliases.h"
#include "gandiva/logging.h"
#include "gandiva/visibility.h"

namespace gandiva {

/// \brief annotate the arrow fields in an expression, and use that
/// to convert the incoming arrow-format row batch to an EvalBatch.
class Annotator {
class GANDIVA_EXPORT Annotator {
public:
Annotator() : buffer_count_(0), local_bitmap_count_(0) {}

Expand Down
3 changes: 2 additions & 1 deletion cpp/src/gandiva/bitmap_accumulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
#include "gandiva/dex.h"
#include "gandiva/dex_visitor.h"
#include "gandiva/eval_batch.h"
#include "gandiva/visibility.h"

namespace gandiva {

/// \brief Extract bitmap buffer from either the input/buffer vectors or the
/// local validity bitmap, and accumultes them to do the final computation.
class BitMapAccumulator : public DexDefaultVisitor {
class GANDIVA_EXPORT BitMapAccumulator : public DexDefaultVisitor {
public:
explicit BitMapAccumulator(const EvalBatch& eval_batch)
: eval_batch_(eval_batch), all_invalid_(false) {}
Expand Down
16 changes: 7 additions & 9 deletions cpp/src/gandiva/bitmap_accumulator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@
#include <vector>

#include <gtest/gtest.h>

#include "arrow/test-util.h"

#include "gandiva/dex.h"

namespace gandiva {

class TestBitMapAccumulator : public ::testing::Test {
protected:
void FillBitMap(uint8_t* bmap, int nrecords);
void FillBitMap(uint8_t* bmap, uint32_t seed, int nrecords);
void ByteWiseIntersectBitMaps(uint8_t* dst, const std::vector<uint8_t*>& srcs,
int nrecords);
};

void TestBitMapAccumulator::FillBitMap(uint8_t* bmap, int nbytes) {
unsigned int cur = 0;

for (int i = 0; i < nbytes; ++i) {
rand_r(&cur);
bmap[i] = static_cast<uint8_t>(cur % UINT8_MAX);
}
void TestBitMapAccumulator::FillBitMap(uint8_t* bmap, uint32_t seed, int nbytes) {
::arrow::random_bytes(nbytes, seed, bmap);
}

void TestBitMapAccumulator::ByteWiseIntersectBitMaps(uint8_t* dst,
Expand All @@ -61,7 +59,7 @@ TEST_F(TestBitMapAccumulator, TestIntersectBitMaps) {
uint8_t expected_bitmap[length];

for (int i = 0; i < 4; i++) {
FillBitMap(src_bitmaps[i], length);
FillBitMap(src_bitmaps[i], i, length);
}

for (int i = 0; i < 4; i++) {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/gandiva/compiled_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#ifndef GANDIVA_COMPILED_EXPR_H
#define GANDIVA_COMPILED_EXPR_H

#include <llvm/IR/IRBuilder.h>
#include "gandiva/llvm_includes.h"
#include "gandiva/value_validity_pair.h"

namespace gandiva {
Expand Down
Loading