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

#include <udf.h>

Collaboration diagram for impala_udf::FunctionContext:

Classes

struct  TypeDesc
 
struct  UniqueId
 

Public Types

enum  ImpalaVersion { v1_2, v1_3 }
 
enum  Type {
  INVALID_TYPE = 0, TYPE_NULL, TYPE_BOOLEAN, TYPE_TINYINT,
  TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT, TYPE_FLOAT,
  TYPE_DOUBLE, TYPE_TIMESTAMP, TYPE_STRING, TYPE_FIXED_BUFFER,
  TYPE_DECIMAL, TYPE_VARCHAR
}
 
enum  FunctionStateScope { FRAGMENT_LOCAL, THREAD_LOCAL }
 

Public Member Functions

ImpalaVersion version () const
 Returns the version of Impala that's currently running. More...
 
const char * user () const
 
UniqueId query_id () const
 Returns the query_id for the current query. More...
 
void SetError (const char *error_msg)
 
bool AddWarning (const char *warning_msg)
 
bool has_error () const
 Returns true if there's been an error set. More...
 
const char * error_msg () const
 Returns the current error message. Returns NULL if there is no error. More...
 
uint8_t * Allocate (int byte_size)
 
uint8_t * Reallocate (uint8_t *ptr, int byte_size)
 
void Free (uint8_t *buffer)
 Frees a buffer returned from Allocate() or Reallocate() More...
 
void TrackAllocation (int64_t byte_size)
 
void Free (int64_t byte_size)
 
void SetFunctionState (FunctionStateScope scope, void *ptr)
 
void * GetFunctionState (FunctionStateScope scope) const
 
const TypeDescGetReturnType () const
 
const TypeDescGetIntermediateType () const
 
int GetNumArgs () const
 
const TypeDescGetArgType (int arg_idx) const
 
bool IsArgConstant (int arg_idx) const
 
AnyValGetConstantArg (int arg_idx) const
 
impala::FunctionContextImplimpl ()
 TODO: Add mechanism for UDAs to update stats similar to runtime profile counters. More...
 
 ~FunctionContext ()
 

Private Member Functions

 FunctionContext ()
 
 FunctionContext (const FunctionContext &other)
 Disable copy ctor and assignment operator. More...
 
FunctionContextoperator= (const FunctionContext &other)
 

Private Attributes

impala::FunctionContextImplimpl_
 

Friends

class impala::FunctionContextImpl
 

Detailed Description

A FunctionContext is passed to every UDF/UDA and is the interface for the UDF to the rest of the system. It contains APIs to examine the system state, report errors and manage memory.

Definition at line 47 of file udf.h.

Member Enumeration Documentation

Enumerator
FRAGMENT_LOCAL 

Indicates that the function state for this FunctionContext's UDF is shared across the plan fragment (a query is divided into multiple plan fragments, each of which is responsible for a part of the query execution). Within the plan fragment, there may be multiple instances of the UDF executing concurrently with multiple FunctionContexts sharing this state, meaning that the state must be thread-safe. The Prepare() function for the UDF may be called with this scope concurrently on a single host if the UDF will be evaluated in multiple plan fragments on that host. In general, read-only state that doesn't need to be recomputed for every UDF call should be fragment-local. TODO: not yet implemented

THREAD_LOCAL 

Indicates that the function state is local to the execution thread. This state does not need to be thread-safe. However, this state will be initialized (via the Prepare() function) once for every execution thread, so fragment-local state should be used when possible for better performance. In general, inexpensive shared state that is written to by the UDF (e.g. scratch space) should be thread-local.

Definition at line 87 of file udf.h.

Enumerator
v1_2 
v1_3 

Definition at line 49 of file udf.h.

Enumerator
INVALID_TYPE 
TYPE_NULL 
TYPE_BOOLEAN 
TYPE_TINYINT 
TYPE_SMALLINT 
TYPE_INT 
TYPE_BIGINT 
TYPE_FLOAT 
TYPE_DOUBLE 
TYPE_TIMESTAMP 
TYPE_STRING 
TYPE_FIXED_BUFFER 
TYPE_DECIMAL 
TYPE_VARCHAR 

Definition at line 54 of file udf.h.

Constructor & Destructor Documentation

FunctionContext::~FunctionContext ( )
FunctionContext::FunctionContext ( )
private

Definition at line 156 of file udf.cc.

impala_udf::FunctionContext::FunctionContext ( const FunctionContext other)
private

Disable copy ctor and assignment operator.

Member Function Documentation

bool FunctionContext::AddWarning ( const char *  warning_msg)

Adds a warning that is returned to the user. This can include things like overflow or other recoverable error conditions. Warnings are capped at a maximum number. Returns true if the warning was added and false if it was ignored due to the cap.

Definition at line 345 of file udf.cc.

References MAX_WARNINGS.

Referenced by impala::FunctionContextImpl::Close(), impala::TimestampFunctions::DateAddSub(), impala::AggregateFunctions::DecimalAvgGetValue(), impala::HiveUdfCall::Evaluate(), impala::TimestampFunctions::FromUtc(), impala::StringFunctions::ParseUrl(), impala::StringFunctions::ParseUrlKey(), impala::StringFunctions::RegexpExtract(), impala::StringFunctions::RegexpReplace(), impala::TimestampFunctions::ReportBadFormat(), TestWarnings(), and impala::TimestampFunctions::ToUtc().

const char * FunctionContext::error_msg ( ) const

Returns the current error message. Returns NULL if there is no error.

Definition at line 257 of file udf.cc.

Referenced by impala_udf::UdaTestHarnessBase< RESULT, INTERMEDIATE >::CheckContext(), impala::ScalarFnCall::Open(), impala_udf::UdfTestHarness::ValidateError(), ValidateFail(), and ValidateUdf().

void FunctionContext::Free ( int64_t  byte_size)

Definition at line 318 of file udf.cc.

AnyVal * FunctionContext::GetConstantArg ( int  arg_idx) const

Returns a pointer to the value of the arg_idx-th input argument (0 indexed, not including the FunctionContext* argument). Returns NULL if the argument is not constant. This function can be used to obtain user-specified constants in a UDF's Init() or Close() functions.

Definition at line 25 of file udf-ir.cc.

References impala::FunctionContextImpl::constant_args_, and impl_.

Referenced by ConstantArgPrepare(), impala::UdfBuiltins::ExtractPrepare(), impala::LikePredicate::LikePrepare(), impala::AggregateFunctions::OffsetFnInit(), impala::StringFunctions::ParseUrlPrepare(), impala::MathFunctions::RandPrepare(), impala::StringFunctions::RegexpPrepare(), impala::LikePredicate::RegexPrepare(), impala::InPredicate::SetLookupPrepare(), impala::UdfBuiltins::TruncPrepare(), impala::TimestampFunctions::UnixAndFromUnixPrepare(), and ValidateSharedStatePrepare().

void * FunctionContext::GetFunctionState ( FunctionStateScope  scope) const

Definition at line 38 of file udf-ir.cc.

References impala::FunctionContextImpl::closed_, FRAGMENT_LOCAL, impala::FunctionContextImpl::fragment_local_fn_state_, impl_, THREAD_LOCAL, and impala::FunctionContextImpl::thread_local_fn_state_.

Referenced by impala::CaseExpr::Close(), impala::HiveUdfCall::Close(), ConstantArg(), ConstantArgClose(), impala::LikePredicate::ConstantEndsWithFn(), impala::LikePredicate::ConstantEqualsFn(), impala::LikePredicate::ConstantRegexFn(), impala::LikePredicate::ConstantRegexFnPartial(), impala::LikePredicate::ConstantStartsWithFn(), impala::LikePredicate::ConstantSubstringFn(), impala::LikePredicate::ConvertLikePattern(), Count(), CountClose(), impala::HiveUdfCall::Evaluate(), impala::UdfBuiltins::Extract(), impala::UdfBuiltins::ExtractClose(), impala::TimestampFunctions::FromUnix(), impala::LikePredicate::Like(), impala::LikePredicate::LikeClose(), MemTest(), MemTestClose(), impala::StringFunctions::ParseUrl(), impala::StringFunctions::ParseUrlClose(), impala::StringFunctions::ParseUrlKey(), impala::MathFunctions::Rand(), impala::LikePredicate::Regex(), impala::LikePredicate::RegexClose(), impala::LikePredicate::RegexMatch(), impala::StringFunctions::RegexpClose(), impala::StringFunctions::RegexpExtract(), impala::StringFunctions::RegexpReplace(), impala::InPredicate::SetLookupClose(), impala::InPredicate::TemplatedIn(), impala::UdfBuiltins::Trunc(), impala::UdfBuiltins::TruncClose(), impala::TimestampFunctions::Unix(), impala::TimestampFunctions::UnixAndFromUnixClose(), ValidateOpen(), ValidateOpenClose(), ValidateSharedState(), and ValidateSharedStateClose().

const TypeDesc& impala_udf::FunctionContext::GetIntermediateType ( ) const

Returns the intermediate type for UDAs, i.e., the one returned by update and merge functions. Returns INVALID_TYPE for UDFs.

int FunctionContext::GetNumArgs ( ) const

Returns the number of arguments to this function (not including the FunctionContext* argument).

Definition at line 30 of file udf-ir.cc.

References impala::FunctionContextImpl::arg_types_, and impl_.

Referenced by impala::AggregateFunctions::OffsetFnInit(), impala::MathFunctions::RandPrepare(), and impala::InPredicate::SetLookupPrepare().

const FunctionContext::TypeDesc & FunctionContext::GetReturnType ( ) const
impala::FunctionContextImpl* impala_udf::FunctionContext::impl ( )
inline

TODO: Add mechanism for UDAs to update stats similar to runtime profile counters.

TODO: Do we need to add arbitrary key/value metadata. This would be plumbed through the query. E.g. "select UDA(col, 'sample=true') from tbl". const char* GetMetadata(const char*) const;TODO: Add mechanism to query for table/column stats Returns the underlying opaque implementation object. The UDF/UDA should not use this. This is used internally.

Definition at line 202 of file udf.h.

References impl_.

Referenced by impala::AggFnEvaluator::Add(), impala::CastFunctions::CastToChar(), impala_udf::UdfTestHarness::CloseContext(), impala::UtilityFunctions::CurrentDatabase(), impala::ScalarFnCall::EvaluateChildren(), impala::AggregateFunctions::FirstValUpdate(), impala::AggFnEvaluator::Init(), impala::ScalarFnCall::InterpretEval(), impala::AggregateFunctions::LastValRemove(), impala::TimestampFunctions::Now(), impala::ScalarFnCall::Open(), impala::AggFnEvaluator::Open(), impala::UtilityFunctions::Pid(), impala::AggFnEvaluator::Remove(), impala_udf::UdfTestHarness::SetConstantArgs(), impala::AggregateFunctions::SumDecimalRemove(), impala::AggregateFunctions::SumRemove(), impala::AggregateFunctions::SumUpdate(), and impala::TimestampFunctions::Unix().

FunctionContext& impala_udf::FunctionContext::operator= ( const FunctionContext other)
private
FunctionContext::UniqueId FunctionContext::query_id ( ) const

Returns the query_id for the current query.

Definition at line 242 of file udf.cc.

References impala_udf::FunctionContext::UniqueId::hi.

uint8_t * FunctionContext::Reallocate ( uint8_t *  ptr,
int  byte_size 
)

Reallocates 'ptr' to the new byte_size. If the currently underlying allocation is big enough, the original ptr will be returned. If the allocation needs to grow, a new allocation is made that is at least 'byte_size' and the contents of 'ptr' will be copied into it. This should be used for buffers that constantly get appended to.

Definition at line 276 of file udf.cc.

References VLOG_ROW.

Referenced by impala::AggregateFunctions::LastValUpdate(), impala::AggregateFunctions::StringConcatMerge(), and impala::AggregateFunctions::StringConcatUpdate().

void FunctionContext::TrackAllocation ( int64_t  byte_size)

For allocations that cannot use the Allocate() API provided by this object, TrackAllocation()/Free() can be used to just keep count of the byte sizes. For each call to TrackAllocation(), the UDF/UDA must call the corresponding Free().

Definition at line 312 of file udf.cc.

Referenced by DoubleFreeTest(), MemTest(), MemTestMerge(), and MemTestUpdate().

const char * FunctionContext::user ( ) const

Returns the user that is running the query. Returns NULL if it is not available.

Definition at line 237 of file udf.cc.

Referenced by impala::UtilityFunctions::User().

FunctionContext::ImpalaVersion FunctionContext::version ( ) const

Returns the version of Impala that's currently running.

Definition at line 233 of file udf.cc.

Referenced by ValidateUdf().

Friends And Related Function Documentation

friend class impala::FunctionContextImpl
friend

Definition at line 207 of file udf.h.

Member Data Documentation


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