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

Utility class to help test UDFs. More...

#include <udf-test-harness.h>

Collaboration diagram for impala_udf::UdfTestHarness:

Static Public Member Functions

static FunctionContextCreateTestContext (const FunctionContext::TypeDesc &return_type, const std::vector< FunctionContext::TypeDesc > &arg_types)
 
static void SetConstantArgs (FunctionContext *context, const std::vector< AnyVal * > &constant_args)
 The AnyVal* values are owned by the caller. More...
 
static void CloseContext (FunctionContext *context)
 
template<typename RET >
static bool ValidateUdf (boost::function< RET(FunctionContext *)> fn, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 
template<typename RET , typename A1 >
static bool ValidateUdf (boost::function< RET(FunctionContext *, const A1 &)> fn, const A1 &a1, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 
template<typename RET , typename A1 >
static bool ValidateUdf (boost::function< RET(FunctionContext *, int, const A1 *)> fn, const std::vector< A1 > &a1, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 
template<typename RET , typename A1 , typename A2 >
static bool ValidateUdf (boost::function< RET(FunctionContext *, const A1 &, const A2 &)> fn, const A1 &a1, const A2 &a2, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 
template<typename RET , typename A1 , typename A2 >
static bool ValidateUdf (boost::function< RET(FunctionContext *, const A1 &, int, const A2 *)> fn, const A1 &a1, const std::vector< A2 > &a2, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 
template<typename RET , typename A1 , typename A2 , typename A3 >
static bool ValidateUdf (boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &)> fn, const A1 &a1, const A2 &a2, const A3 &a3, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 
template<typename RET , typename A1 , typename A2 , typename A3 >
static bool ValidateUdf (boost::function< RET(FunctionContext *, const A1 &, const A2 &, int, const A3 *)> fn, const A1 &a1, const A2 &a2, const std::vector< A3 > &a3, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 
template<typename RET , typename A1 , typename A2 , typename A3 , typename A4 >
static bool ValidateUdf (boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &, const A4 &)> fn, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 
template<typename RET , typename A1 , typename A2 , typename A3 , typename A4 >
static bool ValidateUdf (boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &, int, const A4 *)> fn, const A1 &a1, const A2 &a2, const A3 &a3, const std::vector< A4 > &a4, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 
template<typename RET , typename A1 , typename A2 , typename A3 , typename A4 , typename A5 >
static bool ValidateUdf (boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &)> fn, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 
template<typename RET , typename A1 , typename A2 , typename A3 , typename A4 , typename A5 , typename A6 >
static bool ValidateUdf (boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &)> fn, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 
template<typename RET , typename A1 , typename A2 , typename A3 , typename A4 , typename A5 , typename A6 , typename A7 >
static bool ValidateUdf (boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &)> fn, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 
template<typename RET , typename A1 , typename A2 , typename A3 , typename A4 , typename A5 , typename A6 , typename A7 , typename A8 >
static bool ValidateUdf (boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &)> fn, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8, const RET &expected, UdfPrepare init_fn=NULL, UdfClose close_fn=NULL, const std::vector< AnyVal * > &constant_args=std::vector< AnyVal * >())
 

Static Private Member Functions

static bool ValidateError (FunctionContext *context)
 
template<typename RET >
static bool Validate (FunctionContext *context, const RET &expected, const RET &actual)
 
static bool RunPrepareFn (UdfPrepare prepare_fn, FunctionContext *context)
 
static void RunCloseFn (UdfClose close_fn, FunctionContext *context)
 

Detailed Description

Utility class to help test UDFs.

Definition at line 30 of file udf-test-harness.h.

Member Function Documentation

void UdfTestHarness::CloseContext ( FunctionContext context)
static

Test contexts should be closed in order to check for UDF memory leaks. Leaks cause the error to be set on context.

Definition at line 40 of file udf-test-harness.cc.

References impala::FunctionContextImpl::Close(), and impala_udf::FunctionContext::impl().

Referenced by Validate(), and impala_udf::UdaTestHarnessBase< RESULT, INTERMEDIATE >::ScopedFunctionContext::~ScopedFunctionContext().

FunctionContext * UdfTestHarness::CreateTestContext ( const FunctionContext::TypeDesc return_type,
const std::vector< FunctionContext::TypeDesc > &  arg_types 
)
static

Create a test FunctionContext object. 'arg_types' should contain a TypeDesc for each argument of the UDF not including the FunctionContext*. The caller is responsible for calling delete on it. This context has additional debugging validation enabled.

Definition at line 25 of file udf-test-harness.cc.

Referenced by impala_udf::UdaTestHarnessBase< RESULT, INTERMEDIATE >::Execute(), impala_udf::UdaTestHarnessBase< RESULT, INTERMEDIATE >::ExecuteOneLevel(), impala_udf::UdaTestHarnessBase< RESULT, INTERMEDIATE >::ExecuteTwoLevel(), and ValidateUdf().

static void impala_udf::UdfTestHarness::RunCloseFn ( UdfClose  close_fn,
FunctionContext context 
)
inlinestaticprivate

Definition at line 311 of file udf-test-harness.h.

References impala_udf::FunctionContext::THREAD_LOCAL.

Referenced by ValidateUdf().

static bool impala_udf::UdfTestHarness::RunPrepareFn ( UdfPrepare  prepare_fn,
FunctionContext context 
)
inlinestaticprivate

Definition at line 302 of file udf-test-harness.h.

References impala_udf::FunctionContext::THREAD_LOCAL, and ValidateError().

Referenced by ValidateUdf().

void UdfTestHarness::SetConstantArgs ( FunctionContext context,
const std::vector< AnyVal * > &  constant_args 
)
static

The AnyVal* values are owned by the caller.

Use with test contexts to test use of IsArgConstant() and GetConstantArg(). constant_args should contain an AnyVal* for each argument of the UDF not including the FunctionContext*; constant_args[i] corresponds to the i-th argument. Non-constant arguments should be set to NULL, and constant arguments should be set to the constant value.Can only be called on contexts created by CreateTestContext().

Definition at line 31 of file udf-test-harness.cc.

References impala::FunctionContextImpl::debug(), impala_udf::FunctionContext::impl(), impala::FunctionContextImpl::SetConstantArgs(), and impala_udf::FunctionContext::SetError().

Referenced by ValidateUdf().

template<typename RET >
static bool impala_udf::UdfTestHarness::Validate ( FunctionContext context,
const RET &  expected,
const RET &  actual 
)
inlinestaticprivate
static bool impala_udf::UdfTestHarness::ValidateError ( FunctionContext context)
inlinestaticprivate
template<typename RET >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *)>  fn,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic

Template function to execute a UDF and validate the result. They should be used like: ValidateUdf(udf_fn, arg1, arg2, ..., expected_result); Only functions with up to 8 arguments are supported For variable argument udfs, the variable arguments should be passed as a std::vector: ValidateUdf(udf_fn, arg1, arg2, const vector<arg3>& args, expected_result);

Definition at line 63 of file udf-test-harness.h.

References CreateTestContext(), RunCloseFn(), RunPrepareFn(), SetConstantArgs(), and Validate().

template<typename RET , typename A1 >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *, const A1 &)>  fn,
const A1 &  a1,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic
template<typename RET , typename A1 >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *, int, const A1 *)>  fn,
const std::vector< A1 > &  a1,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic
template<typename RET , typename A1 , typename A2 >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *, const A1 &, const A2 &)>  fn,
const A1 &  a1,
const A2 &  a2,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic
template<typename RET , typename A1 , typename A2 >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *, const A1 &, int, const A2 *)>  fn,
const A1 &  a1,
const std::vector< A2 > &  a2,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic
template<typename RET , typename A1 , typename A2 , typename A3 >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &)>  fn,
const A1 &  a1,
const A2 &  a2,
const A3 &  a3,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic
template<typename RET , typename A1 , typename A2 , typename A3 >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *, const A1 &, const A2 &, int, const A3 *)>  fn,
const A1 &  a1,
const A2 &  a2,
const std::vector< A3 > &  a3,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic
template<typename RET , typename A1 , typename A2 , typename A3 , typename A4 >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &, const A4 &)>  fn,
const A1 &  a1,
const A2 &  a2,
const A3 &  a3,
const A4 &  a4,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic
template<typename RET , typename A1 , typename A2 , typename A3 , typename A4 >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &, int, const A4 *)>  fn,
const A1 &  a1,
const A2 &  a2,
const A3 &  a3,
const std::vector< A4 > &  a4,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic
template<typename RET , typename A1 , typename A2 , typename A3 , typename A4 , typename A5 >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &)>  fn,
const A1 &  a1,
const A2 &  a2,
const A3 &  a3,
const A4 &  a4,
const A5 &  a5,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic
template<typename RET , typename A1 , typename A2 , typename A3 , typename A4 , typename A5 , typename A6 >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &)>  fn,
const A1 &  a1,
const A2 &  a2,
const A3 &  a3,
const A4 &  a4,
const A5 &  a5,
const A6 &  a6,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic
template<typename RET , typename A1 , typename A2 , typename A3 , typename A4 , typename A5 , typename A6 , typename A7 >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &)>  fn,
const A1 &  a1,
const A2 &  a2,
const A3 &  a3,
const A4 &  a4,
const A5 &  a5,
const A6 &  a6,
const A7 &  a7,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic
template<typename RET , typename A1 , typename A2 , typename A3 , typename A4 , typename A5 , typename A6 , typename A7 , typename A8 >
static bool impala_udf::UdfTestHarness::ValidateUdf ( boost::function< RET(FunctionContext *, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &)>  fn,
const A1 &  a1,
const A2 &  a2,
const A3 &  a3,
const A4 &  a4,
const A5 &  a5,
const A6 &  a6,
const A7 &  a7,
const A8 &  a8,
const RET &  expected,
UdfPrepare  init_fn = NULL,
UdfClose  close_fn = NULL,
const std::vector< AnyVal * > &  constant_args = std::vector<AnyVal*>() 
)
inlinestatic

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