26 using namespace impala;
27 using namespace impala_udf;
32 : fn_contexts_ptr_(NULL),
49 DCHECK(tracker != NULL);
50 DCHECK(
pool_.get() == NULL);
63 is_clone_? FunctionContext::THREAD_LOCAL : FunctionContext::FRAGMENT_LOCAL;
70 is_clone_? FunctionContext::THREAD_LOCAL : FunctionContext::FRAGMENT_LOCAL;
83 const vector<impala_udf::FunctionContext::TypeDesc>& arg_types,
84 int varargs_buffer_size) {
86 state,
pool_.get(), return_type, arg_types, varargs_buffer_size));
96 (*new_ctx)->pool_.reset(
new MemPool(
pool_->mem_tracker()));
98 (*new_ctx)->fn_contexts_.push_back(
101 (*new_ctx)->fn_contexts_ptr_ = &((*new_ctx)->fn_contexts_[0]);
103 (*new_ctx)->prepared_ =
true;
104 (*new_ctx)->is_clone_ =
true;
106 return root_->
Open(state, *new_ctx, FunctionContext::THREAD_LOCAL);
114 for (
int i = 0; i < ctxs.size(); ++i) {
115 ctxs[i]->FreeLocalAllocations();
120 for (
int i = 0; i < fn_ctxs.size(); ++i) {
121 if (fn_ctxs[i]->impl()->closed())
continue;
122 fn_ctxs[i]->impl()->FreeLocalAllocations();
130 col_val->__isset.string_val =
true;
133 if (value == NULL)
return;
139 col_val->__set_bool_val(*reinterpret_cast<bool*>(value));
142 col_val->__set_byte_val(*reinterpret_cast<int8_t*>(value));
145 col_val->__set_short_val(*reinterpret_cast<int16_t*>(value));
148 col_val->__set_int_val(*reinterpret_cast<int32_t*>(value));
151 col_val->__set_long_val(*reinterpret_cast<int64_t*>(value));
154 col_val->__set_double_val(*reinterpret_cast<float*>(value));
157 col_val->__set_double_val(*reinterpret_cast<double*>(value));
162 col_val->string_val =
166 col_val->string_val =
170 col_val->string_val =
174 DCHECK(
false) <<
"Bad Type: " <<
root_->
type_;
176 col_val->__isset.string_val =
true;
180 string_val =
reinterpret_cast<StringValue*
>(value);
181 tmp.assign(static_cast<char*>(string_val->
ptr), string_val->
len);
182 col_val->string_val.swap(tmp);
183 col_val->__isset.string_val =
true;
187 col_val->string_val.swap(tmp);
188 col_val->__isset.string_val =
true;
193 col_val->__isset.string_val =
true;
static void PrintValue(const void *value, const ColumnType &type, int scale, std::stringstream *stream)
BooleanVal GetBooleanVal(TupleRow *row)
Calls Get*Val on root_.
virtual IntVal GetIntVal(ExprContext *context, TupleRow *)
virtual TimestampVal GetTimestampVal(ExprContext *context, TupleRow *)
virtual SmallIntVal GetSmallIntVal(ExprContext *context, TupleRow *)
static Status Open(const std::vector< ExprContext * > &ctxs, RuntimeState *state)
Convenience function for opening multiple expr trees.
IntVal GetIntVal(TupleRow *row)
Decimal8Value decimal8_val
boost::scoped_ptr< MemPool > pool_
Pool backing fn_contexts_. Counts against the runtime state's UDF mem tracker.
void * GetValue(TupleRow *row)
virtual BooleanVal GetBooleanVal(ExprContext *context, TupleRow *)
Expr * root_
The expr tree this context is for.
virtual DoubleVal GetDoubleVal(ExprContext *context, TupleRow *)
Status Clone(RuntimeState *state, ExprContext **new_context)
TimestampValue timestamp_val
This object has a compatible storage format with boost::ptime.
virtual StringVal GetStringVal(ExprContext *context, TupleRow *)
virtual DecimalVal GetDecimalVal(ExprContext *context, TupleRow *)
static void Close(const std::vector< ExprContext * > &ctxs, RuntimeState *state)
Convenience function for closing multiple expr trees.
void PrintValue(TupleRow *row, std::string *str)
Convenience functions: print value into 'str' or 'stream'. NULL turns into "NULL".
Status Prepare(RuntimeState *state, const RowDescriptor &row_desc, MemTracker *tracker)
std::string DebugString() const
TimestampVal GetTimestampVal(TupleRow *row)
static const char * LLVM_CLASS_NAME
DecimalVal GetDecimalVal(TupleRow *row)
FloatVal GetFloatVal(TupleRow *row)
FunctionContext ** fn_contexts_ptr_
bool is_clone_
Debugging variables.
ObjectPool * obj_pool() const
int GetByteSize() const
Returns the byte size of this type. Returns 0 for variable length types.
TinyIntVal GetTinyIntVal(TupleRow *row)
int len
Only set if type == TYPE_CHAR or type == TYPE_VARCHAR.
StringVal GetStringVal(TupleRow *row)
DoubleVal GetDoubleVal(TupleRow *row)
This is the superclass of all expr evaluation nodes.
virtual FloatVal GetFloatVal(ExprContext *context, TupleRow *)
This class is thread-safe.
const RowDescriptor & row_desc() const
virtual BigIntVal GetBigIntVal(ExprContext *context, TupleRow *)
static TimestampValue FromTimestampVal(const impala_udf::TimestampVal &udf_value)
const ColumnType & type() const
Decimal4Value decimal4_val
void FreeLocalAllocations()
static impala_udf::FunctionContext * CreateContext(RuntimeState *state, MemPool *pool, const impala_udf::FunctionContext::TypeDesc &return_type, const std::vector< impala_udf::FunctionContext::TypeDesc > &arg_types, int varargs_buffer_size=0, bool debug=false)
Create a FunctionContext for a UDF. Caller is responsible for deleting it.
SmallIntVal GetSmallIntVal(TupleRow *row)
Decimal16Value decimal16_val
static char * CharSlotToPtr(void *slot, const ColumnType &type)
virtual TinyIntVal GetTinyIntVal(ExprContext *context, TupleRow *)
std::vector< FunctionContext * > fn_contexts_
int Register(RuntimeState *state, const FunctionContext::TypeDesc &return_type, const std::vector< FunctionContext::TypeDesc > &arg_types, int varargs_buffer_size=0)
const ColumnType type_
analysis is done, types are fixed at this point
static Status Prepare(const std::vector< ExprContext * > &ctxs, RuntimeState *state, const RowDescriptor &row_desc, MemTracker *tracker)
Status Open(RuntimeState *state)
Must be called after calling Prepare(). Should not be called on clones.
BigIntVal GetBigIntVal(TupleRow *row)
void Close(RuntimeState *state)
Closes all FunctionContexts. Must be called on every ExprContext, including clones.