forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_expr_assign.cpp
More file actions
148 lines (137 loc) · 4.99 KB
/
Copy pathob_expr_assign.cpp
File metadata and controls
148 lines (137 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright (c) 2025 OceanBase.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define USING_LOG_PREFIX SQL_ENG
#include "sql/engine/expr/ob_expr_assign.h"
#include "sql/engine/ob_exec_context.h"
namespace oceanbase
{
using namespace common;
namespace sql
{
ObExprAssign::ObExprAssign(ObIAllocator &alloc)
: ObFuncExprOperator(alloc, T_OP_ASSIGN, N_ASSIGN, 2, NOT_VALID_FOR_GENERATED_COL, NOT_ROW_DIMENSION)
{
}
ObExprAssign::~ObExprAssign()
{
}
int ObExprAssign::calc_result_type2(ObExprResType &type,
ObExprResType &key,
ObExprResType &value,
common::ObExprTypeCtx &type_ctx) const
{
int ret = OB_SUCCESS;
UNUSED(type_ctx);
UNUSED(key);
ObObjType val_type = value.get_type();
if (ob_is_temporal_type(val_type)){
type.set_varchar();
type.set_collation_level(common::CS_LEVEL_IMPLICIT);
type.set_collation_type(common::ObCharset::get_default_collation(common::ObCharset::get_default_charset()));
} else if (ob_is_bit_tc(val_type)) {
type.set_uint64();
value.set_calc_type(ObUInt64Type);
} else if (OB_UNLIKELY(value.is_null())) {
type.set_varchar();
type.set_collation_level(common::CS_LEVEL_IMPLICIT);
type.set_collation_type(common::CS_TYPE_BINARY);
} else if (ob_is_enum_or_set_type(value.get_type())) {
type.set_varchar();
type.set_collation_level(value.get_collation_level());
type.set_collation_type(value.get_collation_type());
} else if (ob_is_collection_sql_type(value.get_type())) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("Variable value set to collection type is not supported", K(ret));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "Variable value set to collection type");
} else {
type.set_type(val_type);
type.set_collation_level(value.get_collation_level());
type.set_collation_type(value.get_collation_type());
}
type.set_precision(value.get_precision());
type.set_scale(value.get_scale());
//set length
if (ob_is_string_type(type.get_type())) {
type.set_full_length(value.get_length(), value.get_length_semantics());
}
value.set_calc_meta(type.get_obj_meta());
value.set_calc_accuracy(type.get_accuracy());
value.set_calc_collation_type(type.get_collation_type());
value.set_calc_collation_level(type.get_collation_level());
key.set_calc_type(ObVarcharType);
key.set_calc_collation_type(ObCharset::get_system_collation());
return ret;
}
int calc_assign_expr(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datum)
{
int ret = OB_SUCCESS;
ObDatum *key_res = NULL;
ObDatum *val_res = NULL;
ObSQLSessionInfo *session = ctx.exec_ctx_.get_my_session();
if (OB_ISNULL(session)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("session is NULL", K(ret));
} else if (OB_FAIL(expr.args_[0]->eval(ctx, key_res)) ||
OB_FAIL(expr.args_[1]->eval(ctx, val_res))) {
LOG_WARN("eval arg failed", K(ret));
} else {
ObObj obj;
ObObjMeta obj_meta;
ObSessionVariable sess_var;
if (val_res->is_null()) {
obj.set_null();
obj_meta.set_null();
// same as old engine. but why...
obj_meta.set_collation_level(CS_LEVEL_IMPLICIT);
obj_meta.set_collation_type(ObCharset::get_default_collation(
ObCharset::get_default_charset()));
} else {
obj_meta.set_type(expr.datum_meta_.type_);
obj_meta.set_scale(expr.datum_meta_.scale_);
obj_meta.set_collation_type(expr.datum_meta_.cs_type_);
obj_meta.set_collation_level(common::CS_LEVEL_IMPLICIT);
if (expr.args_[1]->obj_meta_.has_lob_header()) {
// use temp meta to session var,ensure flag in expr.args_[1](val_res) copy to dest
obj_meta.set_has_lob_header();
}
if (OB_FAIL(val_res->to_obj(obj, obj_meta))) {
LOG_WARN("to_obj failed", K(ret), K(expr), K(obj_meta));
}
}
if (OB_SUCC(ret)) {
sess_var.value_ = obj;
sess_var.meta_ = obj_meta;
}
if (OB_SUCC(ret) && OB_FAIL(session->replace_user_variable(
key_res->get_string(), sess_var))) {
LOG_WARN("replace user val failed", K(ret), K(key_res->get_string()));
} else {
res_datum.set_datum(*val_res);
}
}
return ret;
}
int ObExprAssign::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
ObExpr &rt_expr) const
{
int ret = OB_SUCCESS;
UNUSED(expr_cg_ctx);
UNUSED(raw_expr);
rt_expr.eval_func_ = calc_assign_expr;
return ret;
}
} //namespace sql
} //namespace oceanbase