|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | #include "codegen/timestamp_ir_builder.h" |
| 18 | + |
18 | 19 | #include <string> |
19 | 20 | #include <vector> |
| 21 | + |
20 | 22 | #include "codegen/arithmetic_expr_ir_builder.h" |
21 | 23 | #include "codegen/ir_base_builder.h" |
22 | 24 | #include "codegen/null_ir_builder.h" |
23 | 25 | #include "codegen/predicate_expr_ir_builder.h" |
24 | 26 | #include "glog/logging.h" |
25 | | -#include "node/sql_node.h" |
26 | 27 |
|
27 | 28 | using hybridse::common::kCodegenError; |
28 | 29 |
|
@@ -70,29 +71,30 @@ base::Status TimestampIRBuilder::CastFrom(::llvm::BasicBlock* block, |
70 | 71 | CondSelectIRBuilder cond_ir_builder; |
71 | 72 | PredicateIRBuilder predicate_ir_builder(block); |
72 | 73 | NullIRBuilder null_ir_builder; |
| 74 | + |
| 75 | + // always allocate for returned timestmap even it is null |
| 76 | + ::llvm::Value* dist = nullptr; |
| 77 | + if (!CreateDefault(block, &dist)) { |
| 78 | + status.code = common::kCodegenError; |
| 79 | + status.msg = "Fail to cast date: create default date fail"; |
| 80 | + return status; |
| 81 | + } |
| 82 | + |
73 | 83 | if (IsNumber(src.GetType())) { |
74 | 84 | CHECK_STATUS(cast_builder.Cast(src, builder.getInt64Ty(), &ts)); |
75 | 85 | NativeValue cond; |
76 | 86 | CHECK_STATUS(predicate_ir_builder.BuildGeExpr( |
77 | 87 | ts, NativeValue::Create(builder.getInt64(0)), &cond)); |
78 | | - ::llvm::Value* timestamp; |
79 | | - CHECK_TRUE(NewTimestamp(block, ts.GetValue(&builder), ×tamp), |
| 88 | + CHECK_TRUE(SetTs(block, dist, ts.GetValue(&builder)), |
80 | 89 | kCodegenError, |
81 | 90 | "Fail to cast timestamp: new timestamp(ts) fail"); |
82 | | - CHECK_STATUS( |
83 | | - cond_ir_builder.Select(block, cond, NativeValue::Create(timestamp), |
84 | | - NativeValue::CreateNull(GetType()), output)); |
| 91 | + CHECK_STATUS(cond_ir_builder.Select(block, cond, NativeValue::Create(dist), |
| 92 | + NativeValue::CreateWithFlag(dist, builder.getInt1(true)), output)); |
85 | 93 |
|
86 | 94 | } else if (IsStringPtr(src.GetType()) || IsDatePtr(src.GetType())) { |
87 | 95 | ::llvm::IRBuilder<> builder(block); |
88 | | - ::llvm::Value* dist = nullptr; |
89 | 96 | ::llvm::Value* is_null_ptr = CreateAllocaAtHead( |
90 | 97 | &builder, builder.getInt1Ty(), "timestamp_is_null_alloca"); |
91 | | - if (!CreateDefault(block, &dist)) { |
92 | | - status.code = common::kCodegenError; |
93 | | - status.msg = "Fail to cast date: create default date fail"; |
94 | | - return status; |
95 | | - } |
96 | 98 | ::std::string fn_name = "timestamp." + TypeName(src.GetType()); |
97 | 99 |
|
98 | 100 | auto cast_func = m_->getOrInsertFunction( |
|
0 commit comments