Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
null-literal.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 "null-literal.h"
16 
17 #include "codegen/codegen-anyval.h"
18 #include "codegen/llvm-codegen.h"
19 #include "runtime/runtime-state.h"
20 #include "udf/udf.h"
21 #include "gen-cpp/Exprs_types.h"
22 
23 #include "common/names.h"
24 
25 using namespace impala_udf;
26 using namespace llvm;
27 
28 namespace impala {
29 
30 BooleanVal NullLiteral::GetBooleanVal(ExprContext* context, TupleRow* row) {
31  DCHECK_EQ(type_.type, TYPE_BOOLEAN) << type_;
32  return BooleanVal::null();
33 }
34 
35 TinyIntVal NullLiteral::GetTinyIntVal(ExprContext* context, TupleRow* row) {
36  DCHECK_EQ(type_.type, TYPE_TINYINT) << type_;
37  return TinyIntVal::null();
38 }
39 
40 SmallIntVal NullLiteral::GetSmallIntVal(ExprContext* context, TupleRow* row) {
41  DCHECK_EQ(type_.type, TYPE_SMALLINT) << type_;
42  return SmallIntVal::null();
43 }
44 
45 IntVal NullLiteral::GetIntVal(ExprContext* context, TupleRow* row) {
46  DCHECK_EQ(type_.type, TYPE_INT) << type_;
47  return IntVal::null();
48 }
49 
50 BigIntVal NullLiteral::GetBigIntVal(ExprContext* context, TupleRow* row) {
51  DCHECK_EQ(type_.type, TYPE_BIGINT) << type_;
52  return BigIntVal::null();
53 }
54 
55 FloatVal NullLiteral::GetFloatVal(ExprContext* context, TupleRow* row) {
56  DCHECK_EQ(type_.type, TYPE_FLOAT) << type_;
57  return FloatVal::null();
58 }
59 
60 DoubleVal NullLiteral::GetDoubleVal(ExprContext* context, TupleRow* row) {
61  DCHECK_EQ(type_.type, TYPE_DOUBLE) << type_;
62  return DoubleVal::null();
63 }
64 
65 StringVal NullLiteral::GetStringVal(ExprContext* context, TupleRow* row) {
66  DCHECK(type_.IsStringType()) << type_;
67  return StringVal::null();
68 }
69 
70 TimestampVal NullLiteral::GetTimestampVal(ExprContext* context, TupleRow* row) {
71  DCHECK_EQ(type_.type, TYPE_TIMESTAMP) << type_;
72  return TimestampVal::null();
73 }
74 
75 DecimalVal NullLiteral::GetDecimalVal(ExprContext* context, TupleRow* row) {
76  DCHECK_EQ(type_.type, TYPE_DECIMAL) << type_;
77  return DecimalVal::null();
78 }
79 
80 // Generated IR for a bigint NULL literal:
81 //
82 // define { i8, i64 } @NullLiteral(i8* %context, %"class.impala::TupleRow"* %row) {
83 // entry:
84 // ret { i8, i64 } { i8 1, i64 0 }
85 // }
86 Status NullLiteral::GetCodegendComputeFn(RuntimeState* state, llvm::Function** fn) {
87  if (ir_compute_fn_ != NULL) {
88  *fn = ir_compute_fn_;
89  return Status::OK;
90  }
91 
92  DCHECK_EQ(GetNumChildren(), 0);
93  LlvmCodeGen* codegen;
94  RETURN_IF_ERROR(state->GetCodegen(&codegen));
95  Value* args[2];
96  *fn = CreateIrFunctionPrototype(codegen, "NullLiteral", &args);
97  BasicBlock* entry_block = BasicBlock::Create(codegen->context(), "entry", *fn);
98  LlvmCodeGen::LlvmBuilder builder(entry_block);
99 
100  Value* v = CodegenAnyVal::GetNullVal(codegen, type());
101  builder.CreateRet(v);
102  *fn = codegen->FinalizeFunction(*fn);
103  ir_compute_fn_ = *fn;
104  return Status::OK;
105 }
106 
107 string NullLiteral::DebugString() const {
108  stringstream out;
109  out << "NullLiteral(" << Expr::DebugString() << ")";
110  return out.str();
111 }
112 
113 }
static BigIntVal null()
Definition: udf.h:444
static IntVal null()
Definition: udf.h:425
static FloatVal null()
Definition: udf.h:463
#define RETURN_IF_ERROR(stmt)
some generally useful macros
Definition: status.h:242
static TinyIntVal null()
Definition: udf.h:387
This object has a compatible storage format with boost::ptime.
Definition: udf.h:495
static SmallIntVal null()
Definition: udf.h:406
LLVM code generator. This is the top level object to generate jitted code.
Definition: llvm-codegen.h:107
static TimestampVal null()
Definition: udf.h:505
std::string DebugString(const T &val)
Definition: udf-debug.h:27
static BooleanVal null()
Definition: udf.h:368
static DecimalVal null()
Definition: udf.h:580
static StringVal null()
Definition: udf.h:536
Status GetCodegen(LlvmCodeGen **codegen, bool initialize=true)
llvm::Function * FinalizeFunction(llvm::Function *function)
static DoubleVal null()
Definition: udf.h:480
llvm::LLVMContext & context()
Definition: llvm-codegen.h:214