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
2 changes: 1 addition & 1 deletion cpp/src/gandiva/gdv_function_stubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,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));
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
27 changes: 27 additions & 0 deletions cpp/src/gandiva/in_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>
#include <unordered_set>

#include "arrow/util/hashing.h"
#include "gandiva/arrow.h"
#include "gandiva/gandiva_aliases.h"

Expand All @@ -42,4 +43,30 @@ 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:
struct string_view_hash {
public:
std::size_t operator()(arrow::util::string_view v) const {
return arrow::internal::ComputeStringHash<0>(v.data(), v.length());
}
};

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

} // namespace gandiva