Skip to content

Commit

Permalink
specialize in holder impl for strings
Browse files Browse the repository at this point in the history
  • Loading branch information
pprudhvi committed Oct 26, 2020
1 parent 6e1acc0 commit 54c16e0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cpp/src/arrow/stl_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace stl {

/// \brief A STL allocator delegating allocations to a Arrow MemoryPool
template <class T>
class allocator : public std::allocator<T> {
class allocator {
public:
using value_type = T;
using pointer = T*;
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/gandiva/gdv_function_stubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <string>
#include <vector>

#include "arrow/stl_allocator.h"
#include "arrow/util/value_parsing.h"
#include "gandiva/engine.h"
#include "gandiva/exported_funcs.h"
Expand Down Expand Up @@ -95,7 +94,7 @@ bool gdv_fn_in_expr_lookup_utf8(int64_t ptr, const char* data, int data_len,
}
gandiva::InHolder<std::string>* holder =
reinterpret_cast<gandiva::InHolder<std::string>*>(ptr);
return holder->HasValue(std::string(data, data_len, ::arrow::stl::allocator<char>()));
return holder->HasValue(arrow::util::string_view(data, data_len));
}

int32_t gdv_fn_populate_varlen_vector(int64_t context_ptr, int8_t* data_ptr,
Expand Down
19 changes: 19 additions & 0 deletions cpp/src/gandiva/in_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,23 @@ class InHolder {
std::unordered_set<Type> values_;
};

template <>
class InHolder<std::string> {
public:
explicit InHolder(std::unordered_set<std::string> values) : values_(std::move(values)) {
values_lookup_.max_load_factor(0.25f);
for (const std::string& value : values_) {
values_lookup_.emplace(value);
}
}

bool HasValue(arrow::util::string_view value) const {
return values_lookup_.count(value) == 1;
}

private:
std::unordered_set<arrow::util::string_view> values_lookup_;
const std::unordered_set<std::string> values_;
};

} // namespace gandiva

0 comments on commit 54c16e0

Please sign in to comment.