Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::FunctionContextImpl Class Reference

#include <udf-internal.h>

Collaboration diagram for impala::FunctionContextImpl:

Public Member Functions

 FunctionContextImpl (impala_udf::FunctionContext *parent)
 
void Close ()
 
impala_udf::FunctionContextClone (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)
 
RuntimeStatestate ()
 

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::FunctionContextcontext_
 Parent context object. Not owned. More...
 
FreePoolpool_
 Pool to service allocations from. More...
 
RuntimeStatestate_
 
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
 

Detailed Description

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.

Constructor & Destructor Documentation

FunctionContextImpl::FunctionContextImpl ( impala_udf::FunctionContext parent)

Definition at line 165 of file udf.cc.

Member Function Documentation

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().

bool impala::FunctionContextImpl::closed ( )
inline

Definition at line 84 of file udf-internal.h.

References closed_.

static impala_udf::FunctionContext* impala::FunctionContextImpl::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 
)
static

Create a FunctionContext for a UDF. Caller is responsible for deleting it.

Referenced by impala::AggFnEvaluator::Prepare(), and impala::ExprContext::Register().

static impala_udf::FunctionContext* impala::FunctionContextImpl::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

Create a FunctionContext for a UDA. Identical to the UDF version except for the intermediate type. Caller is responsible for deleting it.

bool impala::FunctionContextImpl::debug ( )
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().

void impala::FunctionContextImpl::IncrementNumRemoves ( int64_t  n = 1)
inline

Definition at line 91 of file udf-internal.h.

References num_removes_.

Referenced by impala::AggFnEvaluator::Remove(), and impala::AggregateFunctions::SumRemove().

void impala::FunctionContextImpl::IncrementNumUpdates ( int64_t  n = 1)
inline

Definition at line 90 of file udf-internal.h.

References num_updates_.

Referenced by impala::AggFnEvaluator::Add(), and impala::AggregateFunctions::SumUpdate().

int64_t impala::FunctionContextImpl::num_removes ( ) const
inline
int64_t impala::FunctionContextImpl::num_updates ( ) const
inline
void impala::FunctionContextImpl::set_num_removes ( int64_t  n)
inline

Definition at line 89 of file udf-internal.h.

References num_removes_.

Referenced by impala::AggFnEvaluator::Init().

void impala::FunctionContextImpl::set_num_updates ( int64_t  n)
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().

std::vector<impala_udf::AnyVal*>* impala::FunctionContextImpl::staging_input_vals ( )
inline
RuntimeState* impala::FunctionContextImpl::state ( )
inline
uint8_t* impala::FunctionContextImpl::varargs_buffer ( )
inline

Friends And Related Function Documentation

friend class impala_udf::FunctionContext
friend

Definition at line 98 of file udf-internal.h.

Member Data Documentation

std::map<uint8_t*, int> impala::FunctionContextImpl::allocations_
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().

std::vector<impala_udf::FunctionContext::TypeDesc> impala::FunctionContextImpl::arg_types_
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().

bool impala::FunctionContextImpl::closed_
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().

std::vector<impala_udf::AnyVal*> impala::FunctionContextImpl::constant_args_
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().

impala_udf::FunctionContext* impala::FunctionContextImpl::context_
private

Parent context object. Not owned.

Definition at line 109 of file udf-internal.h.

Referenced by AllocateLocal(), Close(), and FreeLocalAllocations().

bool impala::FunctionContextImpl::debug_
private

If true, indicates this is a debug context which will do additional validation.

Definition at line 119 of file udf-internal.h.

Referenced by Close(), and debug().

std::string impala::FunctionContextImpl::error_msg_
private

Empty if there's no error.

Definition at line 124 of file udf-internal.h.

int64_t impala::FunctionContextImpl::external_bytes_tracked_
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().

void* impala::FunctionContextImpl::fragment_local_fn_state_
private

Definition at line 141 of file udf-internal.h.

Referenced by Clone(), and impala_udf::FunctionContext::GetFunctionState().

impala_udf::FunctionContext::TypeDesc impala::FunctionContextImpl::intermediate_type_
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.

const char * FunctionContextImpl::LLVM_FUNCTIONCONTEXT_NAME
static
std::vector<uint8_t*> impala::FunctionContextImpl::local_allocations_
private

Allocations owned by Impala.

Definition at line 137 of file udf-internal.h.

Referenced by AllocateLocal(), and FreeLocalAllocations().

int64_t impala::FunctionContextImpl::num_removes_
private

Definition at line 131 of file udf-internal.h.

Referenced by IncrementNumRemoves(), num_removes(), and set_num_removes().

int64_t impala::FunctionContextImpl::num_updates_
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().

int64_t impala::FunctionContextImpl::num_warnings_
private

The number of warnings reported.

Definition at line 127 of file udf-internal.h.

FreePool* impala::FunctionContextImpl::pool_
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().

impala_udf::FunctionContext::TypeDesc impala::FunctionContextImpl::return_type_
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().

std::vector<impala_udf::AnyVal*> impala::FunctionContextImpl::staging_input_vals_
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().

RuntimeState* impala::FunctionContextImpl::state_
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.

Referenced by Close(), and state().

void* impala::FunctionContextImpl::thread_local_fn_state_
private

The function state accessed via FunctionContext::Get/SetFunctionState()

Definition at line 140 of file udf-internal.h.

Referenced by impala_udf::FunctionContext::GetFunctionState().

uint8_t* impala::FunctionContextImpl::varargs_buffer_
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().

int impala::FunctionContextImpl::varargs_buffer_size_
private

Definition at line 106 of file udf-internal.h.

impala_udf::FunctionContext::ImpalaVersion impala::FunctionContextImpl::version_
private

Definition at line 121 of file udf-internal.h.


The documentation for this class was generated from the following files: