Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
test-udas.cc
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "testutil/test-udas.h"
16 
17 #include <udf/udf.h>
18 
19 using namespace impala_udf;
20 
22 void TwoArgUpdate(FunctionContext*, const IntVal&, const StringVal&, IntVal*) {}
24 
26 void VarArgUpdate(FunctionContext*, const DoubleVal&, int, const StringVal*, IntVal*) {}
28 
29 // Defines Agg(<some args>) returns int
31 void AggUpdate(FunctionContext*, const IntVal&, const IntVal&, IntVal*) {}
32 // Update function intentionally not called *Update for FE testing.
33 void AggFn(FunctionContext*, const IntVal&, IntVal*) {}
36 IntVal AggSerialize(FunctionContext*, const IntVal& i) { return i; }
37 IntVal AggFinalize(FunctionContext*, const IntVal&i) { return i; }
38 
39 
40 // Defines Agg(<some args>) returns string intermediate string
43 void Agg(FunctionContext*, const StringVal&, const DoubleVal&, StringVal*) {}
44 
49 
50 
51 // Defines Agg(int) returns BIGINT intermediate CHAR(10)
52 void Agg(FunctionContext*, const IntVal&, BufferVal*) {}
57  return BigIntVal::null();
58 }
59 
60 // Defines MemTest(bigint) return bigint
61 // "Allocates" the specified number of bytes in the update function and frees them in the
62 // serialize function. Useful for testing mem limits.
64  *total = BigIntVal(0);
65 }
66 
67 void MemTestUpdate(FunctionContext* context, const BigIntVal& bytes, BigIntVal* total) {
68  if (bytes.is_null) return;
69  context->TrackAllocation(bytes.val); // freed by serialize()
70  total->val += bytes.val;
71 }
72 
73 void MemTestMerge(FunctionContext* context, const BigIntVal& src, BigIntVal* dst) {
74  if (src.is_null) return;
75  context->TrackAllocation(src.val); // freed by finalize()
76  if (dst->is_null) {
77  *dst = src;
78  return;
79  }
80  dst->val += src.val;
81 }
82 
83 const BigIntVal MemTestSerialize(FunctionContext* context, const BigIntVal& total) {
84  if (total.is_null) return BigIntVal(0);
85  context->Free(total.val);
86  return total;
87 }
88 
90  if (total.is_null) return BigIntVal(0);
91  context->Free(total.val);
92  return total;
93 }
static BigIntVal null()
Definition: udf.h:444
const BigIntVal MemTestSerialize(FunctionContext *context, const BigIntVal &total)
Definition: test-udas.cc:83
void TwoArgMerge(FunctionContext *, const IntVal &, IntVal *)
Definition: test-udas.cc:23
void Agg2Update(FunctionContext *, const StringVal &, const DoubleVal &, StringVal *)
Definition: test-udas.cc:42
void AggFn(FunctionContext *, const IntVal &, IntVal *)
Definition: test-udas.cc:33
void TwoArgInit(FunctionContext *, IntVal *)
Definition: test-udas.cc:21
BigIntVal MemTestFinalize(FunctionContext *context, const BigIntVal &total)
Definition: test-udas.cc:89
void MemTestInit(FunctionContext *, BigIntVal *total)
Definition: test-udas.cc:63
void AggUpdate(FunctionContext *, const IntVal &, IntVal *)
Definition: test-udas.cc:30
void AggMerge(FunctionContext *, const IntVal &, IntVal *)
Definition: test-udas.cc:35
void Agg(FunctionContext *, const StringVal &, const DoubleVal &, StringVal *)
Definition: test-udas.cc:43
uint8_t * BufferVal
Definition: udf.h:600
void MemTestMerge(FunctionContext *context, const BigIntVal &src, BigIntVal *dst)
Definition: test-udas.cc:73
bool is_null
Definition: udf.h:359
void TwoArgUpdate(FunctionContext *, const IntVal &, const StringVal &, IntVal *)
Definition: test-udas.cc:22
IntVal AggSerialize(FunctionContext *, const IntVal &i)
Definition: test-udas.cc:36
void VarArgUpdate(FunctionContext *, const DoubleVal &, int, const StringVal *, IntVal *)
Definition: test-udas.cc:26
void AggInit(FunctionContext *, IntVal *)
Definition: test-udas.cc:34
void Free(uint8_t *buffer)
Frees a buffer returned from Allocate() or Reallocate()
Definition: udf.cc:291
void VarArgMerge(FunctionContext *, const IntVal &, IntVal *)
Definition: test-udas.cc:27
IntVal AggFinalize(FunctionContext *, const IntVal &i)
Definition: test-udas.cc:37
void TrackAllocation(int64_t byte_size)
Definition: udf.cc:312
void VarArgInit(FunctionContext *, IntVal *)
Definition: test-udas.cc:25
void MemTestUpdate(FunctionContext *context, const BigIntVal &bytes, BigIntVal *total)
Definition: test-udas.cc:67