16 #ifndef IMPALA_UDA_TEST_HARNESS_H
17 #define IMPALA_UDA_TEST_HARNESS_H
23 #include <boost/scoped_ptr.hpp>
24 #include <boost/shared_ptr.hpp>
30 namespace impala_udf {
39 template<
typename RESULT,
typename INTERMEDIATE>
48 const INTERMEDIATE& type);
104 bool CheckResult(
const RESULT& x,
const RESULT& y);
140 template<
typename RESULT,
typename INTERMEDIATE,
typename INPUT>
144 INTERMEDIATE* result);
154 :
BaseClass(init_fn, merge_fn, serialize_fn, finalize_fn),
159 bool Execute(
const std::vector<INPUT>& values,
const RESULT& expected,
165 bool Execute(
const std::vector<T>& values,
const RESULT& expected,
167 input_.resize(values.size());
169 for (
int i = 0; i < values.size(); ++i) {
184 template<
typename RESULT,
typename INTERMEDIATE,
typename INPUT1,
typename INPUT2>
188 const INPUT2& input2, INTERMEDIATE* result);
198 :
BaseClass(init_fn, merge_fn, serialize_fn, finalize_fn),
203 bool Execute(
const std::vector<INPUT1>& values1,
const std::vector<INPUT2>& values2,
215 template<
typename RESULT,
typename INTERMEDIATE,
typename INPUT1,
typename INPUT2,
220 const INPUT2& input2,
const INPUT3& input3, INTERMEDIATE* result);
230 :
BaseClass(init_fn, merge_fn, serialize_fn, finalize_fn),
235 bool Execute(
const std::vector<INPUT1>& values1,
const std::vector<INPUT2>& values2,
236 const std::vector<INPUT3>& values3,
249 template<
typename RESULT,
typename INTERMEDIATE,
typename INPUT1,
typename INPUT2,
250 typename INPUT3,
typename INPUT4>
254 const INPUT2& input2,
const INPUT3& input3,
const INPUT4& input4,
255 INTERMEDIATE* result);
265 :
BaseClass(init_fn, merge_fn, serialize_fn, finalize_fn),
270 bool Execute(
const std::vector<INPUT1>& values1,
const std::vector<INPUT2>& values2,
271 const std::vector<INPUT3>& values3,
const std::vector<INPUT4>& values4,
bool Execute(const std::vector< INPUT1 > &values1, const std::vector< INPUT2 > &values2, const std::vector< INPUT3 > &values3, const std::vector< INPUT4 > &values4, const RESULT &expected, UdaExecutionMode mode=ALL)
Runs the UDA in all the modes, validating the result is 'expected' each time.
UdaTestHarnessBase< RESULT, INTERMEDIATE > BaseClass
void SetResultComparator(ResultComparator fn)
void(* UpdateFn)(FunctionContext *context, const INPUT1 &input1, const INPUT2 &input2, INTERMEDIATE *result)
void SetIntermediateSize(int byte_size)
This must be called if the INTERMEDIATE is TYPE_FIXED_BUFFER.
bool Execute(const std::vector< INPUT1 > &values1, const std::vector< INPUT2 > &values2, const RESULT &expected, UdaExecutionMode mode=ALL)
Runs the UDA in all the modes, validating the result is 'expected' each time.
virtual void Update(int idx, FunctionContext *context, INTERMEDIATE *dst)
int fixed_buffer_byte_size_
Buffer len for intermediate results if the type is TYPE_FIXED_BUFFER.
const std::vector< INPUT2 > * input2_
const std::vector< INPUT2 > * input2_
UdaTestHarnessBase * harness_
const std::vector< INPUT1 > * input1_
UdaTestHarness(typename BaseClass::InitFn init_fn, UpdateFn update_fn, typename BaseClass::MergeFn merge_fn, typename BaseClass::SerializeFn serialize_fn, typename BaseClass::FinalizeFn finalize_fn)
const std::vector< INPUT3 > * input3_
virtual void Update(int idx, FunctionContext *context, INTERMEDIATE *dst)=0
UdaTestHarness2(typename BaseClass::InitFn init_fn, UpdateFn update_fn, typename BaseClass::MergeFn merge_fn, typename BaseClass::SerializeFn serialize_fn, typename BaseClass::FinalizeFn finalize_fn)
void(* UpdateFn)(FunctionContext *context, const INPUT &input, INTERMEDIATE *result)
RESULT ExecuteOneLevel(int num_nodes, ScopedFunctionContext *result_context)
SerializeFn serialize_fn_
UdaTestHarness4(typename BaseClass::InitFn init_fn, UpdateFn update_fn, typename BaseClass::MergeFn merge_fn, typename BaseClass::SerializeFn serialize_fn, typename BaseClass::FinalizeFn finalize_fn)
const std::vector< INPUT2 > * input2_
const std::vector< INPUT1 > * input1_
bool Execute(const std::vector< INPUT1 > &values1, const std::vector< INPUT2 > &values2, const std::vector< INPUT3 > &values3, const RESULT &expected, UdaExecutionMode mode=ALL)
Runs the UDA in all the modes, validating the result is 'expected' each time.
virtual void Update(int idx, FunctionContext *context, INTERMEDIATE *dst)
int num_input_values_
Set during Execute() by subclass.
bool CheckResult(const RESULT &x, const RESULT &y)
Verifies x == y, using the custom comparator if set.
bool CheckContext(FunctionContext *context)
Returns false if there is an error set in the context.
RESULT(* FinalizeFn)(FunctionContext *context, const INTERMEDIATE &value)
virtual void Update(int idx, FunctionContext *context, INTERMEDIATE *dst)
UdaTestHarnessBase< RESULT, INTERMEDIATE > BaseClass
const std::vector< INPUT3 > * input3_
FunctionContext * context_
RESULT ExecuteTwoLevel(int num1, int num2, ScopedFunctionContext *result_context)
bool Execute(const RESULT &expected, UdaExecutionMode mode)
Runs the UDA in all the modes, validating the result is 'expected' each time.
bool Execute(const std::vector< INPUT > &values, const RESULT &expected, UdaExecutionMode mode=ALL)
Runs the UDA in all the modes, validating the result is 'expected' each time.
UdaTestHarnessBase< RESULT, INTERMEDIATE > BaseClass
ResultComparator result_comparator_fn_
Customer comparator, NULL if default == should be used.
ScopedFunctionContext(FunctionContext *context, UdaTestHarnessBase *harness)
std::string error_msg_
Error message if anything went wrong during the execution.
InitFn init_fn_
UDA functions.
bool Execute(const std::vector< T > &values, const RESULT &expected, UdaExecutionMode mode=ALL)
UdaTestHarness3(typename BaseClass::InitFn init_fn, UpdateFn update_fn, typename BaseClass::MergeFn merge_fn, typename BaseClass::SerializeFn serialize_fn, typename BaseClass::FinalizeFn finalize_fn)
const std::vector< INPUT4 > * input4_
void(* MergeFn)(FunctionContext *context, const INTERMEDIATE &src, INTERMEDIATE *dst)
UdaTestHarnessBase(InitFn init_fn, MergeFn merge_fn, SerializeFn serialize_fn, FinalizeFn finalize_fn)
const std::string & GetErrorMsg() const
Returns the failure string if any.
virtual void Update(int idx, FunctionContext *context, INTERMEDIATE *dst)
UdaTestHarnessBase< RESULT, INTERMEDIATE > BaseClass
RESULT ExecuteSingleNode(ScopedFunctionContext *result_context)
const std::vector< INPUT1 > * input1_
bool(* ResultComparator)(const RESULT &x, const RESULT &y)
void(* UpdateFn)(FunctionContext *context, const INPUT1 &input1, const INPUT2 &input2, const INPUT3 &input3, const INPUT4 &input4, INTERMEDIATE *result)
const INTERMEDIATE(* SerializeFn)(FunctionContext *context, const INTERMEDIATE &type)
void(* UpdateFn)(FunctionContext *context, const INPUT1 &input1, const INPUT2 &input2, const INPUT3 &input3, INTERMEDIATE *result)
void(* InitFn)(FunctionContext *context, INTERMEDIATE *result)
static void CloseContext(FunctionContext *context)
std::vector< const INPUT * > input_
Set during Execute()