bugfix: support OB_VECTOR_TYPE in some array exprs
This commit is contained in:
parent
bec9a59d43
commit
aec5c8657b
14
deps/oblib/src/lib/udt/ob_collection_type.cpp
vendored
14
deps/oblib/src/lib/udt/ob_collection_type.cpp
vendored
@ -445,7 +445,9 @@ int ObSqlCollectionInfo::parse_type_info()
|
||||
const auto& match = *it;
|
||||
std::string type_name = match.str();
|
||||
if (is_root) {
|
||||
if (OB_FAIL(create_meta_info_by_name(type_name, collection_meta_, arr_depth))) {
|
||||
// vector element is float
|
||||
std::string root_elem = isNumber(type_name) ? "FLOAT" : type_name;
|
||||
if (OB_FAIL(create_meta_info_by_name(root_elem, collection_meta_, arr_depth))) {
|
||||
LOG_WARN("get type by name failed", K(ret));
|
||||
} else {
|
||||
is_root = false;
|
||||
@ -497,12 +499,16 @@ bool ObSqlCollectionInfo::has_same_super_type(const ObSqlCollectionInfo &other)
|
||||
int ObSqlCollectionInfo::get_child_def_string(ObString &child_def) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const uint32_t min_len = 7; // array()
|
||||
if (name_len_ <= min_len) {
|
||||
if (name_len_ <= 7) { // array()
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(*this));
|
||||
} else if (ObString(6, name_def_).compare("ARRAY(") == 0) {
|
||||
child_def = ObString(name_len_ - 7, name_def_ + 6);
|
||||
} else if (ObString(7, name_def_).compare("VECTOR(") == 0) {
|
||||
child_def = ObString(name_len_ - 8, name_def_ + 7);
|
||||
} else {
|
||||
child_def = ObString(name_len_ - min_len, name_def_ + (min_len - 1));
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(*this));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -544,7 +544,8 @@ int ObArrayTypeCastFactory::alloc(ObIAllocator &alloc, const ObCollectionTypeBas
|
||||
} else {
|
||||
arr_cast = OB_NEWx(ObArrayFixedSizeCast, &alloc);
|
||||
}
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE) {
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE
|
||||
|| arr_type->element_type_->type_id_ == ObNestedType::OB_VECTOR_TYPE) {
|
||||
arr_cast = OB_NEWx(ObArrayNestedCast, &alloc);
|
||||
} else {
|
||||
// to do
|
||||
|
@ -349,7 +349,8 @@ int ObExprArrayAppendCommon::append_elem(ObIAllocator &tmp_allocator, ObEvalCtx
|
||||
if (OB_FAIL(ObArrayUtil::append(*res_arr, elem_type->basic_meta_.get_obj_type(), val_datum))) {
|
||||
LOG_WARN("failed to append array value", K(ret));
|
||||
}
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE) {
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE
|
||||
|| arr_type->element_type_->type_id_ == ObNestedType::OB_VECTOR_TYPE) {
|
||||
bool is_null_elem = val_datum->is_null();
|
||||
if (!is_null_elem && OB_FAIL(ObArrayExprUtils::get_array_obj(tmp_allocator, ctx, val_subschema_id, val_datum->get_string(), val_arr))) {
|
||||
LOG_WARN("construct array obj failed", K(ret));
|
||||
@ -357,8 +358,8 @@ int ObExprArrayAppendCommon::append_elem(ObIAllocator &tmp_allocator, ObEvalCtx
|
||||
LOG_WARN("failed to append array", K(ret));
|
||||
}
|
||||
} else {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
OB_LOG(WARN, "invalid array type", K(ret), K(arr_type->element_type_->type_id_));
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid element type", K(ret), K(arr_type->element_type_->type_id_));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -384,7 +385,8 @@ int ObExprArrayAppendCommon::append_elem_vector(ObIAllocator &tmp_allocator, ObE
|
||||
if (OB_FAIL(ObArrayUtil::append(*res_arr, elem_type->basic_meta_.get_obj_type(), &val_datum))) {
|
||||
LOG_WARN("failed to append array value", K(ret));
|
||||
}
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE) {
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE
|
||||
|| arr_type->element_type_->type_id_ == ObNestedType::OB_VECTOR_TYPE) {
|
||||
bool is_null_elem = val_vec->is_null(idx);
|
||||
if (is_null_elem) {
|
||||
// do nothing
|
||||
@ -400,8 +402,8 @@ int ObExprArrayAppendCommon::append_elem_vector(ObIAllocator &tmp_allocator, ObE
|
||||
LOG_WARN("failed to append array", K(ret));
|
||||
}
|
||||
} else {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
OB_LOG(WARN, "invalid array type", K(ret), K(arr_type->element_type_->type_id_));
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid element type", K(ret), K(arr_type->element_type_->type_id_));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -69,7 +69,8 @@ int ObExprElementAt::calc_result_type2(ObExprResType &type,
|
||||
ObCollectionBasicType *elem_type = static_cast<ObCollectionBasicType *>(arr_type->element_type_);
|
||||
type.set_meta(elem_type->basic_meta_.get_meta_type());
|
||||
type.set_accuracy(elem_type->basic_meta_.get_accuracy());
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE) {
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE
|
||||
|| arr_type->element_type_->type_id_ == ObNestedType::OB_VECTOR_TYPE) {
|
||||
ObString child_def;
|
||||
uint16_t child_subschema_id = 0;
|
||||
if (OB_FAIL(coll_info->get_child_def_string(child_def))) {
|
||||
@ -79,8 +80,6 @@ int ObExprElementAt::calc_result_type2(ObExprResType &type,
|
||||
} else {
|
||||
type.set_collection(child_subschema_id);
|
||||
}
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_VECTOR_TYPE) {
|
||||
type.set_float();
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected ObNestedType type", K(ret), K(arr_type->element_type_->type_id_));
|
||||
@ -132,7 +131,8 @@ int ObExprElementAt::eval_element_at(const ObExpr &expr, ObEvalCtx &ctx, ObDatum
|
||||
} else {
|
||||
res.from_obj(elem_obj);
|
||||
}
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE) {
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE
|
||||
|| arr_type->element_type_->type_id_ == ObNestedType::OB_VECTOR_TYPE) {
|
||||
uint16_t child_subschema_id = expr.obj_meta_.get_subschema_id();
|
||||
ObIArrayType* child_arr = NULL;
|
||||
ObString child_arr_str;
|
||||
@ -145,9 +145,6 @@ int ObExprElementAt::eval_element_at(const ObExpr &expr, ObEvalCtx &ctx, ObDatum
|
||||
} else {
|
||||
res.set_string(child_arr_str);
|
||||
}
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_VECTOR_TYPE) {
|
||||
float *vector_data = reinterpret_cast<float*>(src_arr->get_data());
|
||||
res.set_float(vector_data[idx]);
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid element type", K(ret), K(arr_type->element_type_->type_id_));
|
||||
@ -215,7 +212,8 @@ int ObExprElementAt::eval_element_at_batch(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
} else {
|
||||
res_datum.at(j)->from_obj(elem_obj);
|
||||
}
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE) {
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE
|
||||
|| arr_type->element_type_->type_id_ == ObNestedType::OB_VECTOR_TYPE) {
|
||||
uint16_t child_subschema_id = expr.obj_meta_.get_subschema_id();
|
||||
ObString child_arr_str;
|
||||
if (OB_FAIL(ObArrayExprUtils::construct_array_obj(tmp_allocator,ctx, child_subschema_id, child_arr, false))) {
|
||||
@ -243,9 +241,6 @@ int ObExprElementAt::eval_element_at_batch(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
output_result.set_result();
|
||||
}
|
||||
}
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_VECTOR_TYPE) {
|
||||
float *vector_data = reinterpret_cast<float*>(src_arr->get_data());
|
||||
res_datum.at(j)->set_float(vector_data[idx]);
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid element type", K(ret), K(arr_type->element_type_->type_id_));
|
||||
@ -340,7 +335,8 @@ int ObExprElementAt::eval_element_at_vector(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
OB_LOG(WARN, "unexpected element type", K(ret), K(elem_obj.get_type()));
|
||||
}
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE) {
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE
|
||||
|| arr_type->element_type_->type_id_ == ObNestedType::OB_VECTOR_TYPE) {
|
||||
uint16_t child_subschema_id = expr.obj_meta_.get_subschema_id();
|
||||
ObString child_arr_str;
|
||||
if (OB_FAIL(ObArrayExprUtils::construct_array_obj(tmp_allocator,ctx, child_subschema_id, child_arr, false))) {
|
||||
@ -359,9 +355,6 @@ int ObExprElementAt::eval_element_at_vector(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
} else if (OB_FAIL(ObArrayExprUtils::set_array_res<ObVectorBase>(child_arr, expr, ctx, static_cast<ObVectorBase *>(res_vec), idx))) {
|
||||
LOG_WARN("set array res failed", K(ret));
|
||||
}
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_VECTOR_TYPE) {
|
||||
float *vector_data = reinterpret_cast<float*>(src_arr->get_data());
|
||||
res_vec->set_float(idx, vector_data[arr_idx]);
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid element type", K(ret), K(arr_type->element_type_->type_id_));
|
||||
|
@ -5575,7 +5575,8 @@ int ObDMLResolver::unnest_table_add_column(TableItem *&table_item, ColumnItem *&
|
||||
if (arr_type->element_type_->type_id_ == ObNestedType::OB_BASIC_TYPE) {
|
||||
ObCollectionBasicType *elem_type = static_cast<ObCollectionBasicType *>(arr_type->element_type_);
|
||||
data_type = elem_type->basic_meta_;
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE) {
|
||||
} else if (arr_type->element_type_->type_id_ == ObNestedType::OB_ARRAY_TYPE
|
||||
|| arr_type->element_type_->type_id_ == ObNestedType::OB_VECTOR_TYPE) {
|
||||
ObString child_def;
|
||||
uint16_t child_subschema_id = 0;
|
||||
if (OB_FAIL(coll_info->get_child_def_string(child_def))) {
|
||||
@ -5588,8 +5589,8 @@ int ObDMLResolver::unnest_table_add_column(TableItem *&table_item, ColumnItem *&
|
||||
data_type.set_subschema_id(child_subschema_id);
|
||||
}
|
||||
} else {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_WARN("not supportted array data type provided.", K(ret), K(arr_type->element_type_->type_id_));
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid element type", K(ret), K(arr_type->element_type_->type_id_));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user