Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
conditional-functions.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_EXPRS_CONDITIONAL_FUNCTIONS_H
17 #define IMPALA_EXPRS_CONDITIONAL_FUNCTIONS_H
18 
19 #include <stdint.h>
20 
21 #include "exprs/expr.h"
22 #include "udf/udf.h"
23 
24 using namespace impala_udf;
25 
26 namespace impala {
27 
28 class TupleRow;
29 
32  public:
33  static TinyIntVal NullIfZero(FunctionContext* context, const TinyIntVal& val);
34  static SmallIntVal NullIfZero(FunctionContext* context, const SmallIntVal& val);
35  static IntVal NullIfZero(FunctionContext* context, const IntVal& val);
36  static BigIntVal NullIfZero(FunctionContext* context, const BigIntVal& val);
37  static FloatVal NullIfZero(FunctionContext* context, const FloatVal& val);
38  static DoubleVal NullIfZero(FunctionContext* context, const DoubleVal& val);
39  static DecimalVal NullIfZero(FunctionContext* context, const DecimalVal& val);
40 
41  static TinyIntVal ZeroIfNull(FunctionContext* context, const TinyIntVal& val);
42  static SmallIntVal ZeroIfNull(FunctionContext* context, const SmallIntVal& val);
43  static IntVal ZeroIfNull(FunctionContext* context, const IntVal& val);
44  static BigIntVal ZeroIfNull(FunctionContext* context, const BigIntVal& val);
45  static FloatVal ZeroIfNull(FunctionContext* context, const FloatVal& val);
46  static DoubleVal ZeroIfNull(FunctionContext* context, const DoubleVal& val);
47  static DecimalVal ZeroIfNull(FunctionContext* context, const DecimalVal& val);
48 
51  static BooleanVal IsFalse(FunctionContext* ctx, const BooleanVal& val);
52  static BooleanVal IsNotFalse(FunctionContext* ctx, const BooleanVal& val);
53  static BooleanVal IsTrue(FunctionContext* ctx, const BooleanVal& val);
54  static BooleanVal IsNotTrue(FunctionContext* ctx, const BooleanVal& val);
55 };
56 
59 
60 class IsNullExpr : public Expr {
61  public:
62  virtual BooleanVal GetBooleanVal(ExprContext* context, TupleRow* row);
63  virtual TinyIntVal GetTinyIntVal(ExprContext* context, TupleRow* row);
64  virtual SmallIntVal GetSmallIntVal(ExprContext* context, TupleRow* row);
65  virtual IntVal GetIntVal(ExprContext* context, TupleRow* row);
66  virtual BigIntVal GetBigIntVal(ExprContext* context, TupleRow* row);
67  virtual FloatVal GetFloatVal(ExprContext* context, TupleRow* row);
68  virtual DoubleVal GetDoubleVal(ExprContext* context, TupleRow* row);
69  virtual StringVal GetStringVal(ExprContext* context, TupleRow* row);
70  virtual TimestampVal GetTimestampVal(ExprContext* context, TupleRow* row);
71  virtual DecimalVal GetDecimalVal(ExprContext* context, TupleRow* row);
72 
73  virtual Status GetCodegendComputeFn(RuntimeState* state, llvm::Function** fn);
74  virtual std::string DebugString() const { return Expr::DebugString("IsNullExpr"); }
75 
76  protected:
77  friend class Expr;
78  IsNullExpr(const TExprNode& node) : Expr(node) { }
79 };
80 
81 class NullIfExpr : public Expr {
82  public:
83  virtual BooleanVal GetBooleanVal(ExprContext* context, TupleRow* row);
84  virtual TinyIntVal GetTinyIntVal(ExprContext* context, TupleRow* row);
85  virtual SmallIntVal GetSmallIntVal(ExprContext* context, TupleRow* row);
86  virtual IntVal GetIntVal(ExprContext* context, TupleRow* row);
87  virtual BigIntVal GetBigIntVal(ExprContext* context, TupleRow* row);
88  virtual FloatVal GetFloatVal(ExprContext* context, TupleRow* row);
89  virtual DoubleVal GetDoubleVal(ExprContext* context, TupleRow* row);
90  virtual StringVal GetStringVal(ExprContext* context, TupleRow* row);
91  virtual TimestampVal GetTimestampVal(ExprContext* context, TupleRow* row);
92  virtual DecimalVal GetDecimalVal(ExprContext* context, TupleRow* row);
93 
94  virtual Status GetCodegendComputeFn(RuntimeState* state, llvm::Function** fn);
95  virtual std::string DebugString() const { return Expr::DebugString("NullIfExpr"); }
96 
97  protected:
98  friend class Expr;
99  NullIfExpr(const TExprNode& node) : Expr(node) { }
100 };
101 
102 class IfExpr : public Expr {
103  public:
104  virtual BooleanVal GetBooleanVal(ExprContext* context, TupleRow* row);
105  virtual TinyIntVal GetTinyIntVal(ExprContext* context, TupleRow* row);
106  virtual SmallIntVal GetSmallIntVal(ExprContext* context, TupleRow* row);
107  virtual IntVal GetIntVal(ExprContext* context, TupleRow* row);
108  virtual BigIntVal GetBigIntVal(ExprContext* context, TupleRow* row);
109  virtual FloatVal GetFloatVal(ExprContext* context, TupleRow* row);
110  virtual DoubleVal GetDoubleVal(ExprContext* context, TupleRow* row);
111  virtual StringVal GetStringVal(ExprContext* context, TupleRow* row);
112  virtual TimestampVal GetTimestampVal(ExprContext* context, TupleRow* row);
113  virtual DecimalVal GetDecimalVal(ExprContext* context, TupleRow* row);
114 
115  virtual Status GetCodegendComputeFn(RuntimeState* state, llvm::Function** fn);
116  virtual std::string DebugString() const { return Expr::DebugString("IfExpr"); }
117 
118  protected:
119  friend class Expr;
120  IfExpr(const TExprNode& node) : Expr(node) { }
121 };
122 
123 class CoalesceExpr : public Expr {
124  public:
125  virtual BooleanVal GetBooleanVal(ExprContext* context, TupleRow* row);
126  virtual TinyIntVal GetTinyIntVal(ExprContext* context, TupleRow* row);
127  virtual SmallIntVal GetSmallIntVal(ExprContext* context, TupleRow* row);
128  virtual IntVal GetIntVal(ExprContext* context, TupleRow* row);
129  virtual BigIntVal GetBigIntVal(ExprContext* context, TupleRow* row);
130  virtual FloatVal GetFloatVal(ExprContext* context, TupleRow* row);
131  virtual DoubleVal GetDoubleVal(ExprContext* context, TupleRow* row);
132  virtual StringVal GetStringVal(ExprContext* context, TupleRow* row);
133  virtual TimestampVal GetTimestampVal(ExprContext* context, TupleRow* row);
134  virtual DecimalVal GetDecimalVal(ExprContext* context, TupleRow* row);
135 
136  virtual std::string DebugString() const { return Expr::DebugString("CoalesceExpr"); }
137 
138  protected:
139  friend class Expr;
140  CoalesceExpr(const TExprNode& node) : Expr(node) { }
141  virtual Status GetCodegendComputeFn(RuntimeState* state, llvm::Function** fn);
142 };
143 
144 }
145 
146 #endif
virtual std::string DebugString() const
NullIfExpr(const TExprNode &node)
virtual std::string DebugString() const
IsNullExpr(const TExprNode &node)
virtual std::string DebugString() const
This object has a compatible storage format with boost::ptime.
Definition: udf.h:495
Conditional functions that can be expressed as UDFs.
IfExpr(const TExprNode &node)
CoalesceExpr(const TExprNode &node)
std::string DebugString(const T &val)
Definition: udf-debug.h:27
This is the superclass of all expr evaluation nodes.
Definition: expr.h:116
virtual std::string DebugString() const