fix bug time_zone=default when developing global time_zone formalize
This commit is contained in:
@ -2083,49 +2083,11 @@ int ObSysVarOnCheckFuncs::check_and_convert_time_zone(ObExecContext &ctx,
|
|||||||
common::ObObj &out_val)
|
common::ObObj &out_val)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
UNUSED(sys_var);
|
UNUSED(ctx);
|
||||||
UNUSED(set_var);
|
UNUSED(set_var);
|
||||||
|
UNUSED(sys_var);
|
||||||
int32_t sec_val = 0;
|
UNUSED(in_val);
|
||||||
int ret_more = OB_SUCCESS;
|
UNUSED(out_val);
|
||||||
bool check_timezone_valid = false;
|
|
||||||
bool is_oralce_mode = false;
|
|
||||||
ObSQLSessionInfo *session = ctx.get_my_session();
|
|
||||||
if (OB_ISNULL(session)) {
|
|
||||||
ret = OB_ERR_UNEXPECTED;
|
|
||||||
LOG_WARN("fail to get session info", K(ret), K(session));
|
|
||||||
} else {
|
|
||||||
is_oralce_mode = is_oracle_compatible(session->get_sql_mode());
|
|
||||||
ObString str = in_val.get_string();
|
|
||||||
if (OB_ISNULL(str.ptr()) || OB_UNLIKELY(str.length() <= 0)) {
|
|
||||||
ret = OB_ERR_UNKNOWN_TIME_ZONE;
|
|
||||||
LOG_WARN("invalid time zone offset", K(ret), K(str));
|
|
||||||
} else {
|
|
||||||
if (OB_FAIL(ObTimeConverter::str_to_offset(str, sec_val, ret_more, is_oralce_mode, check_timezone_valid))) {
|
|
||||||
if (ret != OB_ERR_UNKNOWN_TIME_ZONE) {
|
|
||||||
LOG_WARN("fail to convert time zone", K(sec_val), K(ret));
|
|
||||||
} else {
|
|
||||||
ret = OB_SUCCESS;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int64_t pos = 0;
|
|
||||||
const int64_t buf_len = 16;
|
|
||||||
char *tmp_buf = reinterpret_cast<char*>(ctx.get_allocator().alloc(buf_len));
|
|
||||||
if(OB_ISNULL(tmp_buf)) {
|
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
|
||||||
LOG_WARN("fail to allocate memory", K(ret), K(tmp_buf));
|
|
||||||
} else {
|
|
||||||
int32_t offset_min = static_cast<int32_t>(SEC_TO_MIN(sec_val));
|
|
||||||
const char *fmt_str = (offset_min < 0 ? "-%02d:%02d" : "+%02d:%02d");
|
|
||||||
if (OB_FAIL(databuff_printf(tmp_buf, buf_len, pos, fmt_str, abs(offset_min) / 60, abs(offset_min) % 60))) {
|
|
||||||
LOG_ERROR("fail to print offset_min information to tmp_buf", K(ret), K(tmp_buf), K(offset_min));
|
|
||||||
} else {
|
|
||||||
out_val.set_varchar(tmp_buf, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -273,7 +273,12 @@ int ObVariableSetExecutor::execute(ObExecContext &ctx, ObVariableSetStmt &stmt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (OB_SUCC(ret) && set_var.set_scope_ == ObSetVar::SET_SCOPE_GLOBAL) {
|
if (OB_SUCC(ret) && set_var.set_scope_ == ObSetVar::SET_SCOPE_GLOBAL) {
|
||||||
if (OB_FAIL(update_global_variables(ctx, stmt, set_var, value_obj))) {
|
if(set_var.var_name_ == OB_SV_TIME_ZONE) {
|
||||||
|
if(OB_FAIL(global_variable_timezone_formalize(ctx, value_obj))) {
|
||||||
|
LOG_WARN("failed to formalize global variables", K(ret));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (OB_SUCC(ret) && OB_FAIL(update_global_variables(ctx, stmt, set_var, value_obj))) {
|
||||||
LOG_WARN("failed to update global variables", K(ret));
|
LOG_WARN("failed to update global variables", K(ret));
|
||||||
} else { }
|
} else { }
|
||||||
}
|
}
|
||||||
@ -670,6 +675,49 @@ int ObVariableSetExecutor::update_global_variables(ObExecContext &ctx,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// formalize : '+8:00' ---> '+08:00'
|
||||||
|
int ObVariableSetExecutor::global_variable_timezone_formalize(ObExecContext &ctx, ObObj &in_val) {
|
||||||
|
int ret = OB_SUCCESS;
|
||||||
|
|
||||||
|
int32_t sec_val = 0;
|
||||||
|
int ret_more = OB_SUCCESS;
|
||||||
|
bool check_timezone_valid = false;
|
||||||
|
bool is_oralce_mode = false;
|
||||||
|
ObSQLSessionInfo *session = ctx.get_my_session();
|
||||||
|
if (OB_ISNULL(session)) {
|
||||||
|
ret = OB_ERR_UNEXPECTED;
|
||||||
|
LOG_WARN("fail to get session info", K(ret), K(session));
|
||||||
|
} else {
|
||||||
|
is_oralce_mode = is_oracle_compatible(session->get_sql_mode());
|
||||||
|
ObString str = in_val.get_string();
|
||||||
|
if (OB_FAIL(ObTimeConverter::str_to_offset(str, sec_val, ret_more, is_oralce_mode, check_timezone_valid))) {
|
||||||
|
if (ret != OB_ERR_UNKNOWN_TIME_ZONE) {
|
||||||
|
LOG_WARN("fail to convert time zone", K(sec_val), K(ret));
|
||||||
|
} else {
|
||||||
|
ret = OB_SUCCESS;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int64_t pos = 0;
|
||||||
|
const int64_t buf_len = 16;
|
||||||
|
char *tmp_buf = reinterpret_cast<char*>(ctx.get_allocator().alloc(buf_len));
|
||||||
|
if(OB_ISNULL(tmp_buf)) {
|
||||||
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
|
LOG_WARN("fail to allocate memory", K(ret), K(tmp_buf));
|
||||||
|
} else {
|
||||||
|
int32_t offset_min = static_cast<int32_t>(SEC_TO_MIN(sec_val));
|
||||||
|
const char *fmt_str = (offset_min < 0 ? "-%02d:%02d" : "+%02d:%02d");
|
||||||
|
if (OB_FAIL(databuff_printf(tmp_buf, buf_len, pos, fmt_str, abs(offset_min) / 60, abs(offset_min) % 60))) {
|
||||||
|
LOG_ERROR("fail to print offset_min information to tmp_buf", K(ret), K(tmp_buf), K(offset_min));
|
||||||
|
} else {
|
||||||
|
in_val.set_varchar(tmp_buf, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int ObVariableSetExecutor::check_and_convert_sys_var(ObExecContext &ctx,
|
int ObVariableSetExecutor::check_and_convert_sys_var(ObExecContext &ctx,
|
||||||
const ObSetVar &set_var,
|
const ObSetVar &set_var,
|
||||||
ObBasicSysVar &sys_var,
|
ObBasicSysVar &sys_var,
|
||||||
|
|||||||
@ -90,6 +90,7 @@ private:
|
|||||||
ObDDLStmt &stmt,
|
ObDDLStmt &stmt,
|
||||||
const share::ObSetVar &set_var,
|
const share::ObSetVar &set_var,
|
||||||
const common::ObObj &value_obj);
|
const common::ObObj &value_obj);
|
||||||
|
int global_variable_timezone_formalize(ObExecContext &ctx, ObObj &val);
|
||||||
private:
|
private:
|
||||||
DISALLOW_COPY_AND_ASSIGN(ObVariableSetExecutor);
|
DISALLOW_COPY_AND_ASSIGN(ObVariableSetExecutor);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
connect (conn_admin_tz, $OBMYSQL_MS0,admin,$OBMYSQL_PWD,test,$OBMYSQL_PORT);
|
connect (conn_admin_tz, $OBMYSQL_MS0,admin,$OBMYSQL_PWD,test,$OBMYSQL_PORT);
|
||||||
connection conn_admin_tz;
|
connection conn_admin_tz;
|
||||||
|
set session ob_query_timeout = 20000000;
|
||||||
select count(*) c1 from oceanbase.__all_tenant_time_zone;
|
select count(*) c1 from oceanbase.__all_tenant_time_zone;
|
||||||
select count(*) c1 from oceanbase.__all_tenant_time_zone_name;
|
select count(*) c1 from oceanbase.__all_tenant_time_zone_name;
|
||||||
select count(*) c1 from oceanbase.__all_tenant_time_zone_transition;
|
select count(*) c1 from oceanbase.__all_tenant_time_zone_transition;
|
||||||
|
|||||||
Reference in New Issue
Block a user