16 #ifndef IMPALA_EXPRS_ANYVAL_UTIL_H
17 #define IMPALA_EXPRS_ANYVAL_UTIL_H
25 using namespace impala_udf;
75 switch (ColumnType::GetDecimalByteSize(t.
precision)) {
87 return HashUtil::FnvHash64(&v.
val, 1, seed);
92 return HashUtil::FnvHash64(&v.
val, 1, seed);
97 return HashUtil::FnvHash64(&v.
val, 2, seed);
102 return HashUtil::FnvHash64(&v.
val, 4, seed);
107 return HashUtil::FnvHash64(&v.
val, 8, seed);
112 return HashUtil::FnvHash64(&v.
val, 4, seed);
117 return HashUtil::FnvHash64(&v.
val, 8, seed);
122 return HashUtil::FnvHash64(v.
ptr, v.
len, seed);
128 return HashUtil::FnvHash64(&tv, 12, seed);
133 switch (ColumnType::GetDecimalByteSize(t.
precision)) {
134 case 4:
return HashUtil::FnvHash64(&v.
val4, 4, seed);
135 case 8:
return HashUtil::FnvHash64(&v.
val8, 8, seed);
136 case 16:
return HashUtil::FnvHash64(&v.
val16, 16, seed);
146 DCHECK_NOTNULL(type);
147 return Equals(TypeDescToColumnType(*type), x, y);
154 return x.val == y.val;
180 return std::string(reinterpret_cast<char*>(v.
ptr), v.
len);
184 StringVal val = FromBuffer(ctx, s.c_str(), s.size());
190 DCHECK(type.
len >= 0);
197 memcpy(result.
ptr, ptr, len);
215 reinterpret_cast<BooleanVal*
>(dst)->val = *reinterpret_cast<const bool*>(slot);
218 reinterpret_cast<TinyIntVal*
>(dst)->val = *reinterpret_cast<const int8_t*>(slot);
221 reinterpret_cast<SmallIntVal*
>(dst)->val = *reinterpret_cast<const int16_t*>(slot);
224 reinterpret_cast<IntVal*
>(dst)->val = *reinterpret_cast<const int32_t*>(slot);
227 reinterpret_cast<BigIntVal*
>(dst)->val = *reinterpret_cast<const int64_t*>(slot);
230 reinterpret_cast<FloatVal*
>(dst)->val = *reinterpret_cast<const float*>(slot);
233 reinterpret_cast<DoubleVal*
>(dst)->val = *reinterpret_cast<const double*>(slot);
240 reinterpret_cast<StringVal*>(dst));
243 DCHECK(type.
len >= 0);
244 DCHECK_LE(sv->
len, type.
len);
249 sv->
ptr =
const_cast<uint8_t*
>(
reinterpret_cast<const uint8_t*
>(slot));
256 reinterpret_cast<TimestampVal*>(dst));
262 *reinterpret_cast<const int32_t*>(slot);
266 *reinterpret_cast<const int64_t*>(slot);
268 #if __BYTE_ORDER == __LITTLE_ENDIAN
270 memcpy(&reinterpret_cast<DecimalVal*>(dst)->val4, slot, type.
GetByteSize());
272 DCHECK(
false) <<
"Not implemented.";
279 DCHECK(
false) <<
"NYI: " << type;
290 template<>
inline bool AnyValUtil::Equals(
299 template<>
inline bool AnyValUtil::Equals(
308 template<>
inline bool AnyValUtil::Equals(
312 if (type.
precision <= ColumnType::MAX_DECIMAL4_PRECISION) {
314 }
else if (type.
precision <= ColumnType::MAX_DECIMAL8_PRECISION) {
int precision
Only valid if type == TYPE_DECIMAL.
AnyVal * CreateAnyVal(ObjectPool *pool, const ColumnType &type)
Creates the corresponding AnyVal subclass for type. The object is added to the pool.
static void TruncateIfNecessary(const ColumnType &type, StringVal *val)
static uint32_t Hash(const BooleanVal &v, const FunctionContext::TypeDesc &, int seed)
static uint32_t Hash(const StringVal &v, const FunctionContext::TypeDesc &, int seed)
static StringVal FromBuffer(FunctionContext *ctx, const char *ptr, int len)
int precision
Only set if type == TYPE_DECIMAL.
static bool Equals(const FunctionContext::TypeDesc *type, const T &x, const T &y)
Templated equality functions. These assume the input values are not NULL.
static uint64_t Hash64(const BigIntVal &v, const FunctionContext::TypeDesc &, int64_t seed)
StringVal ToStringVal(FunctionContext *context, T val)
static uint64_t Hash64(const SmallIntVal &v, const FunctionContext::TypeDesc &, int64_t seed)
This object has a compatible storage format with boost::ptime.
static uint64_t Hash64(const DecimalVal &v, const FunctionContext::TypeDesc &t, int64_t seed)
static uint32_t Hash(const IntVal &v, const FunctionContext::TypeDesc &, int seed)
static uint64_t Hash(const DecimalVal &v, const FunctionContext::TypeDesc &t, int64_t seed)
uint32_t Hash(int seed=0) const
int GetByteSize() const
Returns the byte size of this type. Returns 0 for variable length types.
static uint32_t Hash(const TimestampVal &v, const FunctionContext::TypeDesc &, int seed)
static uint64_t Hash64(const FloatVal &v, const FunctionContext::TypeDesc &, int64_t seed)
int len
Only set if type == TYPE_CHAR or type == TYPE_VARCHAR.
static StringVal FromString(FunctionContext *ctx, const std::string &s)
static uint32_t Hash(const BigIntVal &v, const FunctionContext::TypeDesc &, int seed)
static uint64_t Hash(const IntVal &v)
static uint32_t Hash(const DoubleVal &v, const FunctionContext::TypeDesc &, int seed)
static uint64_t Hash64(const BooleanVal &v, const FunctionContext::TypeDesc &, int64_t seed)
static std::string ToString(const StringVal &v)
static bool Equals(const ColumnType &type, const T &x, const T &y)
static uint32_t Hash(const FloatVal &v, const FunctionContext::TypeDesc &, int seed)
static uint64_t Hash64(const IntVal &v, const FunctionContext::TypeDesc &, int64_t seed)
static uint64_t Hash64(const TimestampVal &v, const FunctionContext::TypeDesc &, int64_t seed)
static uint32_t Hash(const TinyIntVal &v, const FunctionContext::TypeDesc &, int seed)
static uint64_t Hash64(const StringVal &v, const FunctionContext::TypeDesc &, int64_t seed)
static uint64_t Hash64(const TinyIntVal &v, const FunctionContext::TypeDesc &, int64_t seed)
static uint32_t Hash(const SmallIntVal &v, const FunctionContext::TypeDesc &, int seed)
static int AnyValSize(const ColumnType &t)
Returns the byte size of *Val for type t.
static void SetAnyVal(const void *slot, const ColumnType &type, AnyVal *dst)
Utility to put val into an AnyVal struct.
static uint64_t Hash64(const DoubleVal &v, const FunctionContext::TypeDesc &, int64_t seed)