Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
udf-internal.h
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 
16 #ifndef IMPALA_UDF_UDF_INTERNAL_H
17 #define IMPALA_UDF_UDF_INTERNAL_H
18 
19 #include <boost/cstdint.hpp>
20 #include <map>
21 #include <string>
22 #include <string.h>
23 #include <vector>
24 
27 #include "udf/udf.h"
28 
29 namespace impala {
30 
31 class FreePool;
32 class MemPool;
33 class RuntimeState;
34 
39  public:
42  const impala_udf::FunctionContext::TypeDesc& return_type,
43  const std::vector<impala_udf::FunctionContext::TypeDesc>& arg_types,
44  int varargs_buffer_size = 0, bool debug = false);
45 
49  const impala_udf::FunctionContext::TypeDesc& intermediate_type,
50  const impala_udf::FunctionContext::TypeDesc& return_type,
51  const std::vector<impala_udf::FunctionContext::TypeDesc>& arg_types,
52  int varargs_buffer_size = 0, bool debug = false);
53 
55 
59  void Close();
60 
65 
71  uint8_t* AllocateLocal(int byte_size);
72 
74  void FreeLocalAllocations();
75 
77  void SetConstantArgs(const std::vector<impala_udf::AnyVal*>& constant_args);
78 
79  uint8_t* varargs_buffer() { return varargs_buffer_; }
80 
81  std::vector<impala_udf::AnyVal*>* staging_input_vals() { return &staging_input_vals_; }
82 
83  bool debug() { return debug_; }
84  bool closed() { return closed_; }
85 
86  int64_t num_updates() const { return num_updates_; }
87  int64_t num_removes() const { return num_removes_; }
88  void set_num_updates(int64_t n) { num_updates_ = n; }
89  void set_num_removes(int64_t n) { num_removes_ = n; }
90  void IncrementNumUpdates(int64_t n = 1) { num_updates_ += n; }
91  void IncrementNumRemoves(int64_t n = 1) { num_removes_ += n; }
92 
93  static const char* LLVM_FUNCTIONCONTEXT_NAME;
94 
95  RuntimeState* state() { return state_; }
96 
97  private:
99 
102  //
105  uint8_t* varargs_buffer_;
107 
110 
113 
117 
119  bool debug_;
120 
122 
124  std::string error_msg_;
125 
127  int64_t num_warnings_;
128 
130  int64_t num_updates_;
131  int64_t num_removes_;
132 
135  std::map<uint8_t*, int> allocations_;
137  std::vector<uint8_t*> local_allocations_;
138 
142 
148 
151 
154 
156  std::vector<impala_udf::FunctionContext::TypeDesc> arg_types_;
157 
161  std::vector<impala_udf::AnyVal*> constant_args_;
162 
167  std::vector<impala_udf::AnyVal*> staging_input_vals_;
168 
170  bool closed_;
171 };
172 
173 }
174 
175 #endif
176 
impala_udf::FunctionContext::ImpalaVersion version_
Definition: udf-internal.h:121
impala_udf::FunctionContext::TypeDesc intermediate_type_
Type descriptor for the intermediate type of a UDA. Set to INVALID_TYPE for UDFs. ...
Definition: udf-internal.h:150
std::vector< impala_udf::FunctionContext::TypeDesc > arg_types_
Type descriptors for each argument of the function.
Definition: udf-internal.h:156
int64_t num_warnings_
The number of warnings reported.
Definition: udf-internal.h:127
void * thread_local_fn_state_
The function state accessed via FunctionContext::Get/SetFunctionState()
Definition: udf-internal.h:140
void SetConstantArgs(const std::vector< impala_udf::AnyVal * > &constant_args)
Sets constant_args_. The AnyVal* values are owned by the caller.
Definition: udf.cc:414
impala_udf::FunctionContext * context_
Parent context object. Not owned.
Definition: udf-internal.h:109
FreePool * pool_
Pool to service allocations from.
Definition: udf-internal.h:112
int64_t num_updates() const
Definition: udf-internal.h:86
std::vector< impala_udf::AnyVal * > staging_input_vals_
Definition: udf-internal.h:167
std::string error_msg_
Empty if there's no error.
Definition: udf-internal.h:124
std::map< uint8_t *, int > allocations_
Definition: udf-internal.h:135
void IncrementNumUpdates(int64_t n=1)
Definition: udf-internal.h:90
std::vector< uint8_t * > local_allocations_
Allocations owned by Impala.
Definition: udf-internal.h:137
impala_udf::FunctionContext::TypeDesc return_type_
Type descriptor for the return type of the function.
Definition: udf-internal.h:153
bool closed_
Indicates whether this context has been closed. Used for verification/debugging.
Definition: udf-internal.h:170
static const char * LLVM_FUNCTIONCONTEXT_NAME
Definition: udf-internal.h:93
std::vector< impala_udf::AnyVal * > constant_args_
Definition: udf-internal.h:161
ObjectPool pool
void set_num_removes(int64_t n)
Definition: udf-internal.h:89
void set_num_updates(int64_t n)
Definition: udf-internal.h:88
bool debug_
If true, indicates this is a debug context which will do additional validation.
Definition: udf-internal.h:119
int64_t num_removes() const
Definition: udf-internal.h:87
RuntimeState * state()
Definition: udf-internal.h:95
impala_udf::FunctionContext * Clone(MemPool *pool)
Definition: udf.cc:147
FunctionContextImpl(impala_udf::FunctionContext *parent)
Definition: udf.cc:165
static impala_udf::FunctionContext * CreateContext(RuntimeState *state, MemPool *pool, const impala_udf::FunctionContext::TypeDesc &return_type, const std::vector< impala_udf::FunctionContext::TypeDesc > &arg_types, int varargs_buffer_size=0, bool debug=false)
Create a FunctionContext for a UDF. Caller is responsible for deleting it.
uint8_t * AllocateLocal(int byte_size)
Definition: udf.cc:386
void FreeLocalAllocations()
Frees all allocations returned by AllocateLocal().
Definition: udf.cc:397
void IncrementNumRemoves(int64_t n=1)
Definition: udf-internal.h:91
int64_t num_updates_
The number of calls to Update()/Remove().
Definition: udf-internal.h:130
std::vector< impala_udf::AnyVal * > * staging_input_vals()
Definition: udf-internal.h:81