15 #ifndef IMPALA_UTIL_KEY_NORMALIZER_INLINE_H_
16 #define IMPALA_UTIL_KEY_NORMALIZER_INLINE_H_
20 #include <boost/date_time/gregorian/gregorian_types.hpp>
32 if (*bytes_left < 1)
return true;
33 *dst = (value == NULL ? null_bit : !null_bit);
38 template <
typename ValueType>
41 if (!is_asc) value = ~value;
42 memcpy(dst, &value,
sizeof(ValueType));
45 template <
typename IntType>
47 const int num_bits = 8 *
sizeof(IntType);
48 IntType sign_bit = (1LL << (num_bits - 1));
50 IntType value = *(
reinterpret_cast<IntType*
>(src));
51 value = (sign_bit ^ value);
52 StoreFinalValue<IntType>(value, dst, is_asc);
55 template <
typename FloatType,
typename ResultType>
57 DCHECK_EQ(
sizeof(FloatType),
sizeof(
ResultType));
59 const int num_bits = 8 *
sizeof(FloatType);
60 const ResultType sign_bit = (1LL << (num_bits - 1));
63 if (value & sign_bit) {
68 value = (sign_bit ^ value);
70 StoreFinalValue<ResultType>(value, dst, is_asc);
77 boost::gregorian::date::ymd_type ymd = timestamp.
date().year_month_day();
78 uint32_t date = ymd.day | (ymd.month << 5) | (ymd.year << 9);
79 StoreFinalValue<uint32_t>(date, dst, is_asc);
82 uint64_t time_ns = timestamp.time_of_day().total_nanoseconds();
83 StoreFinalValue<uint64_t>(time_ns, dst +
sizeof(date), is_asc);
87 uint8_t* value, uint8_t* dst,
int* bytes_left) {
92 if (*bytes_left >= byte_size) {
93 *bytes_left -= byte_size;
101 NormalizeInt<int64_t>(value, dst, is_asc);
104 NormalizeInt<int32_t>(value, dst, is_asc);
107 NormalizeInt<int16_t>(value, dst, is_asc);
110 NormalizeInt<int8_t>(value, dst, is_asc);
114 NormalizeFloat<double, uint64_t>(value, dst, is_asc);
117 NormalizeFloat<float, uint32_t>(value, dst, is_asc);
129 int size = std::min(string_val->
len, *bytes_left);
130 for (
int i = 0; i < size; ++i) {
131 StoreFinalValue<uint8_t>(string_val->
ptr[i], dst + i, is_asc);
135 if (*bytes_left == 0)
return true;
137 StoreFinalValue<uint8_t>(0, dst + size, is_asc);
143 StoreFinalValue<uint8_t>(*
reinterpret_cast<uint8_t*
>(value), dst, is_asc);
146 StoreFinalValue<uint8_t>(0, dst, is_asc);
149 DCHECK(
false) <<
"Value type not supported for normalization";
156 bool is_asc, uint8_t* value, uint8_t* dst,
int* bytes_left) {
157 bool went_over =
WriteNullBit(null_bit, value, dst, bytes_left);
158 if (went_over || value == NULL)
return went_over;
163 int* key_idx_over_budget) {
166 uint8_t* key =
reinterpret_cast<uint8_t*
>(
key_expr_ctxs_[i]->GetValue(row));
171 if (key_idx_over_budget != NULL) *key_idx_over_budget = i;
178 bzero(dst + offset, bytes_left);
bool NormalizeKey(TupleRow *tuple_row, uint8_t *dst, int *key_idx_over_budget=NULL)
static void NormalizeTimestamp(uint8_t *src, uint8_t *dst, bool is_asc)
static void NormalizeFloat(void *src, void *dst, bool is_asc)
static void NormalizeInt(void *src, void *dst, bool is_asc)
static bool NormalizeKeyColumn(const ColumnType &type, uint8_t null_bit, bool is_asc, uint8_t *value, uint8_t *dst, int *bytes_left)
int GetByteSize() const
Returns the byte size of this type. Returns 0 for variable length types.
static int64_t ToBigEndian(int64_t value)
static bool WriteNormalizedKey(const ColumnType &type, bool is_asc, uint8_t *value, uint8_t *dst, int *bytes_left)
std::vector< ExprContext * > key_expr_ctxs_
uint8_t offset[7 *64-sizeof(uint64_t)]
static void StoreFinalValue(ValueType value, void *dst, bool is_asc)
std::vector< bool > is_asc_
static bool WriteNullBit(uint8_t null_bit, uint8_t *value, uint8_t *dst, int *bytes_left)
Returns true if we went over the max key size while writing the null bit.
std::vector< bool > nulls_first_
const boost::gregorian::date & date() const