Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

[NSE-610] support big keys in hashagg #1078

Merged
merged 1 commit into from
Aug 23, 2022
Merged
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
18 changes: 13 additions & 5 deletions native-sql-engine/cpp/src/third_party/row_wise_memory/unsafe_row.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

#include "third_party/row_wise_memory/native_memory.h"

#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)

#define TEMP_UNSAFEROW_BUFFER_SIZE 8192
static constexpr uint8_t kBitmask[] = {1, 2, 4, 8, 16, 32, 64, 128};

Expand Down Expand Up @@ -103,22 +106,27 @@ using is_number_alike =

template <typename T, typename std::enable_if_t<is_number_alike<T>::value>* = nullptr>
static inline void appendToUnsafeRow(UnsafeRow* row, const int& index, const T& val) {
if (unlikely(row->cursor + sizeof(T) > TEMP_UNSAFEROW_BUFFER_SIZE))
row->data =
(char*)nativeRealloc(row->data, 2 * TEMP_UNSAFEROW_BUFFER_SIZE, MEMTYPE_ROW);
*((T*)(row->data + row->cursor)) = val;
row->cursor += sizeof(T);
}

static inline void appendToUnsafeRow(UnsafeRow* row, const int& index,
const std::string& str) {
memcpy(row->data + row->cursor, str.data(), str.size());
row->cursor += str.size();
}
static inline void appendToUnsafeRow(UnsafeRow* row, const int& index,
arrow::util::string_view str) {
if (unlikely(row->cursor + str.size() > TEMP_UNSAFEROW_BUFFER_SIZE))
row->data =
(char*)nativeRealloc(row->data, 2 * TEMP_UNSAFEROW_BUFFER_SIZE, MEMTYPE_ROW);
memcpy(row->data + row->cursor, str.data(), str.size());
row->cursor += str.size();
}

static inline void appendToUnsafeRow(UnsafeRow* row, const int& index,
const arrow::Decimal128& dcm) {
if (unlikely(row->cursor + 16 > TEMP_UNSAFEROW_BUFFER_SIZE))
row->data =
(char*)nativeRealloc(row->data, 2 * TEMP_UNSAFEROW_BUFFER_SIZE, MEMTYPE_ROW);
int numBytes = 16;
zeroOutPaddingBytes(row, numBytes);
memcpy(row->data + row->cursor, dcm.ToBytes().data(), numBytes);
Expand Down