patch 4.0
This commit is contained in:
@ -46,50 +46,12 @@ int ObExprTimeFormat::calc_result_type2(ObExprResType &type,
|
||||
time.set_calc_type(ObTimeType);
|
||||
format.set_calc_type(ObVarcharType);
|
||||
format.set_calc_collation_type(type.get_collation_type());
|
||||
|
||||
// result is null if cast first param to ObTimeType failed.
|
||||
type_ctx.set_cast_mode(type_ctx.get_cast_mode() | CM_NULL_ON_WARN);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ObExprTimeFormat::calc_result2(ObObj &result,
|
||||
const ObObj &time,
|
||||
const ObObj &format,
|
||||
ObExprCtx &expr_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
char *buf = NULL;
|
||||
int64_t buf_len = format.get_val_len() * OB_TEMPORAL_BUF_SIZE_RATIO;
|
||||
int64_t pos = 0;
|
||||
bool res_null = false;
|
||||
if (OB_UNLIKELY(time.is_null() || format.is_null())) {
|
||||
result.set_null();
|
||||
} else if (OB_UNLIKELY(ObVarcharType != format.get_type())) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("TIME_FORMAT() expected a string as format argument");
|
||||
} else if (OB_ISNULL(expr_ctx.calc_buf_)) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("the pointer is null");
|
||||
} else if (OB_UNLIKELY(format.get_string().empty())) {
|
||||
result.set_null();
|
||||
} else if (OB_ISNULL(buf = static_cast<char *>(expr_ctx.calc_buf_->alloc(buf_len)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_ERROR("no more memory to alloc for buf");
|
||||
} else if (OB_FAIL(time_to_str_format(time.get_time(),
|
||||
format.get_string(),
|
||||
buf,
|
||||
buf_len,
|
||||
pos,
|
||||
res_null))) {
|
||||
LOG_WARN("failed to convert ob time to str with format");
|
||||
} else if (res_null) {
|
||||
result.set_null();
|
||||
} else {
|
||||
result.set_varchar(buf, static_cast<int32_t>(pos));
|
||||
result.set_collation(result_type_);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprTimeFormat::time_to_str_format(const int64_t &time_value, const ObString &format,
|
||||
char *buf, int64_t buf_len, int64_t &pos, bool &res_null)
|
||||
{
|
||||
@ -297,4 +259,4 @@ int ObExprTimeFormat::calc_time_format(const ObExpr &expr, ObEvalCtx &ctx, ObDat
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user