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

#include <expr-context.h>

Collaboration diagram for impala::ExprContext:

Public Member Functions

 ExprContext (Expr *root)
 
 ~ExprContext ()
 
Status Prepare (RuntimeState *state, const RowDescriptor &row_desc, MemTracker *tracker)
 
Status Open (RuntimeState *state)
 Must be called after calling Prepare(). Should not be called on clones. More...
 
Status Clone (RuntimeState *state, ExprContext **new_context)
 
void Close (RuntimeState *state)
 Closes all FunctionContexts. Must be called on every ExprContext, including clones. More...
 
void * GetValue (TupleRow *row)
 
void GetValue (TupleRow *row, bool as_ascii, TColumnValue *col_val)
 
void PrintValue (TupleRow *row, std::string *str)
 Convenience functions: print value into 'str' or 'stream'. NULL turns into "NULL". More...
 
void PrintValue (void *value, std::string *str)
 
void PrintValue (void *value, std::stringstream *stream)
 
void PrintValue (TupleRow *row, std::stringstream *stream)
 
int Register (RuntimeState *state, const FunctionContext::TypeDesc &return_type, const std::vector< FunctionContext::TypeDesc > &arg_types, int varargs_buffer_size=0)
 
FunctionContextfn_context (int i)
 
Exprroot ()
 
bool closed ()
 
BooleanVal GetBooleanVal (TupleRow *row)
 Calls Get*Val on root_. More...
 
TinyIntVal GetTinyIntVal (TupleRow *row)
 
SmallIntVal GetSmallIntVal (TupleRow *row)
 
IntVal GetIntVal (TupleRow *row)
 
BigIntVal GetBigIntVal (TupleRow *row)
 
FloatVal GetFloatVal (TupleRow *row)
 
DoubleVal GetDoubleVal (TupleRow *row)
 
StringVal GetStringVal (TupleRow *row)
 
TimestampVal GetTimestampVal (TupleRow *row)
 
DecimalVal GetDecimalVal (TupleRow *row)
 
void FreeLocalAllocations ()
 

Static Public Member Functions

static void FreeLocalAllocations (const std::vector< ExprContext * > &ctxs)
 
static void FreeLocalAllocations (const std::vector< FunctionContext * > &ctxs)
 

Static Public Attributes

static const char * LLVM_CLASS_NAME = "class.impala::ExprContext"
 

Private Member Functions

void * GetValue (Expr *e, TupleRow *row)
 

Private Attributes

std::vector< FunctionContext * > fn_contexts_
 
FunctionContext ** fn_contexts_ptr_
 
boost::scoped_ptr< MemPoolpool_
 Pool backing fn_contexts_. Counts against the runtime state's UDF mem tracker. More...
 
Exprroot_
 The expr tree this context is for. More...
 
ExprValue result_
 
bool is_clone_
 Debugging variables. More...
 
bool prepared_
 
bool opened_
 
bool closed_
 

Friends

class Expr
 
class HiveUdfCall
 Users of private GetValue() More...
 
class ScalarFnCall
 

Detailed Description

An ExprContext contains the state for the execution of a tree of Exprs, in particular the FunctionContexts necessary for the expr tree. This allows for multi-threaded expression evaluation, as a given tree can be evaluated using multiple ExprContexts concurrently. A single ExprContext is not thread-safe.

Definition at line 40 of file expr-context.h.

Constructor & Destructor Documentation

ExprContext::ExprContext ( Expr root)

Definition at line 31 of file expr-context.cc.

Referenced by Clone().

ExprContext::~ExprContext ( )

Definition at line 40 of file expr-context.cc.

References closed_, fn_contexts_, and prepared_.

Member Function Documentation

Status ExprContext::Clone ( RuntimeState state,
ExprContext **  new_context 
)

Creates a copy of this ExprContext. Open() must be called first. The copy contains clones of each FunctionContext, which share the fragment-local state of the originals but have their own MemPool and thread-local state. Clone() should be used to create an ExprContext for each execution thread that needs to evaluate 'root'. Note that clones are already opened.

Definition at line 91 of file expr-context.cc.

References impala::ObjectPool::Add(), ExprContext(), fn_contexts_, impala::RuntimeState::obj_pool(), impala::Expr::Open(), opened_, pool_, prepared_, and root_.

void ExprContext::Close ( RuntimeState state)

Closes all FunctionContexts. Must be called on every ExprContext, including clones.

Definition at line 67 of file expr-context.cc.

References impala::Expr::Close(), closed_, fn_contexts_, is_clone_, pool_, and root_.

Referenced by impala::AnalyticEvalNode::Close(), impala::TEST_F(), and impala::TestSingleLiteralConstruction().

bool impala::ExprContext::closed ( )
inline

Definition at line 106 of file expr-context.h.

FunctionContext* impala::ExprContext::fn_context ( int  i)
inline
void ExprContext::FreeLocalAllocations ( )
static void impala::ExprContext::FreeLocalAllocations ( const std::vector< ExprContext * > &  ctxs)
static
static void impala::ExprContext::FreeLocalAllocations ( const std::vector< FunctionContext * > &  ctxs)
static
BigIntVal ExprContext::GetBigIntVal ( TupleRow row)

Definition at line 322 of file expr-context.cc.

References impala::Expr::GetBigIntVal(), and root_.

BooleanVal ExprContext::GetBooleanVal ( TupleRow row)

Calls Get*Val on root_.

Definition at line 310 of file expr-context.cc.

References impala::Expr::GetBooleanVal(), and root_.

Referenced by impala::ExecNode::EvalConjuncts(), and impala::AnalyticEvalNode::PrevRowCompare().

DecimalVal ExprContext::GetDecimalVal ( TupleRow row)

Definition at line 337 of file expr-context.cc.

References impala::Expr::GetDecimalVal(), and root_.

DoubleVal ExprContext::GetDoubleVal ( TupleRow row)

Definition at line 328 of file expr-context.cc.

References impala::Expr::GetDoubleVal(), and root_.

FloatVal ExprContext::GetFloatVal ( TupleRow row)

Definition at line 325 of file expr-context.cc.

References impala::Expr::GetFloatVal(), and root_.

IntVal ExprContext::GetIntVal ( TupleRow row)

Definition at line 319 of file expr-context.cc.

References impala::Expr::GetIntVal(), and root_.

SmallIntVal ExprContext::GetSmallIntVal ( TupleRow row)

Definition at line 316 of file expr-context.cc.

References impala::Expr::GetSmallIntVal(), and root_.

StringVal ExprContext::GetStringVal ( TupleRow row)

Definition at line 331 of file expr-context.cc.

References impala::Expr::GetStringVal(), and root_.

TimestampVal ExprContext::GetTimestampVal ( TupleRow row)

Definition at line 334 of file expr-context.cc.

References impala::Expr::GetTimestampVal(), and root_.

TinyIntVal ExprContext::GetTinyIntVal ( TupleRow row)

Definition at line 313 of file expr-context.cc.

References impala::Expr::GetTinyIntVal(), and root_.

void * ExprContext::GetValue ( TupleRow row)

Calls the appropriate Get*Val() function on this context's expr tree and stores the result in result_.

Definition at line 200 of file expr-context.cc.

References root_.

Referenced by BenchmarkQueryFn(), impala::HiveUdfCall::Evaluate(), impala::ScalarFnCall::EvaluateChildren(), GetValue(), impala::DataStreamSender::Send(), impala::TEST_F(), and impala::TestSingleLiteralConstruction().

void ExprContext::GetValue ( TupleRow row,
bool  as_ascii,
TColumnValue *  col_val 
)

Convenience function: extract value into col_val and sets the appropriate __isset flag. If the value is NULL and as_ascii is false, nothing is set. If 'as_ascii' is true, writes the value in ascii into stringVal (nulls turn into "NULL"); if it is false, the specific field in col_val that receives the value is based on the type of the expr: TYPE_BOOLEAN: boolVal TYPE_TINYINT/SMALLINT/INT: intVal TYPE_BIGINT: longVal TYPE_FLOAT/DOUBLE: doubleVal TYPE_STRING: stringVal TYPE_TIMESTAMP: stringVal Note: timestamp is converted to string via RawValue::PrintValue because HiveServer2 requires timestamp in a string format.

Definition at line 126 of file expr-context.cc.

References impala::StringValue::CharSlotToPtr(), impala::ColumnType::DebugString(), impala::ColumnType::GetByteSize(), GetValue(), impala::StringValue::len, impala::ColumnType::len, impala::Expr::output_scale_, impala::RawValue::PrintValue(), impala::StringValue::ptr, root_, impala::ColumnType::type, impala::Expr::type_, impala::TYPE_BIGINT, impala::TYPE_BOOLEAN, impala::TYPE_CHAR, impala::TYPE_DECIMAL, impala::TYPE_DOUBLE, impala::TYPE_FLOAT, impala::TYPE_INT, impala::TYPE_SMALLINT, impala::TYPE_STRING, impala::TYPE_TIMESTAMP, impala::TYPE_TINYINT, and impala::TYPE_VARCHAR.

void * ExprContext::GetValue ( Expr e,
TupleRow row 
)
private

Calls the appropriate Get*Val() function on 'e' and stores the result in result_. This is used by Exprs to call GetValue() on a child expr, rather than root_.

Definition at line 204 of file expr-context.cc.

References impala::ExprValue::bigint_val, impala::ExprValue::bool_val, impala::ColumnType::DebugString(), impala::ExprValue::decimal16_val, impala::ExprValue::decimal4_val, impala::ExprValue::decimal8_val, impala::ExprValue::double_val, impala::ExprValue::float_val, impala::TimestampValue::FromTimestampVal(), impala::Expr::GetBigIntVal(), impala::Expr::GetBooleanVal(), impala::ColumnType::GetByteSize(), impala::Expr::GetDecimalVal(), impala::Expr::GetDoubleVal(), impala::Expr::GetFloatVal(), impala::Expr::GetIntVal(), impala::Expr::GetSmallIntVal(), impala::Expr::GetStringVal(), impala::Expr::GetTimestampVal(), impala::Expr::GetTinyIntVal(), impala::ExprValue::int_val, impala_udf::AnyVal::is_null, impala::ColumnType::IsVarLen(), impala::StringValue::len, impala_udf::StringVal::len, impala::StringValue::ptr, impala_udf::StringVal::ptr, result_, impala::ExprValue::smallint_val, impala::ExprValue::string_val, impala::ExprValue::timestamp_val, impala::ExprValue::tinyint_val, impala::ColumnType::type, impala::Expr::type_, impala::TYPE_BIGINT, impala::TYPE_BOOLEAN, impala::TYPE_CHAR, impala::TYPE_DECIMAL, impala::TYPE_DOUBLE, impala::TYPE_FLOAT, impala::TYPE_INT, impala::TYPE_SMALLINT, impala::TYPE_STRING, impala::TYPE_TIMESTAMP, impala::TYPE_TINYINT, impala::TYPE_VARCHAR, impala_udf::BooleanVal::val, impala_udf::TinyIntVal::val, impala_udf::SmallIntVal::val, impala_udf::IntVal::val, impala_udf::BigIntVal::val, impala_udf::FloatVal::val, impala_udf::DoubleVal::val, impala_udf::DecimalVal::val16, impala_udf::DecimalVal::val4, and impala_udf::DecimalVal::val8.

Status ExprContext::Open ( RuntimeState state)

Must be called after calling Prepare(). Should not be called on clones.

Definition at line 56 of file expr-context.cc.

References is_clone_, impala::Expr::Open(), opened_, prepared_, and root_.

Referenced by impala::AnalyticEvalNode::Open(), impala::TEST_F(), and impala::TestSingleLiteralConstruction().

Status ExprContext::Prepare ( RuntimeState state,
const RowDescriptor row_desc,
MemTracker tracker 
)

Prepare expr tree for evaluation. Allocations from this context will be counted against 'tracker'.

Definition at line 47 of file expr-context.cc.

References pool_, impala::Expr::Prepare(), prepared_, and root_.

Referenced by Java_com_cloudera_impala_service_FeSupport_NativeEvalConstExprs(), impala::AnalyticEvalNode::Prepare(), impala::TEST_F(), and impala::TestSingleLiteralConstruction().

void impala::ExprContext::PrintValue ( TupleRow row,
std::string *  str 
)

Convenience functions: print value into 'str' or 'stream'. NULL turns into "NULL".

void impala::ExprContext::PrintValue ( void *  value,
std::string *  str 
)
void impala::ExprContext::PrintValue ( void *  value,
std::stringstream *  stream 
)
void impala::ExprContext::PrintValue ( TupleRow row,
std::stringstream *  stream 
)
int ExprContext::Register ( RuntimeState state,
const FunctionContext::TypeDesc return_type,
const std::vector< FunctionContext::TypeDesc > &  arg_types,
int  varargs_buffer_size = 0 
)

Creates a FunctionContext, and returns the index that's passed to fn_context() to retrieve the created context. Exprs that need a FunctionContext should call this in Prepare() and save the returned index. 'varargs_buffer_size', if specified, is the size of the varargs buffer in the created FunctionContext (see udf-internal.h).

Definition at line 81 of file expr-context.cc.

References impala::FunctionContextImpl::CreateContext(), fn_contexts_, fn_contexts_ptr_, and pool_.

Referenced by impala::ScalarFnCall::Prepare(), and impala::Expr::RegisterFunctionContext().

Friends And Related Function Documentation

friend class Expr
friend

Definition at line 129 of file expr-context.h.

friend class HiveUdfCall
friend

Users of private GetValue()

Definition at line 131 of file expr-context.h.

friend class ScalarFnCall
friend

Definition at line 132 of file expr-context.h.

Member Data Documentation

bool impala::ExprContext::closed_
private

Definition at line 157 of file expr-context.h.

Referenced by Close(), and ~ExprContext().

std::vector<FunctionContext*> impala::ExprContext::fn_contexts_
private

FunctionContexts for each registered expression. The FunctionContexts are created and owned by this ExprContext.

Definition at line 136 of file expr-context.h.

Referenced by Clone(), Close(), FreeLocalAllocations(), Register(), and ~ExprContext().

FunctionContext** impala::ExprContext::fn_contexts_ptr_
private

Array access to fn_contexts_. Used by ScalarFnCall's codegen'd compute function to access the correct FunctionContext. TODO: revisit this

Definition at line 141 of file expr-context.h.

Referenced by Register().

bool impala::ExprContext::is_clone_
private

Debugging variables.

Definition at line 154 of file expr-context.h.

Referenced by Close(), and Open().

bool impala::ExprContext::opened_
private

Definition at line 156 of file expr-context.h.

Referenced by Clone(), impala::HiveUdfCall::Close(), impala::Expr::GetConstVal(), and Open().

boost::scoped_ptr<MemPool> impala::ExprContext::pool_
private

Pool backing fn_contexts_. Counts against the runtime state's UDF mem tracker.

Definition at line 144 of file expr-context.h.

Referenced by Clone(), Close(), Prepare(), and Register().

bool impala::ExprContext::prepared_
private

Definition at line 155 of file expr-context.h.

Referenced by Clone(), Open(), Prepare(), and ~ExprContext().

ExprValue impala::ExprContext::result_
private

Stores the result of the root expr. This is used in interpreted code when we need a void*.

Definition at line 151 of file expr-context.h.

Referenced by GetValue().

Expr* impala::ExprContext::root_
private

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