Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
|
#include <udf-internal.h>
Public Member Functions | |
FunctionContextImpl (impala_udf::FunctionContext *parent) | |
void | Close () |
impala_udf::FunctionContext * | Clone (MemPool *pool) |
uint8_t * | AllocateLocal (int byte_size) |
void | FreeLocalAllocations () |
Frees all allocations returned by AllocateLocal(). More... | |
void | SetConstantArgs (const std::vector< impala_udf::AnyVal * > &constant_args) |
Sets constant_args_. The AnyVal* values are owned by the caller. More... | |
uint8_t * | varargs_buffer () |
std::vector < impala_udf::AnyVal * > * | staging_input_vals () |
bool | debug () |
bool | closed () |
int64_t | num_updates () const |
int64_t | num_removes () const |
void | set_num_updates (int64_t n) |
void | set_num_removes (int64_t n) |
void | IncrementNumUpdates (int64_t n=1) |
void | IncrementNumRemoves (int64_t n=1) |
RuntimeState * | state () |
Static Public Member Functions | |
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. More... | |
static impala_udf::FunctionContext * | CreateContext (RuntimeState *state, MemPool *pool, const impala_udf::FunctionContext::TypeDesc &intermediate_type, const impala_udf::FunctionContext::TypeDesc &return_type, const std::vector< impala_udf::FunctionContext::TypeDesc > &arg_types, int varargs_buffer_size=0, bool debug=false) |
Static Public Attributes | |
static const char * | LLVM_FUNCTIONCONTEXT_NAME |
Private Attributes | |
uint8_t * | varargs_buffer_ |
int | varargs_buffer_size_ |
impala_udf::FunctionContext * | context_ |
Parent context object. Not owned. More... | |
FreePool * | pool_ |
Pool to service allocations from. More... | |
RuntimeState * | state_ |
bool | debug_ |
If true, indicates this is a debug context which will do additional validation. More... | |
impala_udf::FunctionContext::ImpalaVersion | version_ |
std::string | error_msg_ |
Empty if there's no error. More... | |
int64_t | num_warnings_ |
The number of warnings reported. More... | |
int64_t | num_updates_ |
The number of calls to Update()/Remove(). More... | |
int64_t | num_removes_ |
std::map< uint8_t *, int > | allocations_ |
std::vector< uint8_t * > | local_allocations_ |
Allocations owned by Impala. More... | |
void * | thread_local_fn_state_ |
The function state accessed via FunctionContext::Get/SetFunctionState() More... | |
void * | fragment_local_fn_state_ |
int64_t | external_bytes_tracked_ |
impala_udf::FunctionContext::TypeDesc | intermediate_type_ |
Type descriptor for the intermediate type of a UDA. Set to INVALID_TYPE for UDFs. More... | |
impala_udf::FunctionContext::TypeDesc | return_type_ |
Type descriptor for the return type of the function. More... | |
std::vector < impala_udf::FunctionContext::TypeDesc > | arg_types_ |
Type descriptors for each argument of the function. More... | |
std::vector< impala_udf::AnyVal * > | constant_args_ |
std::vector< impala_udf::AnyVal * > | staging_input_vals_ |
bool | closed_ |
Indicates whether this context has been closed. Used for verification/debugging. More... | |
Friends | |
class | impala_udf::FunctionContext |
This class actually implements the interface of FunctionContext. This is split to hide the details from the external header. Note: The actual user code does not include this file.
Definition at line 38 of file udf-internal.h.
FunctionContextImpl::FunctionContextImpl | ( | impala_udf::FunctionContext * | parent | ) |
uint8_t * FunctionContextImpl::AllocateLocal | ( | int | byte_size | ) |
Allocates a buffer of 'byte_size' with "local" memory management. These allocations are not freed one by one but freed as a pool by FreeLocalAllocations() This is used where the lifetime of the allocation is clear. For UDFs, the allocations can be freed at the row level. TODO: free them at the batch level and save some copies?
Definition at line 386 of file udf.cc.
References impala::FreePool::Allocate(), closed_, context_, local_allocations_, pool_, and VLOG_ROW.
Referenced by impala::CastFunctions::CastToChar().
FunctionContext * FunctionContextImpl::Clone | ( | MemPool * | pool | ) |
Returns a new FunctionContext with the same constant args, fragment-local state, and debug flag as this FunctionContext. The caller is responsible for calling delete on it.
Definition at line 147 of file udf.cc.
References constant_args_, fragment_local_fn_state_, and impala_udf::FunctionContext::impl_.
void FunctionContextImpl::Close | ( | ) |
Checks for any outstanding memory allocations. If there is unfreed memory, adds a warning and frees the allocations. Note that local allocations are freed with the MemPool backing pool_.
Definition at line 182 of file udf.cc.
References impala::RuntimeState::abort_on_error(), impala_udf::FunctionContext::AddWarning(), allocations_, closed_, context_, debug_, external_bytes_tracked_, impala_udf::FunctionContext::Free(), FreeLocalAllocations(), impala::FreePool::net_allocations(), pool_, impala_udf::FunctionContext::SetError(), state_, and varargs_buffer_.
Referenced by impala_udf::UdfTestHarness::CloseContext().
|
inline |
Definition at line 84 of file udf-internal.h.
References closed_.
|
static |
Create a FunctionContext for a UDF. Caller is responsible for deleting it.
Referenced by impala::AggFnEvaluator::Prepare(), and impala::ExprContext::Register().
|
static |
Create a FunctionContext for a UDA. Identical to the UDF version except for the intermediate type. Caller is responsible for deleting it.
|
inline |
Definition at line 83 of file udf-internal.h.
References debug_.
Referenced by impala_udf::UdfTestHarness::SetConstantArgs().
void FunctionContextImpl::FreeLocalAllocations | ( | ) |
Frees all allocations returned by AllocateLocal().
Definition at line 397 of file udf.cc.
References closed_, context_, impala::FreePool::Free(), local_allocations_, pool_, VLOG_ROW, and VLOG_ROW_IS_ON.
Referenced by Close().
|
inline |
Definition at line 91 of file udf-internal.h.
References num_removes_.
Referenced by impala::AggFnEvaluator::Remove(), and impala::AggregateFunctions::SumRemove().
|
inline |
Definition at line 90 of file udf-internal.h.
References num_updates_.
Referenced by impala::AggFnEvaluator::Add(), and impala::AggregateFunctions::SumUpdate().
|
inline |
Definition at line 87 of file udf-internal.h.
References num_removes_.
Referenced by impala::AggregateFunctions::FirstValUpdate(), impala::AggregateFunctions::LastValRemove(), impala::AggregateFunctions::SumDecimalRemove(), and impala::AggregateFunctions::SumRemove().
|
inline |
Definition at line 86 of file udf-internal.h.
References num_updates_.
Referenced by impala::AggregateFunctions::FirstValUpdate(), impala::AggregateFunctions::LastValRemove(), impala::AggregateFunctions::SumDecimalRemove(), and impala::AggregateFunctions::SumRemove().
|
inline |
Definition at line 89 of file udf-internal.h.
References num_removes_.
Referenced by impala::AggFnEvaluator::Init().
|
inline |
Definition at line 88 of file udf-internal.h.
References num_updates_.
Referenced by impala::AggFnEvaluator::Init().
void FunctionContextImpl::SetConstantArgs | ( | const std::vector< impala_udf::AnyVal * > & | constant_args | ) |
Sets constant_args_. The AnyVal* values are owned by the caller.
Definition at line 414 of file udf.cc.
References constant_args_.
Referenced by impala::ScalarFnCall::Open(), impala::AggFnEvaluator::Open(), and impala_udf::UdfTestHarness::SetConstantArgs().
|
inline |
Definition at line 81 of file udf-internal.h.
References staging_input_vals_.
Referenced by impala::ScalarFnCall::InterpretEval(), and impala::ScalarFnCall::Open().
|
inline |
Definition at line 95 of file udf-internal.h.
References state_.
Referenced by impala::UtilityFunctions::CurrentDatabase(), impala::TimestampFunctions::Now(), impala::UtilityFunctions::Pid(), and impala::TimestampFunctions::Unix().
|
inline |
Definition at line 79 of file udf-internal.h.
References varargs_buffer_.
Referenced by impala::ScalarFnCall::EvaluateChildren(), and impala::ScalarFnCall::InterpretEval().
|
friend |
Definition at line 98 of file udf-internal.h.
|
private |
Allocations made and still owned by the user function. Only used if debug_ is true because it is very expensive to maintain.
Definition at line 135 of file udf-internal.h.
Referenced by Close().
|
private |
Type descriptors for each argument of the function.
Definition at line 156 of file udf-internal.h.
Referenced by impala_udf::FunctionContext::GetArgType(), and impala_udf::FunctionContext::GetNumArgs().
|
private |
Indicates whether this context has been closed. Used for verification/debugging.
Definition at line 170 of file udf-internal.h.
Referenced by AllocateLocal(), Close(), closed(), FreeLocalAllocations(), impala_udf::FunctionContext::GetFunctionState(), and impala_udf::FunctionContext::~FunctionContext().
|
private |
Contains an AnyVal* for each argument of the function. If the AnyVal* is NULL, indicates that the corresponding argument is non-constant. Otherwise contains the value of the argument.
Definition at line 161 of file udf-internal.h.
Referenced by Clone(), impala_udf::FunctionContext::GetConstantArg(), impala_udf::FunctionContext::IsArgConstant(), and SetConstantArgs().
|
private |
Parent context object. Not owned.
Definition at line 109 of file udf-internal.h.
Referenced by AllocateLocal(), Close(), and FreeLocalAllocations().
|
private |
If true, indicates this is a debug context which will do additional validation.
Definition at line 119 of file udf-internal.h.
|
private |
Empty if there's no error.
Definition at line 124 of file udf-internal.h.
|
private |
The number of bytes allocated externally by the user function. In some cases, it is too inconvenient to use the Allocate()/Free() APIs in the FunctionContext, particularly for existing codebases (e.g. they use std::vector). Instead, they'll have to track those allocations manually.
Definition at line 147 of file udf-internal.h.
Referenced by Close().
|
private |
Definition at line 141 of file udf-internal.h.
Referenced by Clone(), and impala_udf::FunctionContext::GetFunctionState().
|
private |
Type descriptor for the intermediate type of a UDA. Set to INVALID_TYPE for UDFs.
Definition at line 150 of file udf-internal.h.
|
static |
Definition at line 93 of file udf-internal.h.
Referenced by impala::AggregationNode::CodegenUpdateSlot(), impala::PartitionedAggregationNode::CodegenUpdateSlot(), impala::AggregationNode::CodegenUpdateTuple(), and impala::PartitionedAggregationNode::CodegenUpdateTuple().
|
private |
Allocations owned by Impala.
Definition at line 137 of file udf-internal.h.
Referenced by AllocateLocal(), and FreeLocalAllocations().
|
private |
Definition at line 131 of file udf-internal.h.
Referenced by IncrementNumRemoves(), num_removes(), and set_num_removes().
|
private |
The number of calls to Update()/Remove().
Definition at line 130 of file udf-internal.h.
Referenced by IncrementNumUpdates(), num_updates(), and set_num_updates().
|
private |
The number of warnings reported.
Definition at line 127 of file udf-internal.h.
|
private |
Pool to service allocations from.
Definition at line 112 of file udf-internal.h.
Referenced by AllocateLocal(), Close(), FreeLocalAllocations(), and impala_udf::FunctionContext::~FunctionContext().
|
private |
Type descriptor for the return type of the function.
Definition at line 153 of file udf-internal.h.
Referenced by impala_udf::FunctionContext::GetReturnType().
|
private |
Used by ScalarFnCall to store the arguments when running without codegen. Allows us to pass AnyVal* arguments to the scalar function directly, rather than codegening a call that passes the correct AnyVal subclass pointer type. Note that this is only used for non-variadic arguments; varargs are always stored in varargs_buffer_.
Definition at line 167 of file udf-internal.h.
Referenced by staging_input_vals().
|
private |
We use the query's runtime state to report errors and warnings. NULL for test contexts.
Definition at line 116 of file udf-internal.h.
|
private |
The function state accessed via FunctionContext::Get/SetFunctionState()
Definition at line 140 of file udf-internal.h.
Referenced by impala_udf::FunctionContext::GetFunctionState().
|
private |
Preallocated buffer for storing varargs (if the function has any). Allocated and owned by this object, but populated by an Expr function. This is the first field in the class so it's easy to access in codegen'd functions. Don't move it or add fields above unless you know what you're doing.
Definition at line 105 of file udf-internal.h.
Referenced by Close(), and varargs_buffer().
|
private |
Definition at line 106 of file udf-internal.h.
|
private |
Definition at line 121 of file udf-internal.h.