16 #ifndef IMPALA_RUNTIME_RAW_VALUE_H
17 #define IMPALA_RUNTIME_RAW_VALUE_H
21 #include <boost/functional/hash.hpp>
48 std::stringstream* stream);
56 std::stringstream* stream);
87 static void Write(
const void* src,
const ColumnType& type,
void* dst, uint8_t** buf);
92 static bool Eq(
const void* v1,
const void* v2,
const ColumnType& type);
111 return *
reinterpret_cast<const bool*
>(v1)
112 == *reinterpret_cast<const bool*>(v2);
114 return *
reinterpret_cast<const int8_t*
>(v1)
115 == *reinterpret_cast<const int8_t*>(v2);
117 return *
reinterpret_cast<const int16_t*
>(v1)
118 == *reinterpret_cast<const int16_t*>(v2);
120 return *
reinterpret_cast<const int32_t*
>(v1)
121 == *reinterpret_cast<const int32_t*>(v2);
123 return *
reinterpret_cast<const int64_t*
>(v1)
124 == *reinterpret_cast<const int64_t*>(v2);
126 return *
reinterpret_cast<const float*
>(v1)
127 == *reinterpret_cast<const float*>(v2);
129 return *
reinterpret_cast<const double*
>(v1)
130 == *reinterpret_cast<const double*>(v2);
133 string_value1 =
reinterpret_cast<const StringValue*
>(v1);
134 string_value2 =
reinterpret_cast<const StringValue*
>(v2);
135 return string_value1->
Eq(*string_value2);
138 *reinterpret_cast<const TimestampValue*>(v2);
144 return StringCompare(v1ptr, l1, v2ptr, l2, std::min(l1, l2)) == 0;
161 DCHECK(
false) << type;
201 switch (type.
type ) {
225 std::stringstream* stream) {
231 int old_precision = stream->precision();
232 std::ios_base::fmtflags old_flags = stream->flags();
234 stream->precision(scale);
237 *stream << std::fixed;
243 bool val = *
reinterpret_cast<const bool*
>(value);
244 *stream << (val ?
"true" :
"false");
249 *stream << static_cast<int>(*
reinterpret_cast<const int8_t*
>(value));
252 *stream << *reinterpret_cast<const int16_t*>(value);
255 *stream << *reinterpret_cast<const int32_t*>(value);
258 *stream << *reinterpret_cast<const int64_t*>(value);
262 float val = *
reinterpret_cast<const float*
>(value);
263 if (
LIKELY(std::isfinite(val))) {
265 }
else if (isinf(val)) {
269 *stream << (val < 0 ?
"-Infinity" :
"Infinity");
270 }
else if (isnan(val)) {
277 double val = *
reinterpret_cast<const double*
>(value);
278 if (
LIKELY(std::isfinite(val))) {
280 }
else if (isinf(val)) {
282 *stream << (val < 0 ?
"-Infinity" :
"Infinity");
283 }
else if (isnan(val)) {
290 string_val =
reinterpret_cast<const StringValue*
>(value);
292 stream->write(string_val->
ptr, string_val->
len);
295 *stream << *reinterpret_cast<const TimestampValue*>(value);
303 *stream << reinterpret_cast<const Decimal4Value*>(value)->ToString(type);
306 *stream << reinterpret_cast<const Decimal8Value*>(value)->ToString(type);
309 *stream << reinterpret_cast<const Decimal16Value*>(value)->ToString(type);
312 DCHECK(
false) << type;
318 stream->precision(old_precision);
320 stream->flags(old_flags);
bool Eq(const StringValue &other) const
==
static void PrintValue(const void *value, const ColumnType &type, int scale, std::stringstream *stream)
static void PrintValueAsBytes(const void *value, const ColumnType &type, std::stringstream *stream)
Writes the byte representation of a value to a stringstream character-by-character.
static bool Eq(const void *v1, const void *v2, const ColumnType &type)
A tuple with 0 materialised slots is represented as NULL.
static const int ASCII_PRECISION
Ascii output precision for double/float.
static const uint32_t HASH32_COMBINE_SEED
The magic number (used in hash_combine()) 0x9e3779b9 = 2^32 / (golden ratio).
static uint32_t GetHashValueFnv(const void *v, const ColumnType &type, uint32_t seed)
static int64_t UnpaddedCharLength(const char *cptr, int64_t len)
Returns number of characters in a char array (ignores trailing spaces)
static uint32_t HashCombine32(uint32_t value, uint32_t seed)
static uint32_t Hash(const void *data, int32_t bytes, uint32_t seed)
int GetByteSize() const
Returns the byte size of this type. Returns 0 for variable length types.
int len
Only set if type == TYPE_CHAR or type == TYPE_VARCHAR.
static void Write(const void *value, Tuple *tuple, const SlotDescriptor *slot_desc, MemPool *pool)
static int Compare(const void *v1, const void *v2, const ColumnType &type)
static char * CharSlotToPtr(void *slot, const ColumnType &type)
Useful utility functions for runtime values (which are passed around as void*).
static uint32_t FnvHash64to32(const void *data, int32_t bytes, uint32_t hash)
static int StringCompare(const char *s1, int n1, const char *s2, int n2, int len)
static uint32_t GetHashValue(const void *v, const ColumnType &type, uint32_t seed=0)