Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
expr-context.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 #ifndef IMPALA_EXPRS_EXPR_CONTEXT_H
16 #define IMPALA_EXPRS_EXPR_CONTEXT_H
17 
18 #include <boost/scoped_ptr.hpp>
19 
20 #include "common/status.h"
21 #include "exprs/expr-value.h"
22 #include "udf/udf.h"
23 
24 using namespace impala_udf;
25 
26 namespace impala {
27 
28 class Expr;
29 class MemPool;
30 class MemTracker;
31 class RuntimeState;
32 class RowDescriptor;
33 class TColumnValue;
34 class TupleRow;
35 
40 class ExprContext {
41  public:
42  ExprContext(Expr* root);
43  ~ExprContext();
44 
47  Status Prepare(RuntimeState* state, const RowDescriptor& row_desc,
49 
51  Status Open(RuntimeState* state);
52 
58  Status Clone(RuntimeState* state, ExprContext** new_context);
59 
61  void Close(RuntimeState* state);
62 
65  void* GetValue(TupleRow* row);
66 
82  void GetValue(TupleRow* row, bool as_ascii, TColumnValue* col_val);
83 
85  void PrintValue(TupleRow* row, std::string* str);
86  void PrintValue(void* value, std::string* str);
87  void PrintValue(void* value, std::stringstream* stream);
88  void PrintValue(TupleRow* row, std::stringstream* stream);
89 
94  int Register(RuntimeState* state, const FunctionContext::TypeDesc& return_type,
95  const std::vector<FunctionContext::TypeDesc>& arg_types,
96  int varargs_buffer_size = 0);
97 
101  DCHECK_GE(i, 0);
102  return fn_contexts_[i];
103  }
104 
105  Expr* root() { return root_; }
106  bool closed() { return closed_; }
107 
109  BooleanVal GetBooleanVal(TupleRow* row);
110  TinyIntVal GetTinyIntVal(TupleRow* row);
111  SmallIntVal GetSmallIntVal(TupleRow* row);
112  IntVal GetIntVal(TupleRow* row);
113  BigIntVal GetBigIntVal(TupleRow* row);
114  FloatVal GetFloatVal(TupleRow* row);
115  DoubleVal GetDoubleVal(TupleRow* row);
116  StringVal GetStringVal(TupleRow* row);
117  TimestampVal GetTimestampVal(TupleRow* row);
118  DecimalVal GetDecimalVal(TupleRow* row);
119 
122  void FreeLocalAllocations();
123  static void FreeLocalAllocations(const std::vector<ExprContext*>& ctxs);
124  static void FreeLocalAllocations(const std::vector<FunctionContext*>& ctxs);
125 
126  static const char* LLVM_CLASS_NAME;
127 
128  private:
129  friend class Expr;
131  friend class HiveUdfCall;
132  friend class ScalarFnCall;
133 
136  std::vector<FunctionContext*> fn_contexts_;
137 
142 
144  boost::scoped_ptr<MemPool> pool_;
145 
148 
152 
154  bool is_clone_;
155  bool prepared_;
156  bool opened_;
157  bool closed_;
158 
161  void* GetValue(Expr* e, TupleRow* row);
162 };
163 
164 }
165 
166 #endif
If the UDF ran into an error, the FE throws an exception.
Definition: hive-udf-call.h:57
MemTracker tracker
boost::scoped_ptr< MemPool > pool_
Pool backing fn_contexts_. Counts against the runtime state's UDF mem tracker.
Definition: expr-context.h:144
The materialized value returned by ExprContext::GetValue().
Definition: expr-value.h:25
Expr * root_
The expr tree this context is for.
Definition: expr-context.h:147
This object has a compatible storage format with boost::ptime.
Definition: udf.h:495
static const char * LLVM_CLASS_NAME
Definition: expr-context.h:126
FunctionContext ** fn_contexts_ptr_
Definition: expr-context.h:141
bool is_clone_
Debugging variables.
Definition: expr-context.h:154
This is the superclass of all expr evaluation nodes.
Definition: expr.h:116
This class is thread-safe.
Definition: mem-tracker.h:61
const RowDescriptor & row_desc() const
std::vector< FunctionContext * > fn_contexts_
Definition: expr-context.h:136
FunctionContext * fn_context(int i)
Definition: expr-context.h:100