22 #include "gen-cpp/Exprs_types.h"
27 using namespace impala_udf;
31 Literal::Literal(
const TExprNode& node)
35 DCHECK_EQ(node.node_type, TExprNodeType::BOOL_LITERAL);
36 DCHECK(node.__isset.bool_literal);
40 DCHECK_EQ(node.node_type, TExprNodeType::INT_LITERAL);
41 DCHECK(node.__isset.int_literal);
45 DCHECK_EQ(node.node_type, TExprNodeType::INT_LITERAL);
46 DCHECK(node.__isset.int_literal);
50 DCHECK_EQ(node.node_type, TExprNodeType::INT_LITERAL);
51 DCHECK(node.__isset.int_literal);
55 DCHECK_EQ(node.node_type, TExprNodeType::INT_LITERAL);
56 DCHECK(node.__isset.int_literal);
60 DCHECK_EQ(node.node_type, TExprNodeType::FLOAT_LITERAL);
61 DCHECK(node.__isset.float_literal);
65 DCHECK_EQ(node.node_type, TExprNodeType::FLOAT_LITERAL);
66 DCHECK(node.__isset.float_literal);
71 DCHECK_EQ(node.node_type, TExprNodeType::STRING_LITERAL);
72 DCHECK(node.__isset.string_literal);
80 DCHECK_EQ(node.node_type, TExprNodeType::STRING_LITERAL);
81 DCHECK(node.__isset.string_literal);
82 string str = node.string_literal.value;
83 int str_len = str.size();
84 DCHECK_GT(str_len, 0);
94 DCHECK_EQ(node.node_type, TExprNodeType::DECIMAL_LITERAL);
95 DCHECK(node.__isset.decimal_literal);
96 const uint8_t* buffer =
97 reinterpret_cast<const uint8_t*
>(&node.decimal_literal.value[0]);
98 int len = node.decimal_literal.value.size();
101 switch (
type().GetByteSize()) {
185 istringstream stream(str);
187 return !stream.fail();
194 DCHECK(ParseString<bool>(str, &v)) << str;
199 DCHECK(ParseString<int8_t>(str, &v)) << str;
204 DCHECK(ParseString<int16_t>(str, &v)) << str;
209 DCHECK(ParseString<int32_t>(str, &v)) << str;
214 DCHECK(ParseString<int64_t>(str, &v)) << str;
219 DCHECK(ParseString<float>(str, &v)) << str;
224 DCHECK(ParseString<double>(str, &v)) << str;
233 DCHECK(ParseString<double>(str, &v));
237 DCHECK(
false) <<
"Invalid type: " << type.
DebugString();
286 switch (
type().GetByteSize()) {
302 out <<
"Literal(value=";
329 switch (
type().GetByteSize()) {
344 out <<
"[bad type! " <<
type_ <<
"]";
367 BasicBlock* entry_block = BasicBlock::Create(codegen->
context(),
"entry", *fn);
416 ss <<
"Invalid type: " <<
type_;
417 DCHECK(
false) << ss.str();
421 builder.CreateRet(v.
value());
virtual impala_udf::IntVal GetIntVal(ExprContext *, TupleRow *)
llvm::Function * ir_compute_fn_
Cached codegened compute function. Exprs should set this in GetCodegendComputeFn().
static void DecodeFromFixedLenByteArray(const uint8_t *buffer, int fixed_len_size, T *v)
void SetLen(llvm::Value *len)
#define RETURN_IF_ERROR(stmt)
some generally useful macros
Decimal8Value decimal8_val
The materialized value returned by ExprContext::GetValue().
virtual impala_udf::StringVal GetStringVal(ExprContext *, TupleRow *)
void SetVal(llvm::Value *val)
TimestampValue timestamp_val
static CodegenAnyVal GetNonNullVal(LlvmCodeGen *codegen, LlvmCodeGen::LlvmBuilder *builder, const ColumnType &type, const char *name="")
virtual impala_udf::SmallIntVal GetSmallIntVal(ExprContext *, TupleRow *)
string TypeToString(PrimitiveType t)
static Literal * CreateLiteral(const ColumnType &type, const std::string &str)
virtual Status GetCodegendComputeFn(RuntimeState *state, llvm::Function **fn)
LLVM code generator. This is the top level object to generate jitted code.
virtual std::string DebugString() const
llvm::Function * CreateIrFunctionPrototype(LlvmCodeGen *codegen, const std::string &name, llvm::Value *(*args)[2])
bool IsStringType() const
std::string DebugString() const
llvm::Value * CastPtrToLlvmPtr(llvm::Type *type, const void *ptr)
virtual impala_udf::DecimalVal GetDecimalVal(ExprContext *, TupleRow *)
void SetPtr(llvm::Value *ptr)
Setters for StringVals.
std::string DebugString(const T &val)
virtual impala_udf::BigIntVal GetBigIntVal(ExprContext *, TupleRow *)
int GetByteSize() const
Returns the byte size of this type. Returns 0 for variable length types.
int len
Only set if type == TYPE_CHAR or type == TYPE_VARCHAR.
This is the superclass of all expr evaluation nodes.
virtual impala_udf::BooleanVal GetBooleanVal(ExprContext *, TupleRow *)
virtual impala_udf::FloatVal GetFloatVal(ExprContext *, TupleRow *)
std::string ToString(const ColumnType &type) const
const ColumnType & type() const
llvm::Value * value()
Returns the current type-lowered value.
Decimal4Value decimal4_val
Decimal16Value decimal16_val
Status GetCodegen(LlvmCodeGen **codegen, bool initialize=true)
const ColumnType type_
analysis is done, types are fixed at this point
bool ParseString(const string &str, T *val)
llvm::Function * FinalizeFunction(llvm::Function *function)
void ToStringVal(impala_udf::StringVal *sv) const
llvm::LLVMContext & context()
virtual impala_udf::TinyIntVal GetTinyIntVal(ExprContext *, TupleRow *)
virtual std::string DebugString() const
virtual impala_udf::DoubleVal GetDoubleVal(ExprContext *, TupleRow *)
Literal(ColumnType type, bool v)
Test ctors.
int GetNumChildren() const
llvm::PointerType * ptr_type()