cherry-pick bugfix from 3.1 to open source branch

This commit is contained in:
obdev 2021-07-14 17:48:15 +08:00 committed by wangzelin.wzl
parent 131c2cf658
commit a997b23808
19 changed files with 14233 additions and 14190 deletions

View File

@ -897,6 +897,7 @@ int ObTimeConverter::datetime_to_double(int64_t value, const ObTimeZoneInfo* tz_
return ret;
}
// ObDatetimeType: tz_info = NULL. ObTimestampType: tz_info != NULL.
int ObTimeConverter::datetime_to_str(int64_t value, const ObTimeZoneInfo* tz_info, const ObString& nls_format,
int16_t scale, char* buf, int64_t buf_len, int64_t& pos, bool with_delim)
{
@ -1077,12 +1078,6 @@ int ObTimeConverter::datetime_to_timestamp(int64_t dt_value, const ObTimeZoneInf
bool is_timestamp = (tz_info != NULL);
if (OB_FAIL(sub_timezone_offset(tz_info, is_timestamp, ObString(), ts_value))) {
LOG_WARN("failed to adjust value with time zone offset", K(ret));
// timestamp less than 0000-01-02 00:00:00 utc or greater than 9999-12-30 23:59:59 utc is invalid.
// when cast datetime to timestamp, local time of timestamp is equal to origi datetime value.
// so we need to compare result of sub_timezone_offset with MAX/MIN time.
} else if (ts_value > MYSQL_TIMESTAMP_MAX_VAL || ts_value < MYSQL_TIMESTAMP_MIN_VAL) {
ret = OB_INVALID_DATE_VALUE;
LOG_WARN("invalid timestamp", K(ret), K(ts_value));
}
return ret;
}
@ -2660,7 +2655,11 @@ int ObTimeConverter::ob_time_to_str(
if (HAS_TYPE_DATE(mode)) {
if (OB_UNLIKELY(parts[DT_YEAR] > 9999) || OB_UNLIKELY(parts[DT_YEAR] < 0) || OB_UNLIKELY(parts[DT_MON] > 12) ||
OB_UNLIKELY(parts[DT_MON] < 0) || OB_UNLIKELY(parts[DT_MDAY] > 31) || OB_UNLIKELY(parts[DT_MDAY] < 0)) {
ret = OB_ERR_UNEXPECTED;
if (parts[DT_YEAR] > 9999 || parts[DT_YEAR] < 0) {
ret = OB_ERR_DATETIME_INTERVAL_INTERNAL_ERROR;
} else {
ret = OB_ERR_UNEXPECTED;
}
LOG_WARN("Unexpected time", K(ret), K(parts[DT_YEAR]), K(parts[DT_MON]), K(parts[DT_MDAY]));
} else if (OB_LIKELY(with_delim && (buf_len - pos) > 10) // format 0000-00-00
|| OB_LIKELY(!with_delim && (buf_len - pos) > 8)) { // format yyyymmdd
@ -4757,11 +4756,6 @@ int ObTimeConverter::ob_time_to_datetime(ObTime& ob_time, const ObTimeConvertCtx
tz_id_pos_map = NULL;
literal_tz_info = NULL;
}
if (OB_SUCC(ret) && cvrt_ctx.is_timestamp_ &&
(value > MYSQL_TIMESTAMP_MAX_VAL || value < MYSQL_TIMESTAMP_MIN_VAL)) {
ret = OB_INVALID_DATE_VALUE;
LOG_WARN("invalid timestamp", K(ret), K(value));
}
}
return ret;
}

View File

@ -144,8 +144,6 @@ extern const int64_t USECS_PER_MIN;
#define TIMESTAMP_MAX_VAL 253402272000
#define DATETIME_MAX_VAL 253402300799999999
#define DATETIME_MIN_VAL -62167132800000000
#define MYSQL_TIMESTAMP_MAX_VAL 253402214399999999
#define MYSQL_TIMESTAMP_MIN_VAL -62167046400000000
#define ORACLE_DATETIME_MIN_VAL -62135596800000000 // start from '0001-1-1 00:00:00'
#define TIME_MAX_HOUR 838

View File

@ -39399,8 +39399,8 @@ int ObTimeZoneInfoPos::compare_upgrade(const ObTimeZoneInfoPos& other, bool& is_
{
int ret = OB_SUCCESS;
is_equal = false;
const common::ObSArray<ObTZTransitionTypeInfo>& other_type = other.get_tz_tran_types();
const common::ObSArray<ObTZTransitionTypeInfo>& tz_tran_types = get_tz_tran_types();
const common::ObSArray<ObTZTransitionTypeInfo, ObMalloc>& other_type = other.get_tz_tran_types();
const common::ObSArray<ObTZTransitionTypeInfo, ObMalloc>& tz_tran_types = get_tz_tran_types();
if (OB_UNLIKELY(tz_id_ != other.get_tz_id()) || OB_UNLIKELY(0 != other.get_tz_name().compare(tz_name_)) ||
OB_UNLIKELY(default_type_ != other.get_default_trans_type()) ||
@ -39464,7 +39464,7 @@ int ObTimeZoneInfoPos::get_timezone_offset(
int64_t value, int32_t& offset_sec, common::ObString& tz_abbr_str, int32_t& tran_type_id) const
{
int ret = OB_SUCCESS;
const common::ObSArray<ObTZTransitionTypeInfo>& tz_tran_types = get_tz_tran_types();
const common::ObSArray<ObTZTransitionTypeInfo, ObMalloc>& tz_tran_types = get_tz_tran_types();
int64_t type_cnt = tz_tran_types.count();
int64_t type_idx = 0;
if (OB_UNLIKELY(false == is_valid())) {
@ -39516,7 +39516,7 @@ int ObTimeZoneInfoPos::get_timezone_offset(
const int32_t tran_type_id, common::ObString& tz_abbr_str, int32_t& offset_sec) const
{
int ret = OB_SUCCESS;
const common::ObSArray<ObTZTransitionTypeInfo>& tz_tran_types = get_tz_tran_types();
const common::ObSArray<ObTZTransitionTypeInfo, ObMalloc>& tz_tran_types = get_tz_tran_types();
int64_t type_idx = 0;
if (OB_UNLIKELY(false == is_valid())) {
ret = OB_ERR_UNEXPECTED;
@ -39542,7 +39542,7 @@ int ObTimeZoneInfoPos::get_timezone_sub_offset(
int64_t value, const ObString& tz_abbr_str, int32_t& offset_sec, int32_t& tz_id, int32_t& tran_type_id) const
{
int ret = OB_SUCCESS;
const common::ObSArray<ObTZRevertTypeInfo>& tz_revt_types = get_tz_revt_types();
const common::ObSArray<ObTZRevertTypeInfo, ObMalloc>& tz_revt_types = get_tz_revt_types();
tz_id = static_cast<int32_t>(tz_id_);
int64_t type_idx = 0;
if (OB_UNLIKELY(!is_valid())) {
@ -39601,10 +39601,10 @@ int ObTimeZoneInfoPos::calc_revt_types()
ret = OB_ERR_UNEXPECTED;
LOG_WARN("tz info is invalid", K(ret));
} else {
common::ObSArray<ObTZRevertTypeInfo>& tz_revt_types = tz_revt_types_[get_curr_idx() % 2];
common::ObSArray<ObTZRevertTypeInfo, ObMalloc>& tz_revt_types = tz_revt_types_[get_curr_idx() % 2];
tz_revt_types.reset();
ObTZRevertTypeInfo revt_type_info;
const common::ObSArray<ObTZTransitionTypeInfo>& tz_tran_types = get_tz_tran_types();
const common::ObSArray<ObTZTransitionTypeInfo, ObMalloc>& tz_tran_types = get_tz_tran_types();
// add first revert type, type info is from default type
revt_type_info.type_class_ = ObTZRevertTypeInfo::NORMAL;
@ -39678,8 +39678,8 @@ OB_DEF_SERIALIZE(ObTimeZoneInfoPos)
{
int ret = OB_SUCCESS;
ObString tz_name_str(static_cast<ObString::obstr_size_t>(strlen(tz_name_)), tz_name_);
const common::ObSArray<ObTZTransitionTypeInfo>& tz_tran_types = get_tz_tran_types();
const common::ObSArray<ObTZRevertTypeInfo>& tz_revt_types = get_tz_revt_types();
const common::ObSArray<ObTZTransitionTypeInfo, ObMalloc>& tz_tran_types = get_tz_tran_types();
const common::ObSArray<ObTZRevertTypeInfo, ObMalloc>& tz_revt_types = get_tz_revt_types();
LST_DO_CODE(OB_UNIS_ENCODE, tz_id_, default_type_, tz_tran_types, tz_revt_types, tz_name_str);
return ret;
}
@ -39689,8 +39689,8 @@ OB_DEF_DESERIALIZE(ObTimeZoneInfoPos)
int ret = OB_SUCCESS;
ObString tz_name_str;
curr_idx_ = 0;
common::ObSArray<ObTZTransitionTypeInfo>& tz_tran_types = tz_tran_types_[0];
common::ObSArray<ObTZRevertTypeInfo>& tz_revt_types = tz_revt_types_[0];
common::ObSArray<ObTZTransitionTypeInfo, ObMalloc>& tz_tran_types = tz_tran_types_[0];
common::ObSArray<ObTZRevertTypeInfo, ObMalloc>& tz_revt_types = tz_revt_types_[0];
LST_DO_CODE(OB_UNIS_DECODE, tz_id_, default_type_, tz_tran_types, tz_revt_types, tz_name_str);
if (OB_FAIL(ret)) {
} else if (OB_UNLIKELY(tz_name_str.length() + 1 > OB_MAX_TZ_NAME_LEN)) {

View File

@ -576,27 +576,27 @@ public:
{
++curr_idx_;
}
const common::ObSArray<ObTZTransitionTypeInfo>& get_tz_tran_types() const
const common::ObSArray<ObTZTransitionTypeInfo, ObMalloc>& get_tz_tran_types() const
{
return tz_tran_types_[get_curr_idx() % 2];
}
const common::ObSArray<ObTZRevertTypeInfo>& get_tz_revt_types() const
const common::ObSArray<ObTZRevertTypeInfo, ObMalloc>& get_tz_revt_types() const
{
return tz_revt_types_[get_curr_idx() % 2];
}
const common::ObSArray<ObTZTransitionTypeInfo>& get_next_tz_tran_types() const
const common::ObSArray<ObTZTransitionTypeInfo, ObMalloc>& get_next_tz_tran_types() const
{
return tz_tran_types_[get_next_idx() % 2];
}
const common::ObSArray<ObTZRevertTypeInfo>& get_next_tz_revt_types() const
const common::ObSArray<ObTZRevertTypeInfo, ObMalloc>& get_next_tz_revt_types() const
{
return tz_revt_types_[get_next_idx() % 2];
}
common::ObSArray<ObTZTransitionTypeInfo>& get_next_tz_tran_types()
common::ObSArray<ObTZTransitionTypeInfo, ObMalloc>& get_next_tz_tran_types()
{
return tz_tran_types_[get_next_idx() % 2];
}
common::ObSArray<ObTZRevertTypeInfo>& get_next_tz_revt_types()
common::ObSArray<ObTZRevertTypeInfo, ObMalloc>& get_next_tz_revt_types()
{
return tz_revt_types_[get_next_idx() % 2];
}
@ -621,9 +621,9 @@ private:
there are no transitions at all.*/
ObTZTransitionTypeInfo default_type_;
// used for utc time -> local time
common::ObSArray<ObTZTransitionTypeInfo> tz_tran_types_[2];
common::ObSArray<ObTZTransitionTypeInfo, ObMalloc> tz_tran_types_[2];
// used for local time -> utc time
common::ObSArray<ObTZRevertTypeInfo> tz_revt_types_[2];
common::ObSArray<ObTZRevertTypeInfo, ObMalloc> tz_revt_types_[2];
uint32_t curr_idx_;
char tz_name_[common::OB_MAX_TZ_NAME_LEN];
};

View File

@ -206,7 +206,7 @@ int ObTimeZoneInfoManager::fetch_time_zone_info_from_tenant_table(const int64_t
ret = OB_ERR_UNEXPECTED;
LOG_WARN("fail to get result", K(result), K(ret));
} else if (OB_FAIL(fill_tz_info_map(*result, tz_info_map_))) {
LOG_WARN("fail to fill tz_info_map", K(ret));
LOG_ERROR("fail to fill tz_info_map", K(ret));
} else {
last_version_ = current_tz_version;
LOG_INFO("success to fetch tz_info map",
@ -243,7 +243,7 @@ int ObTimeZoneInfoManager::fetch_time_zone_info_from_sys_table()
LOG_WARN("fail to get result", K(result), K(ret));
} else {
if (OB_FAIL(fill_tz_info_map(*result, tz_info_map_))) {
LOG_WARN("fail to fill tz_info_map", K(ret));
LOG_ERROR("fail to fill tz_info_map", K(ret));
} else {
//(void)print_tz_info_map();
if (OB_UNLIKELY(false == is_usable_)) {
@ -285,6 +285,7 @@ int ObTimeZoneInfoManager::set_tz_info_map(
LOG_WARN("fail to insert new_tz_info to tz_info_id_map", KPC(tz_pos_value), K(ret));
} else if (OB_FAIL(tz_info_map.name_map_.insert_and_get(new_tz_info.get_tz_name(), name_id_value))) {
tz_info_map.id_map_.revert(tz_pos_value);
tz_info_map.id_map_.del(new_tz_info.get_tz_id());
LOG_WARN("fail to insert new_tz_info to tz_info_name_map_", K(name_id_value), K(ret));
} else {
tz_info_map.id_map_.revert(tz_pos_value);
@ -297,8 +298,8 @@ int ObTimeZoneInfoManager::set_tz_info_map(
// do nothing
} else {
LOG_INFO("need to upgrade transition time", KPC(stored_tz_info), K(new_tz_info));
common::ObSArray<ObTZTransitionTypeInfo>& next_tz_tran_types = stored_tz_info->get_next_tz_tran_types();
common::ObSArray<ObTZRevertTypeInfo>& next_tz_revt_types = stored_tz_info->get_next_tz_revt_types();
common::ObSArray<ObTZTransitionTypeInfo, ObMalloc>& next_tz_tran_types = stored_tz_info->get_next_tz_tran_types();
common::ObSArray<ObTZRevertTypeInfo, ObMalloc>& next_tz_revt_types = stored_tz_info->get_next_tz_revt_types();
if (OB_FAIL(next_tz_tran_types.assign(new_tz_info.get_tz_tran_types()))) {
LOG_WARN("fail to assign next_tz_tran_types", K(new_tz_info.get_tz_tran_types()), K(ret));
} else if (OB_FAIL(next_tz_revt_types.assign(new_tz_info.get_tz_revt_types()))) {
@ -388,11 +389,17 @@ int ObTimeZoneInfoManager::fill_tz_info_map(sqlclient::ObMySQLResult& result, Ob
EXTRACT_BOOL_FIELD_MYSQL(result, "is_dst", tz_tran_type.info_.is_dst_);
if (OB_SUCC(ret)) {
EXTRACT_INT_FIELD_MYSQL(result, "transition_time", tz_tran_type.lower_time_, int64_t);
// is NULL transition time
if (OB_ERR_NULL_VALUE == ret) {
ret = OB_SUCCESS;
is_tran_time_null = true;
int64_t int_value = 0;
if (OB_FAIL(result.get_int("transition_time", int_value))) {
//is NULL transition time
if (OB_ERR_NULL_VALUE == ret) {
ret = OB_SUCCESS;
is_tran_time_null = true;
} else {
LOG_WARN("fail to get column transition_time in row", K(ret));
}
} else {
tz_tran_type.lower_time_ = int_value;
}
}

View File

@ -2305,22 +2305,33 @@ static int number_date(
{
int ret = OB_SUCCESS;
ObObj int64;
int64_t int_value = 0;
int32_t value = 0;
if (OB_UNLIKELY(ObNumberTC != in.get_type_class() || ObDateTC != ob_obj_type_class(expect_type))) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("invalid input type", K(ret), K(in), K(expect_type));
} else if (OB_FAIL(in.get_number().extract_valid_int64_with_trunc(int_value))) {
if (OB_DATA_OUT_OF_RANGE == ret) {
ret = OB_SUCCESS;
int_value = INT64_MAX;
LOG_ERROR("invalid input type",
K(ret), K(in), K(expect_type));
} else {
int64_t int_part = 0;
int64_t dec_part = 0;
const number::ObNumber nmb = in.get_number();
if (nmb.is_negative()) {
ret = OB_INVALID_DATE_VALUE;
LOG_WARN("invalid date value", K(ret), K(nmb));
} else if (!nmb.is_int_parts_valid_int64(int_part, dec_part)) {
ret = OB_INVALID_DATE_VALUE;
LOG_WARN("invalid date format", K(ret), K(nmb));
} else {
LOG_WARN("extract valid int64 failed", K(ret), K(in));
ret = ObTimeConverter::int_to_date(int_part, value);
if (OB_SUCC(ret) && OB_UNLIKELY(dec_part > 0)) {
LOG_WARN("invalid date value with decimal part", K(ret));
if (!CM_IS_WARN_ON_FAIL(cast_mode)) {
ret = OB_INVALID_DATE_VALUE;
}
}
}
}
if (OB_SUCC(ret)) {
int64.set_int(int_value);
if (CAST_FAIL(int_date(expect_type, params, int64, out, cast_mode))) {
LOG_WARN("int to date failed", K(ret));
if (CAST_FAIL(ret)) {
} else {
SET_RES_DATE(out);
}
}
return ret;
@ -2598,17 +2609,8 @@ static int datetime_datetime(
} else {
int64_t value = in.get_datetime();
if (ObDateTimeType == in.get_type() && ObTimestampType == expect_type) {
if (OB_FAIL(ObTimeConverter::datetime_to_timestamp(in.get_datetime(), params.dtc_params_.tz_info_, value))) {
LOG_WARN("datetime to timestamp failed", K(ret), K(in), K(value));
if (OB_ERR_UNEXPECTED_TZ_TRANSITION == ret) {
ret = OB_INVALID_DATE_VALUE;
} else if (OB_INVALID_DATE_VALUE == ret) {
if (CM_IS_WARN_ON_FAIL(cast_mode)) {
params.warning_ = OB_INVALID_DATE_VALUE;
ret = OB_SUCCESS;
}
}
}
ret = ObTimeConverter::datetime_to_timestamp(in.get_datetime(), params.dtc_params_.tz_info_, value);
ret = OB_ERR_UNEXPECTED_TZ_TRANSITION == ret ? OB_INVALID_DATE_VALUE : ret;
} else if (ObTimestampType == in.get_type() && ObDateTimeType == expect_type) {
ret = ObTimeConverter::timestamp_to_datetime(in.get_datetime(), params.dtc_params_.tz_info_, value);
}
@ -3150,6 +3152,26 @@ static int time_datetime(
return ret;
}
static int time_date(
const ObObjType expect_type, ObObjCastParams& params, const ObObj& in, ObObj& out, const ObCastMode cast_mode)
{
int ret = OB_SUCCESS;
const ObTimeZoneInfo* tz_info = params.dtc_params_.tz_info_;
int32_t value = 0;
if (OB_UNLIKELY(ObTimeTC != in.get_type_class() || ObDateTC != ob_obj_type_class(expect_type))) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("invalid input type",
K(ret), K(in), K(expect_type));
} else if (OB_FAIL(ObTimeConverter::datetime_to_date(params.cur_time_, tz_info, value))) {
LOG_WARN("datetime_to_date failed", K(ret), K(params.cur_time_));
} else {
out.set_date(value);
}
SET_RES_ACCURACY(DEFAULT_PRECISION_FOR_TEMPORAL, DEFAULT_SCALE_FOR_DATE, DEFAULT_LENGTH_FOR_TEMPORAL);
UNUSED(cast_mode);
return ret;
}
static int time_string(
const ObObjType expect_type, ObObjCastParams& params, const ObObj& in, ObObj& out, const ObCastMode cast_mode)
{
@ -3318,6 +3340,27 @@ static int year_number(
return ret;
}
static int year_date(
const ObObjType expect_type, ObObjCastParams& params, const ObObj& in, ObObj& out, const ObCastMode cast_mode)
{
int ret = OB_SUCCESS;
int64_t in_value = 0;
if (OB_UNLIKELY(ObYearTC != in.get_type_class() || ObDateTC != ob_obj_type_class(expect_type))) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("invalid input type",
K(ret), K(in), K(expect_type));
} else if (OB_FAIL(ObTimeConverter::year_to_int(in.get_year(), in_value))) {
} else {
int32_t value = 0;
if (CAST_FAIL(ObTimeConverter::int_to_date(in_value, value))) {
} else {
SET_RES_DATE(out);
}
}
SET_RES_ACCURACY(DEFAULT_PRECISION_FOR_TEMPORAL, DEFAULT_SCALE_FOR_DATE, DEFAULT_LENGTH_FOR_TEMPORAL);
return ret;
}
static int year_string(
const ObObjType expect_type, ObObjCastParams& params, const ObObj& in, ObObj& out, const ObCastMode cast_mode)
{
@ -3759,6 +3802,10 @@ static int string_year(
LOG_USER_ERROR(OB_NOT_SUPPORTED, "Cast to blob type");
} else if (OB_FAIL(string_int(
ObIntType, params, in, int64, CM_UNSET_STRING_INTEGER_TRUNC(CM_SET_WARN_ON_FAIL(cast_mode))))) {
} else if (0 == int64.get_int()) {
const uint8_t base_year = 100;
uint8_t value = 4 == in.get_string().length() ? ObTimeConverter::ZERO_YEAR : base_year;
SET_RES_YEAR(out);
} else if (CAST_FAIL(int_year(ObYearType, params, int64, out, cast_mode))) {
} else if (CAST_FAIL(params.warning_)) {
}
@ -5784,7 +5831,7 @@ ObObjCastFunc OB_OBJ_CAST[ObMaxTC][ObMaxTC] = {
time_double, /*double*/
time_number, /*number*/
time_datetime, /*datetime*/
cast_not_support, /*date*/
time_date, /*date*/
cast_identity, /*time*/
cast_not_support, /*year*/
time_string, /*string*/
@ -5809,7 +5856,7 @@ ObObjCastFunc OB_OBJ_CAST[ObMaxTC][ObMaxTC] = {
year_double, /*double*/
year_number, /*number*/
cast_not_support, /*datetime*/
cast_not_support, /*date*/
year_date, /*date*/
cast_not_support, /*time*/
cast_identity, /*year*/
year_string, /*string*/
@ -8253,6 +8300,21 @@ int ob_obj_to_ob_time_with_date(
}
break;
}
case ObNumberTC: {
int64_t int_part = 0;
int64_t dec_part = 0;
const number::ObNumber num = obj.get_number();
if (num.is_negative()) {
ret = OB_INVALID_DATE_FORMAT;
LOG_WARN("invalid date format", K(ret), K(num));
} else if (!num.is_int_parts_valid_int64(int_part, dec_part)) {
ret = OB_INVALID_DATE_FORMAT;
LOG_WARN("invalid date format", K(ret), K(num));
} else {
ret = ObTimeConverter::int_to_ob_time_with_date(int_part, ob_time, is_dayofmonth);
}
break;
}
default: {
ret = OB_NOT_SUPPORTED;
}
@ -8309,6 +8371,17 @@ int ob_obj_to_ob_time_without_date(const ObObj& obj, const ObTimeZoneInfo* tz_in
}
break;
}
case ObNumberTC: {
const char *num_format = obj.get_number().format();
if (OB_ISNULL(num_format)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("number format value is null", K(ret));
} else {
ObString num_str(num_format);
ret = ObTimeConverter::str_to_ob_time_without_date(num_str, ob_time);
}
break;
}
default: {
ret = OB_NOT_SUPPORTED;
}

View File

@ -813,6 +813,14 @@ static OB_INLINE int common_string_year(const ObExpr& expr, const ObString& in_s
tmp_res.pack_ = sizeof(tmp_int);
if (OB_FAIL(common_string_int(expr, extra, in_str, is_str_int_cast, tmp_res, warning))) {
LOG_WARN("common_string_int failed", K(ret), K(in_str));
} else if (0 == tmp_int) {
// cast '0000' to year, result is 0. cast '0'/'00'/'00000' to year, result is 2000.
if (4 == in_str.length()) {
SET_RES_YEAR(ObTimeConverter::ZERO_YEAR);
} else {
const uint8_t base_year = 100;
SET_RES_YEAR(base_year);
}
} else {
if (CAST_FAIL(common_int_year(expr, tmp_int, res_datum, warning))) {
LOG_WARN("common_int_year failed", K(ret), K(tmp_int));
@ -1493,13 +1501,13 @@ static int common_number_datetime(
int64_t int_part = 0;
int64_t dec_part = 0;
if (nmb.is_negative()) {
ret = OB_INVALID_DATE_FORMAT;
LOG_WARN("invalid date format", K(ret), K(nmb));
ret = OB_INVALID_DATE_VALUE;
LOG_WARN("invalid datetime value", K(ret), K(nmb));
} else if ((ObTimestampType == out_type && nmb.is_decimal())) {
ret = OB_INVALID_DATE_FORMAT;
ret = OB_INVALID_DATE_VALUE;
LOG_WARN("invalid date format", K(ret), K(nmb));
} else if (!nmb.is_int_parts_valid_int64(int_part, dec_part)) {
ret = OB_INVALID_DATE_FORMAT;
ret = OB_INVALID_DATE_VALUE;
LOG_WARN("invalid date format", K(ret), K(nmb));
} else {
ret = ObTimeConverter::int_to_datetime(int_part, dec_part, cvrt_ctx, out_val);
@ -2236,20 +2244,32 @@ CAST_FUNC_NAME(number, date)
{
EVAL_ARG()
{
int64_t int_value = 0;
int32_t out_val = 0;
int warning = OB_SUCCESS;
const number::ObNumber nmb(child_res->get_number());
// Converting number to date should do trunc to number, rounding down the decimal place
if (OB_FAIL(nmb.extract_valid_int64_with_trunc(int_value))) {
if (OB_DATA_OUT_OF_RANGE == ret) {
ret = OB_SUCCESS;
int_value = INT64_MAX;
} else {
LOG_WARN("extract valid int64 failed", K(ret), K(nmb));
int64_t int_part = 0;
int64_t dec_part = 0;
if (nmb.is_negative()) {
ret = OB_INVALID_DATE_VALUE;
LOG_WARN("invalid date value", K(ret), K(nmb));
} else if (!nmb.is_int_parts_valid_int64(int_part, dec_part)) {
ret = OB_INVALID_DATE_VALUE;
LOG_WARN("invalid date format", K(ret), K(nmb));
} else {
ret = ObTimeConverter::int_to_date(int_part, out_val);
if (OB_SUCC(ret) && OB_UNLIKELY(dec_part > 0)) {
LOG_WARN("invalid date value with decimal part", K(ret));
if (!CM_IS_WARN_ON_FAIL(expr.extra_)) {
ret = OB_INVALID_DATE_VALUE;
}
}
LOG_DEBUG("stt, end common number date", K(int_part), K(dec_part), K(out_val), K(ret));
}
if (OB_SUCC(ret) && CAST_FAIL(common_int_date(expr, int_value, res_datum))) {
LOG_WARN("common_in_date failed", K(ret), K(int_value));
if (CAST_FAIL(ret)) {
} else {
SET_RES_DATE(out_val);
LOG_DEBUG("stt, number to date", K(nmb), K(out_val), K(ret), K(warning));
}
}
return ret;
@ -2762,23 +2782,15 @@ CAST_FUNC_NAME(datetime, datetime)
{
GET_SESSION()
{
int warning = OB_SUCCESS;
int64_t in_val = child_res->get_int();
int64_t out_val = in_val;
ObObjType in_type = expr.args_[0]->datum_meta_.type_;
ObObjType out_type = expr.datum_meta_.type_;
if (ObDateTimeType == in_type && ObTimestampType == out_type) {
if (OB_FAIL(ObTimeConverter::datetime_to_timestamp(in_val, session->get_timezone_info(), out_val))) {
LOG_WARN("datetime to timestamp failed", K(ret), K(in_val), K(out_val));
if (OB_ERR_UNEXPECTED_TZ_TRANSITION == ret) {
ret = OB_INVALID_DATE_VALUE;
} else if (OB_INVALID_DATE_VALUE == ret) {
if (CM_IS_WARN_ON_FAIL(expr.extra_)) {
warning = OB_INVALID_DATE_VALUE;
ret = OB_SUCCESS;
}
}
}
ret = ObTimeConverter::datetime_to_timestamp(in_val,
session->get_timezone_info(),
out_val);
ret = OB_ERR_UNEXPECTED_TZ_TRANSITION == ret ? OB_INVALID_DATE_VALUE : ret;
} else if (ObTimestampType == in_type && ObDateTimeType == out_type) {
ret = ObTimeConverter::timestamp_to_datetime(out_val, session->get_timezone_info(), out_val);
}
@ -3227,6 +3239,21 @@ CAST_FUNC_NAME(year, string)
return ret;
}
CAST_FUNC_NAME(year, date)
{
EVAL_ARG()
{
uint8_t in_val = child_res->get_uint8();
int64_t val_int = 0;
if (OB_FAIL(common_year_int(expr, ObIntType, in_val, val_int))) {
LOG_WARN("common_year_int failed", K(ret), K(in_val));
} else if (OB_FAIL(common_int_date(expr, val_int, res_datum))) {
LOG_WARN("common_int_date failed", K(ret), K(val_int));
}
}
return ret;
}
CAST_FUNC_NAME(year, bit)
{
EVAL_ARG()
@ -3814,6 +3841,26 @@ CAST_FUNC_NAME(time, datetime)
return ret;
}
CAST_FUNC_NAME(time, date)
{
EVAL_ARG()
{
GET_SESSION()
{
int32_t out_val = 0;
ObPhysicalPlanCtx *phy_plan_ctx = ctx.exec_ctx_.get_physical_plan_ctx();
int64_t cur_time = phy_plan_ctx ? phy_plan_ctx->get_cur_time().get_datetime() : 0;
if (OB_FAIL(ObTimeConverter::datetime_to_date(cur_time, session->get_timezone_info(),
out_val))) {
LOG_WARN("datetime_to_date failed", K(ret), K(cur_time));
} else {
res_datum.set_date(out_val);
}
}
}
return ret;
}
CAST_FUNC_NAME(time, string)
{
EVAL_ARG()
@ -7021,7 +7068,7 @@ ObExpr::EvalFunc OB_DATUM_CAST_MYSQL_IMPLICIT[ObMaxTC][ObMaxTC] = {
time_double, /*double*/
time_number, /*number*/
time_datetime, /*datetime*/
cast_not_support, /*date*/
time_date, /*date*/
cast_eval_arg, /*time*/
cast_not_support, /*year*/
time_string, /*string*/
@ -7046,7 +7093,7 @@ ObExpr::EvalFunc OB_DATUM_CAST_MYSQL_IMPLICIT[ObMaxTC][ObMaxTC] = {
year_double, /*double*/
year_number, /*number*/
cast_not_support, /*datetime*/
cast_not_support, /*date*/
year_date, /*date*/
cast_not_support, /*time*/
cast_eval_arg, /*year*/
year_string, /*string*/
@ -7522,10 +7569,29 @@ int ob_datum_to_ob_time_with_date(const ObDatum& datum, const ObObjType type, co
ret = ObTimeConverter::str_to_ob_time_with_date(datum.get_string(), ob_time, &res_scale, is_dayofmonth);
break;
}
case ObNumberTC: {
int64_t int_part = 0;
int64_t dec_part = 0;
const number::ObNumber num(datum.get_number());
if (num.is_negative()) {
ret = OB_INVALID_DATE_FORMAT;
LOG_WARN("invalid date format", K(ret), K(num));
} else if (!num.is_int_parts_valid_int64(int_part, dec_part)) {
ret = OB_INVALID_DATE_FORMAT;
LOG_WARN("invalid date format", K(ret), K(num));
} else {
ret = ObTimeConverter::int_to_ob_time_with_date(int_part, ob_time, is_dayofmonth);
if (OB_SUCC(ret)) {
ob_time.parts_[DT_USEC] = (dec_part + 500) / 1000;
}
}
break;
}
default: {
ret = OB_NOT_SUPPORTED;
}
}
LOG_DEBUG("end ob_datum_to_ob_time_with_date", K(type), K(cur_ts_value), K(ob_time), K(ret));
return ret;
}
@ -7583,10 +7649,32 @@ int ob_datum_to_ob_time_without_date(
}
break;
}
case ObNumberTC: {
number::ObNumber num(datum.get_number());
const char *num_format = num.format();
if (OB_ISNULL(num_format)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("number format value is null", K(ret));
} else {
ObString num_str(num_format);
if (OB_FAIL(ObTimeConverter::str_to_ob_time_without_date(num_str, ob_time))) {
LOG_WARN("str to obtime without date failed", K(ret));
} else {
int64_t value = ObTimeConverter::ob_time_to_time(ob_time);
int64_t tmp_value = value;
ObTimeConverter::time_overflow_trunc(value);
if (value != tmp_value) {
ObTimeConverter::time_to_ob_time(value, ob_time);
}
}
}
break;
}
default: {
ret = OB_NOT_SUPPORTED;
}
}
LOG_DEBUG("end ob_datum_to_ob_time_without_date", K(type), K(ob_time), K(ret));
return ret;
}

View File

@ -65,13 +65,12 @@ inline int ObExprDateFormat::calc_result_type2(
// for enum or set obj, we need calc type
if (ob_is_enum_or_set_type(date.get_type())) {
date.set_calc_type(common::ObVarcharType);
} else if (ob_is_double_tc(date.get_type()) || ob_is_float_tc(date.get_type())) {
date.set_calc_type(common::ObNumberType);
}
if (ob_is_enum_or_set_type(format.get_type())) {
format.set_calc_type(common::ObVarcharType);
}
if (ob_is_double_tc(date.get_type()) || ob_is_float_tc(date.get_type()) || ob_is_number_tc(date.get_type())) {
date.set_calc_type(common::ObVarcharType);
}
}
return ret;

View File

@ -625,8 +625,10 @@ int ObExprSubtime::subtime_varchar(const ObExpr& expr, ObEvalCtx& ctx, ObDatum&
}
} else {
t_val1 = ObTimeConverter::ob_time_to_time(ot1);
if (IS_NEG_TIME(ot1.mode_)) {
t_val1 = -t_val1;
}
}
if (OB_SUCC(ret)) {
int64_t int_usec = t_val1 - t_val2;
const int64_t datetime_buf_len = DATETIME_MAX_LENGTH + 1;

View File

@ -244,7 +244,7 @@ int ObExprExtract::calc_oracle(T& result, const int64_t date_unit, const T& date
if (OB_SUCC(ret)) {
switch (ob_obj_type_class(type)) {
case ObDateTimeTC:
if (OB_FAIL(ObTimeConverter::datetime_to_ob_time(date.get_datetime(), get_timezone_info(session), ob_time))) {
if (OB_FAIL(ObTimeConverter::datetime_to_ob_time(date.get_datetime(), NULL, ob_time))) {
LOG_WARN("fail to convert date to ob time", K(ret), K(date));
}
break;

View File

@ -150,8 +150,7 @@ bool ObExprOperator::is_default_expr_cg() const
} func_val;
static_assert(sizeof(int64_t) * 2 == sizeof(CGFunc), "size mismatch");
func_val.func_ = &ObExprOperator::cg_expr;
// virtual member function pointer is vtable absolute offset + 1 (to avoid null)
const int64_t func_idx = (func_val.val_ - 1) / sizeof(void*);
const int64_t func_idx = func_val.val_ / sizeof(void *);
return (*(void***)(&base))[func_idx] == (*(void***)(this))[func_idx];
}
@ -849,6 +848,8 @@ int ObExprOperator::aggregate_result_type_for_case(ObExprResType& type, const Ob
need_merge_type,
skip_null))) {
LOG_WARN("fail to aggregate result type", K(ret));
} else if (ObFloatType == type.get_type() && !is_oracle_mode) {
type.set_type(ObDoubleType);
}
}
return ret;
@ -877,7 +878,6 @@ int ObExprOperator::aggregate_result_type_for_merge(ObExprResType& type, const O
LOG_WARN("invalid argument. wrong type for merge", K(i), K(types[i].get_type()), K(ret));
}
}
if (OB_SUCC(ret)) {
type.set_type(res_type);
if (ob_is_numeric_type(res_type)) {

View File

@ -386,7 +386,7 @@ int ObExprMonthName::calc_month_name(const ObExpr& expr, ObEvalCtx& ctx, ObDatum
// NOTE: the last param should be true otherwise '2020-09-00' will not work
if (OB_FAIL(calc(expr, ctx, expr_datum, DT_MON, true, true))) {
LOG_WARN("eval month in monthname failed", K(ret), K(expr));
} else {
} else if (!expr_datum.is_null()) {
int32_t mon = expr_datum.get_int32();
if (mon < 1 || mon > 12) {
LOG_WARN("invalid month value", K(ret), K(expr));
@ -402,23 +402,19 @@ int ObExprMonthName::calc_month_name(const ObExpr& expr, ObEvalCtx& ctx, ObDatum
int ObExprMonthName::calc_result_type1(ObExprResType& type, ObExprResType& type1, common::ObExprTypeCtx& type_ctx) const
{
ObCollationType cs_type = type_ctx.get_coll_type();
type.set_varchar();
type1.set_calc_type(common::ObVarcharType);
type.set_collation_type(cs_type);
type.set_collation_level(CS_LEVEL_IMPLICIT);
// get collation type from session and set it in type for passing following
// collation checking
int ret = OB_SUCCESS;
if (OB_ISNULL(type_ctx.get_session())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("session is NULL", K(ret));
} else {
ObCollationType cs_type = type_ctx.get_coll_type();
type.set_collation_type(cs_type);
type.set_collation_level(CS_LEVEL_IMPLICIT);
type1.set_calc_collation_type(cs_type);
common::ObObjTypeClass tc1 = ob_obj_type_class(type1.get_type());
if (ob_is_enumset_tc(type1.get_type())) {
type1.set_calc_type(common::ObVarcharType);
} else if ((common::ObFloatTC == tc1) || (common::ObDoubleTC == tc1)) {
type1.set_calc_type(common::ObIntType);
}
return ret;
return OB_SUCCESS;
}
} // namespace sql

View File

@ -62,6 +62,8 @@ inline int ObExprTimeDiff::calc_result_type2(
if (ob_is_enumset_tc(left.get_type())) {
left.set_calc_type(common::ObVarcharType);
scale = common::MAX_SCALE_FOR_TEMPORAL;
} else if (ob_is_real_type(left.get_type())) {
left.set_calc_type(common::ObNumberType);
}
if (ob_is_enumset_tc(right.get_type())) {
right.set_calc_type(common::ObVarcharType);

View File

@ -1009,6 +1009,8 @@ int ObLogDelUpd::calculate_table_location(uint64_t loc_table_id, uint64_t ref_ta
const common::ObDataTypeCastParams dtc_params =
ObBasicSessionInfo::create_dtc_params(my_plan_->get_optimizer_context().get_session_info());
ObTaskExecutorCtx* task_exec_ctx = my_plan_->get_optimizer_context().get_task_exec_ctx();
ObArray<ObRawExpr *> correlated_filters;
ObArray<ObRawExpr *> uncorrelated_filters;
// initialized the table location
if (OB_ISNULL(schema_guard) || OB_ISNULL(sql_schema_guard) || OB_ISNULL(stmt) || OB_ISNULL(exec_ctx) ||
OB_ISNULL(task_exec_ctx) || OB_ISNULL(params) || OB_ISNULL(location_cache)) {
@ -1022,10 +1024,16 @@ int ObLogDelUpd::calculate_table_location(uint64_t loc_table_id, uint64_t ref_ta
K(task_exec_ctx),
K(params),
K(location_cache));
} else if (OB_FAIL(ObOptimizerUtil::extract_parameterized_correlated_filters(
is_first_dml_op_ ? stmt->get_condition_exprs() : get_filter_exprs(),
params->count(),
correlated_filters,
uncorrelated_filters))) {
LOG_WARN("Failed to extract correlated filters", K(ret));
} else if (OB_FAIL(table_partition_info.init_table_location(*sql_schema_guard,
*stmt,
exec_ctx->get_my_session(),
is_first_dml_op_ ? stmt->get_condition_exprs() : get_filter_exprs(),
uncorrelated_filters,
loc_table_id,
ref_table_id,
part_hint,
@ -1061,8 +1069,8 @@ int ObLogDelUpd::alloc_partition_id_expr(ObAllocExprContext& ctx)
int ObLogDelUpd::alloc_shadow_pk_column_for_pdml(ObAllocExprContext& ctx)
{
int ret = OB_SUCCESS;
bool found = false;
for (int64_t i = 0; i < ctx.expr_producers_.count() && OB_SUCC(ret) && !found; i++) {
for (int64_t i = 0; i < ctx.expr_producers_.count() && OB_SUCC(ret); i++) {
bool found = false;
ExprProducer expr_producer = ctx.expr_producers_.at(i);
if (expr_producer.consumer_id_ == id_ && expr_producer.expr_->is_column_ref_expr()) {
ObColumnRefRawExpr* column_ref_expr = (ObColumnRefRawExpr*)(expr_producer.expr_);

View File

@ -12334,6 +12334,10 @@ NAME_OB
{
make_name_node($$, result->malloc_pool_, "database");
}
| SCHEMA
{
make_name_node($$, result->malloc_pool_, "database");
}
| COALESCE
{
make_name_node($$, result->malloc_pool_, "coalesce");

View File

@ -72495,7 +72495,7 @@ static int input (yyscan_t yyscanner );
/* This used to be an fputs(), but since the string might contain NUL's,
* we now use fwrite().
*/
#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
#define ECHO fwrite( yytext, yyleng, 1, yyout )
#endif
/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
@ -72506,7 +72506,7 @@ static int input (yyscan_t yyscanner );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
unsigned n; \
int n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \

File diff suppressed because it is too large Load Diff

View File

@ -3421,6 +3421,16 @@ int ObAlterTableResolver::resolve_change_column(const ParseNode& node)
K(ret),
K(alter_column_schema.get_accuracy()),
KPC(origin_col_schema));
} else if ((ObTimestampType == origin_col_schema->get_data_type()
|| ObDateTimeType == origin_col_schema->get_data_type()
|| ObTimeType == origin_col_schema->get_data_type())
&& origin_col_schema->get_data_type() == alter_column_schema.get_data_type()
&& origin_col_schema->get_accuracy().get_precision() >
alter_column_schema.get_accuracy().get_precision()) {
ret = OB_NOT_SUPPORTED;
LOG_USER_ERROR(OB_NOT_SUPPORTED, "Decrease scale of timestamp type");
LOG_WARN("Decrease scale of timestamp type not supported", K(ret),
K(origin_col_schema->get_accuracy()), K(alter_column_schema.get_accuracy()));
}
}
if (OB_SUCC(ret)) {
@ -3531,6 +3541,17 @@ int ObAlterTableResolver::resolve_modify_column(
K(ret),
K(alter_column_schema.get_accuracy()),
KPC(origin_col_schema));
} else if ((ObTimestampNanoType == origin_col_schema->get_data_type()
|| ObTimestampType == origin_col_schema->get_data_type()
|| ObDateTimeType == origin_col_schema->get_data_type()
|| ObTimeType == origin_col_schema->get_data_type())
&& origin_col_schema->get_data_type() == alter_column_schema.get_data_type()
&& origin_col_schema->get_accuracy().get_precision() >
alter_column_schema.get_accuracy().get_precision()) {
ret = OB_NOT_SUPPORTED;
LOG_USER_ERROR(OB_NOT_SUPPORTED, "Decrease scale of timestamp type");
LOG_WARN("Decrease scale of timestamp type not supported", K(ret),
K(origin_col_schema->get_accuracy()), K(alter_column_schema.get_accuracy()));
} else if (share::is_oracle_mode() &&
((origin_col_schema->get_data_type() != alter_column_schema.get_data_type()) ||
(origin_col_schema->get_data_length() != alter_column_schema.get_data_length()))) {

View File

@ -411,6 +411,10 @@ int ObRawExprPrinter::print(ObOpRawExpr* expr)
case T_OP_GT:
case T_OP_SQ_GT:
SET_SYMBOL_IF_EMPTY(">");
case T_OP_BIT_LEFT_SHIFT:
SET_SYMBOL_IF_EMPTY("<<");
case T_OP_BIT_RIGHT_SHIFT:
SET_SYMBOL_IF_EMPTY(">>");
case T_OP_NE:
case T_OP_SQ_NE:
SET_SYMBOL_IF_EMPTY("<>");